[dtd] Update tests to work via 'dart test'
Now that the SDK uses Pub Workspaces, using the test runner is enabled in Dart-Code. However there are some differences when using 'dart test' that caused some of these tests to fail - this change addresses them: - Don't use Platform.script because it won't be the source Dart filename - Use `print` instead of `stdout.write` because the test runner captures that (see https://github.com/dart-lang/test/issues/1749) Change-Id: Ib0e4e1d83449767dfa9d96a6543bda09705f8d96 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421160 Commit-Queue: Ben Konyi <bkonyi@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com> Reviewed-by: Jake Macdonald <jakemac@google.com>
This commit is contained in:
committed by
Commit Queue
parent
27f18db214
commit
43631b20bb
@@ -5,6 +5,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:dtd/dtd.dart';
|
||||
import 'package:test/test.dart';
|
||||
@@ -14,6 +15,16 @@ import 'utils.dart';
|
||||
void main() {
|
||||
late ToolingDaemonTestProcess toolingDaemonProcess;
|
||||
|
||||
/// Gets the URI for [filename] in the example folder.
|
||||
Uri getExampleFileUri(String filename) {
|
||||
// Use resolvePackageUriSync and not Platform.script so that this works
|
||||
// when run through 'dart test'.
|
||||
return Isolate.resolvePackageUriSync(
|
||||
Uri.parse('package:dtd/'),
|
||||
)!
|
||||
.resolve('../example/$filename');
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
toolingDaemonProcess = ToolingDaemonTestProcess();
|
||||
await toolingDaemonProcess.start();
|
||||
@@ -31,16 +42,14 @@ void main() {
|
||||
Platform.resolvedExecutable,
|
||||
[
|
||||
'run',
|
||||
Platform.script
|
||||
.resolve('../example/dtd_stream_example.dart')
|
||||
.toString(),
|
||||
getExampleFileUri('dtd_stream_example.dart').toString(),
|
||||
toolingDaemonProcess.uri.toString(),
|
||||
],
|
||||
);
|
||||
final lines = <String>[];
|
||||
streamProcess.handle(
|
||||
stdoutLines: (line) {
|
||||
stdout.write('streamProcess stdout: $line');
|
||||
print('streamProcess stdout: $line');
|
||||
lines.add(line);
|
||||
final json = jsonDecode(line) as Map<String, Object?>;
|
||||
if (json['step'] == 'Event A received') {
|
||||
@@ -67,9 +76,7 @@ void main() {
|
||||
Platform.resolvedExecutable,
|
||||
[
|
||||
'run',
|
||||
Platform.script
|
||||
.resolve('../example/dtd_service_example.dart')
|
||||
.toString(),
|
||||
getExampleFileUri('dtd_service_example.dart').toString(),
|
||||
toolingDaemonProcess.uri.toString(),
|
||||
],
|
||||
);
|
||||
@@ -77,7 +84,7 @@ void main() {
|
||||
final stdoutMessages = <Map<String, Object?>>[];
|
||||
serviceExampleProcess.handle(
|
||||
stdoutLines: (line) {
|
||||
stdout.write('serviceExample stdout: $line');
|
||||
print('serviceExample stdout: $line');
|
||||
stdoutMessages.add(jsonDecode(line) as Map<String, Object?>);
|
||||
},
|
||||
stderrLines: (line) => stderr.write('serviceExample stderr: $line'),
|
||||
@@ -132,9 +139,7 @@ void main() {
|
||||
Platform.resolvedExecutable,
|
||||
[
|
||||
'run',
|
||||
Platform.script
|
||||
.resolve('../example/dtd_file_system_service_example.dart')
|
||||
.toString(),
|
||||
getExampleFileUri('dtd_file_system_service_example.dart').toString(),
|
||||
toolingDaemonProcess.uri.toString(),
|
||||
tmpDirectory.uri.toString(),
|
||||
],
|
||||
@@ -142,7 +147,7 @@ void main() {
|
||||
final lines = <String>[];
|
||||
fileSystemServiceExampleProcess.handle(
|
||||
stdoutLines: (line) {
|
||||
stdout.write('fileSystemServiceProcess stdout: $line');
|
||||
print('fileSystemServiceProcess stdout: $line');
|
||||
lines.add(line);
|
||||
final json = jsonDecode(line) as Map<String, Object?>;
|
||||
if (json['step'] == 'read') {
|
||||
|
||||
@@ -28,7 +28,7 @@ class ToolingDaemonTestProcess {
|
||||
);
|
||||
process!.handle(
|
||||
stdoutLines: (line) {
|
||||
stdout.write('DTD stdout: $line');
|
||||
print('DTD stdout: $line');
|
||||
try {
|
||||
final json = jsonDecode(line) as Map<String, Object?>;
|
||||
final toolingDaemonDetails =
|
||||
|
||||
Reference in New Issue
Block a user