@@ -12,6 +12,8 @@ import 'package:dartdoc/src/package_meta.dart';
1212import 'package:path/path.dart' as pathLib;
1313import 'package:test/test.dart' ;
1414
15+ import 'src/utils.dart' ;
16+
1517const List <String > _filesToIgnore = const < String > ['.DS_Store' ];
1618
1719const String gitBinName = 'git' ;
@@ -40,10 +42,20 @@ String get _testPackageFlutterPluginPath => pathLib
4042void main () {
4143 group ('compare outputs' , () {
4244 Directory tempDir;
45+ CoverageSubprocessLauncher subprocessLauncher;
4346
4447 var dartdocBin =
4548 pathLib.fromUri (_currentFileUri.resolve ('../bin/dartdoc.dart' ));
4649
50+ setUpAll (() {
51+ subprocessLauncher =
52+ new CoverageSubprocessLauncher ('compare_output_test-subprocesses' );
53+ });
54+
55+ tearDownAll (() async {
56+ await Future .wait (CoverageSubprocessLauncher .coverageResults);
57+ });
58+
4759 setUp (() {
4860 tempDir = Directory .systemTemp.createTempSync ('dartdoc.test.' );
4961 });
@@ -55,27 +67,38 @@ void main() {
5567 });
5668
5769 test ('Validate missing FLUTTER_ROOT exception is clean' , () async {
70+ StringBuffer output = new StringBuffer ();
5871 var args = < String > [dartdocBin];
59- var result = Process .runSync (Platform .resolvedExecutable, args,
72+ Future run = subprocessLauncher.runStreamed (
73+ Platform .resolvedExecutable, args,
6074 environment: new Map .from (Platform .environment)
6175 ..remove ('FLUTTER_ROOT' ),
6276 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+
6486 expect (
65- result.stderr ,
87+ output. toString () ,
6688 contains (new RegExp (
6789 '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' )));
7091 });
7192
7293 test ("Validate --version works" , () async {
94+ StringBuffer output = new StringBuffer ();
7395 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));
7699 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 ' ));
79102 });
80103
81104 test ("Validate html output of test_package" , () async {
@@ -100,6 +123,8 @@ void main() {
100123 '--pretty-index-json' ,
101124 ];
102125
126+ // Deliberately use runSync here to avoid counting this test as
127+ // "test coverage".
103128 var result = Process .runSync (Platform .resolvedExecutable, args,
104129 workingDirectory: _testPackagePath);
105130
@@ -157,7 +182,8 @@ void main() {
157182 fail (message.join ('\n ' ));
158183 });
159184
160- test ('Check for sample code in examples' , () {
185+ test ('Check for sample code in examples' , () async {
186+ StringBuffer output = new StringBuffer ();
161187 var args = < String > [
162188 dartdocBin,
163189 '--include' ,
@@ -167,28 +193,21 @@ void main() {
167193 tempDir.path
168194 ];
169195
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));
179199
180200 // Examples are reported as unfound because we (purposefully)
181201 // did not use --example-path-prefix above.
182202 final sep = '.' ; // We don't care what the path separator character is
183203 final firstUnfoundExample = new RegExp ('warning: lib${sep }example.dart: '
184204 '@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' );
188207 }
189208 });
190209
191- test ('Validate JSON output' , () {
210+ test ('Validate JSON output' , () async {
192211 var args = < String > [
193212 dartdocBin,
194213 '--include' ,
@@ -199,28 +218,15 @@ void main() {
199218 '--json'
200219 ];
201220
202- var result = Process .runSync (Platform .resolvedExecutable, args,
221+ Iterable <Map > jsonValues = await subprocessLauncher.runStreamed (
222+ Platform .resolvedExecutable, args,
203223 workingDirectory: _testPackagePath);
204224
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-
216225 expect (jsonValues, isNotEmpty,
217226 reason: 'All STDOUT lines should be JSON-encoded maps.' );
227+ }, timeout: new Timeout .factor (2 ));
218228
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 {
224230 String footerTextPath =
225231 pathLib.join (Directory .systemTemp.path, 'footer.txt' );
226232 new File (footerTextPath).writeAsStringSync (' footer text include ' );
@@ -234,20 +240,15 @@ void main() {
234240 tempDir.path
235241 ];
236242
237- var result = Process . runSync (Platform .resolvedExecutable, args,
243+ await subprocessLauncher. runStreamed (Platform .resolvedExecutable, args,
238244 workingDirectory: _testPackagePath);
239245
240- if (result.exitCode != 0 ) {
241- print (result.exitCode);
242- print (result.stdout);
243- print (result.stderr);
244- fail ('dartdoc failed' );
245- }
246-
247246 File outFile = new File (pathLib.join (tempDir.path, 'index.html' ));
248247 expect (outFile.readAsStringSync (), contains ('footer text include' ));
249248 });
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 ));
251252}
252253
253254Map <String , String > _parseOutput (
0 commit comments