@@ -12,6 +12,8 @@ import 'package:dartdoc/src/package_meta.dart';
12
12
import 'package:path/path.dart' as pathLib;
13
13
import 'package:test/test.dart' ;
14
14
15
+ import 'src/utils.dart' ;
16
+
15
17
const List <String > _filesToIgnore = const < String > ['.DS_Store' ];
16
18
17
19
const String gitBinName = 'git' ;
@@ -40,10 +42,20 @@ String get _testPackageFlutterPluginPath => pathLib
40
42
void main () {
41
43
group ('compare outputs' , () {
42
44
Directory tempDir;
45
+ CoverageSubprocessLauncher subprocessLauncher;
43
46
44
47
var dartdocBin =
45
48
pathLib.fromUri (_currentFileUri.resolve ('../bin/dartdoc.dart' ));
46
49
50
+ setUpAll (() {
51
+ subprocessLauncher =
52
+ new CoverageSubprocessLauncher ('compare_output_test-subprocesses' );
53
+ });
54
+
55
+ tearDownAll (() async {
56
+ await Future .wait (CoverageSubprocessLauncher .coverageResults);
57
+ });
58
+
47
59
setUp (() {
48
60
tempDir = Directory .systemTemp.createTempSync ('dartdoc.test.' );
49
61
});
@@ -55,27 +67,38 @@ void main() {
55
67
});
56
68
57
69
test ('Validate missing FLUTTER_ROOT exception is clean' , () async {
70
+ StringBuffer output = new StringBuffer ();
58
71
var args = < String > [dartdocBin];
59
- var result = Process .runSync (Platform .resolvedExecutable, args,
72
+ Future run = subprocessLauncher.runStreamed (
73
+ Platform .resolvedExecutable, args,
60
74
environment: new Map .from (Platform .environment)
61
75
..remove ('FLUTTER_ROOT' ),
62
76
includeParentEnvironment: false ,
63
- workingDirectory: _testPackageFlutterPluginPath);
77
+ workingDirectory: _testPackageFlutterPluginPath, perLine: (s) {
78
+ output.writeln (s);
79
+ });
80
+ // Asynchronous exception, but we still need the output, too.
81
+ expect (run, throwsA (new TypeMatcher <ProcessException >()));
82
+ try {
83
+ await run;
84
+ } on ProcessException catch (_) {}
85
+
64
86
expect (
65
- result.stderr ,
87
+ output. toString () ,
66
88
contains (new RegExp (
67
89
'Top level package requires Flutter but FLUTTER_ROOT environment variable not set|test_package_flutter_plugin requires the Flutter SDK, version solving failed' )));
68
- expect (result.stderr, isNot (contains ('asynchronous gap' )));
69
- expect (result.exitCode, isNot (0 ));
90
+ expect (output.toString (), isNot (contains ('asynchronous gap' )));
70
91
});
71
92
72
93
test ("Validate --version works" , () async {
94
+ StringBuffer output = new StringBuffer ();
73
95
var args = < String > [dartdocBin, '--version' ];
74
- var result = Process .runSync (Platform .resolvedExecutable, args,
75
- workingDirectory: _testPackagePath);
96
+ await subprocessLauncher.runStreamed (Platform .resolvedExecutable, args,
97
+ workingDirectory: _testPackagePath,
98
+ perLine: (s) => output.writeln (s));
76
99
PackageMeta dartdocMeta = new PackageMeta .fromFilename (dartdocBin);
77
- expect (
78
- result.stdout, equals ('dartdoc version: ${dartdocMeta .version }\n ' ));
100
+ expect (output. toString (),
101
+ endsWith ('dartdoc version: ${dartdocMeta .version }\n ' ));
79
102
});
80
103
81
104
test ("Validate html output of test_package" , () async {
@@ -100,6 +123,8 @@ void main() {
100
123
'--pretty-index-json' ,
101
124
];
102
125
126
+ // Deliberately use runSync here to avoid counting this test as
127
+ // "test coverage".
103
128
var result = Process .runSync (Platform .resolvedExecutable, args,
104
129
workingDirectory: _testPackagePath);
105
130
@@ -157,7 +182,8 @@ void main() {
157
182
fail (message.join ('\n ' ));
158
183
});
159
184
160
- test ('Check for sample code in examples' , () {
185
+ test ('Check for sample code in examples' , () async {
186
+ StringBuffer output = new StringBuffer ();
161
187
var args = < String > [
162
188
dartdocBin,
163
189
'--include' ,
@@ -167,28 +193,21 @@ void main() {
167
193
tempDir.path
168
194
];
169
195
170
- var result = Process .runSync (Platform .resolvedExecutable, args,
171
- workingDirectory: _testPackagePath);
172
-
173
- if (result.exitCode != 0 ) {
174
- print (result.exitCode);
175
- print (result.stdout);
176
- print (result.stderr);
177
- fail ('dartdoc failed' );
178
- }
196
+ await subprocessLauncher.runStreamed (Platform .resolvedExecutable, args,
197
+ workingDirectory: _testPackagePath,
198
+ perLine: (s) => output.writeln (s));
179
199
180
200
// Examples are reported as unfound because we (purposefully)
181
201
// did not use --example-path-prefix above.
182
202
final sep = '.' ; // We don't care what the path separator character is
183
203
final firstUnfoundExample = new RegExp ('warning: lib${sep }example.dart: '
184
204
'@example file not found.*test_package${sep }dog${sep }food.md' );
185
- if (! result.stderr.contains (firstUnfoundExample)) {
186
- fail ('Should warn about unfound @example files: \n '
187
- 'stdout:\n ${result .stdout }\n stderr:\n ${result .stderr }' );
205
+ if (! output.toString ().contains (firstUnfoundExample)) {
206
+ fail ('Should warn about unfound @example files' );
188
207
}
189
208
});
190
209
191
- test ('Validate JSON output' , () {
210
+ test ('Validate JSON output' , () async {
192
211
var args = < String > [
193
212
dartdocBin,
194
213
'--include' ,
@@ -199,28 +218,15 @@ void main() {
199
218
'--json'
200
219
];
201
220
202
- var result = Process .runSync (Platform .resolvedExecutable, args,
221
+ Iterable <Map > jsonValues = await subprocessLauncher.runStreamed (
222
+ Platform .resolvedExecutable, args,
203
223
workingDirectory: _testPackagePath);
204
224
205
- if (result.exitCode != 0 ) {
206
- print (result.exitCode);
207
- print (result.stdout);
208
- print (result.stderr);
209
- fail ('dartdoc failed' );
210
- }
211
-
212
- var jsonValues = LineSplitter .split (result.stdout)
213
- .map ((j) => json.decode (j) as Map <String , dynamic >)
214
- .toList ();
215
-
216
225
expect (jsonValues, isNotEmpty,
217
226
reason: 'All STDOUT lines should be JSON-encoded maps.' );
227
+ }, timeout: new Timeout .factor (2 ));
218
228
219
- expect (result.stderr as String , isEmpty,
220
- reason: 'STDERR should be empty.' );
221
- });
222
-
223
- test ('--footer-text includes text' , () {
229
+ test ('--footer-text includes text' , () async {
224
230
String footerTextPath =
225
231
pathLib.join (Directory .systemTemp.path, 'footer.txt' );
226
232
new File (footerTextPath).writeAsStringSync (' footer text include ' );
@@ -234,20 +240,15 @@ void main() {
234
240
tempDir.path
235
241
];
236
242
237
- var result = Process . runSync (Platform .resolvedExecutable, args,
243
+ await subprocessLauncher. runStreamed (Platform .resolvedExecutable, args,
238
244
workingDirectory: _testPackagePath);
239
245
240
- if (result.exitCode != 0 ) {
241
- print (result.exitCode);
242
- print (result.stdout);
243
- print (result.stderr);
244
- fail ('dartdoc failed' );
245
- }
246
-
247
246
File outFile = new File (pathLib.join (tempDir.path, 'index.html' ));
248
247
expect (outFile.readAsStringSync (), contains ('footer text include' ));
249
248
});
250
- }, onPlatform: {'windows' : new Skip ('Avoiding parsing git output' )});
249
+ },
250
+ onPlatform: {'windows' : new Skip ('Avoiding parsing git output' )},
251
+ timeout: new Timeout .factor (3 ));
251
252
}
252
253
253
254
Map <String , String > _parseOutput (
0 commit comments