Skip to content

Commit 43631b2

Browse files
DanTupCommit Queue
authored andcommitted
[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 dart-lang/test#1749) Change-Id: Ib0e4e1d83449767dfa9d96a6543bda09705f8d96 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421160 Commit-Queue: Ben Konyi <[email protected]> Reviewed-by: Ben Konyi <[email protected]> Reviewed-by: Jake Macdonald <[email protected]>
1 parent 27f18db commit 43631b2

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

pkg/dtd/test/example_test.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:async';
66
import 'dart:convert';
77
import 'dart:io';
8+
import 'dart:isolate';
89

910
import 'package:dtd/dtd.dart';
1011
import 'package:test/test.dart';
@@ -14,6 +15,16 @@ import 'utils.dart';
1415
void main() {
1516
late ToolingDaemonTestProcess toolingDaemonProcess;
1617

18+
/// Gets the URI for [filename] in the example folder.
19+
Uri getExampleFileUri(String filename) {
20+
// Use resolvePackageUriSync and not Platform.script so that this works
21+
// when run through 'dart test'.
22+
return Isolate.resolvePackageUriSync(
23+
Uri.parse('package:dtd/'),
24+
)!
25+
.resolve('../example/$filename');
26+
}
27+
1728
setUp(() async {
1829
toolingDaemonProcess = ToolingDaemonTestProcess();
1930
await toolingDaemonProcess.start();
@@ -31,16 +42,14 @@ void main() {
3142
Platform.resolvedExecutable,
3243
[
3344
'run',
34-
Platform.script
35-
.resolve('../example/dtd_stream_example.dart')
36-
.toString(),
45+
getExampleFileUri('dtd_stream_example.dart').toString(),
3746
toolingDaemonProcess.uri.toString(),
3847
],
3948
);
4049
final lines = <String>[];
4150
streamProcess.handle(
4251
stdoutLines: (line) {
43-
stdout.write('streamProcess stdout: $line');
52+
print('streamProcess stdout: $line');
4453
lines.add(line);
4554
final json = jsonDecode(line) as Map<String, Object?>;
4655
if (json['step'] == 'Event A received') {
@@ -67,17 +76,15 @@ void main() {
6776
Platform.resolvedExecutable,
6877
[
6978
'run',
70-
Platform.script
71-
.resolve('../example/dtd_service_example.dart')
72-
.toString(),
79+
getExampleFileUri('dtd_service_example.dart').toString(),
7380
toolingDaemonProcess.uri.toString(),
7481
],
7582
);
7683

7784
final stdoutMessages = <Map<String, Object?>>[];
7885
serviceExampleProcess.handle(
7986
stdoutLines: (line) {
80-
stdout.write('serviceExample stdout: $line');
87+
print('serviceExample stdout: $line');
8188
stdoutMessages.add(jsonDecode(line) as Map<String, Object?>);
8289
},
8390
stderrLines: (line) => stderr.write('serviceExample stderr: $line'),
@@ -132,17 +139,15 @@ void main() {
132139
Platform.resolvedExecutable,
133140
[
134141
'run',
135-
Platform.script
136-
.resolve('../example/dtd_file_system_service_example.dart')
137-
.toString(),
142+
getExampleFileUri('dtd_file_system_service_example.dart').toString(),
138143
toolingDaemonProcess.uri.toString(),
139144
tmpDirectory.uri.toString(),
140145
],
141146
);
142147
final lines = <String>[];
143148
fileSystemServiceExampleProcess.handle(
144149
stdoutLines: (line) {
145-
stdout.write('fileSystemServiceProcess stdout: $line');
150+
print('fileSystemServiceProcess stdout: $line');
146151
lines.add(line);
147152
final json = jsonDecode(line) as Map<String, Object?>;
148153
if (json['step'] == 'read') {

pkg/dtd/test/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ToolingDaemonTestProcess {
2828
);
2929
process!.handle(
3030
stdoutLines: (line) {
31-
stdout.write('DTD stdout: $line');
31+
print('DTD stdout: $line');
3232
try {
3333
final json = jsonDecode(line) as Map<String, Object?>;
3434
final toolingDaemonDetails =

0 commit comments

Comments
 (0)