@@ -6,6 +6,7 @@ library dartdoc.dartdoc_test;
66
77import 'dart:async' ;
88import 'dart:io' ;
9+ import 'dart:mirrors' ;
910
1011import 'package:dartdoc/dartdoc.dart' ;
1112import 'package:dartdoc/src/logging.dart' ;
@@ -17,6 +18,13 @@ import 'package:test/test.dart';
1718
1819import 'src/utils.dart' ;
1920
21+ Uri get _currentFileUri =>
22+ (reflect (main) as ClosureMirror ).function.location.sourceUri;
23+ String get _testPackagePath =>
24+ pathLib.fromUri (_currentFileUri.resolve ('../testing/test_package' ));
25+ String get _testPackageFlutterPluginPath => pathLib
26+ .fromUri (_currentFileUri.resolve ('../testing/test_package_flutter_plugin' ));
27+
2028class DartdocLoggingOptionContext extends DartdocGeneratorOptionContext
2129 with LoggingContext {
2230 DartdocLoggingOptionContext (DartdocOptionSet optionSet, Directory dir)
@@ -27,11 +35,8 @@ void main() {
2735 group ('dartdoc with generators' , () {
2836 Directory tempDir;
2937 List <String > outputParam;
30- CoverageSubprocessLauncher subprocessLauncher;
3138
3239 setUpAll (() async {
33- subprocessLauncher =
34- new CoverageSubprocessLauncher ('dartdoc_test-subprocesses' );
3540 tempDir = Directory .systemTemp.createTempSync ('dartdoc.test.' );
3641 outputParam = ['--output' , tempDir.path];
3742 DartdocOptionSet optionSet = await DartdocOptionSet .fromOptionGenerators (
@@ -42,7 +47,6 @@ void main() {
4247 });
4348
4449 tearDown (() async {
45- await Future .wait (CoverageSubprocessLauncher .coverageResults);
4650 tempDir.listSync ().forEach ((FileSystemEntity f) {
4751 f.deleteSync (recursive: true );
4852 });
@@ -114,7 +118,18 @@ void main() {
114118 });
115119
116120 group ('Invoking command-line dartdoc' , () {
117- String dartdocPath = pathLib.join ('bin' , 'dartdoc.dart' );
121+ String dartdocPath =
122+ pathLib.canonicalize (pathLib.join ('bin' , 'dartdoc.dart' ));
123+ CoverageSubprocessLauncher subprocessLauncher;
124+
125+ setUpAll (() {
126+ subprocessLauncher =
127+ new CoverageSubprocessLauncher ('dartdoc_test-subprocesses' );
128+ });
129+
130+ tearDownAll (() async {
131+ await Future .wait (CoverageSubprocessLauncher .coverageResults);
132+ });
118133
119134 test ('errors cause non-zero exit when warnings are off' , () async {
120135 expect (
@@ -136,7 +151,108 @@ void main() {
136151 ]),
137152 throwsA (const TypeMatcher <ProcessException >()));
138153 });
139- });
154+
155+ test ('Validate missing FLUTTER_ROOT exception is clean' , () async {
156+ StringBuffer output = new StringBuffer ();
157+ var args = < String > [dartdocPath];
158+ Future run = subprocessLauncher.runStreamed (
159+ Platform .resolvedExecutable, args,
160+ environment: new Map .from (Platform .environment)
161+ ..remove ('FLUTTER_ROOT' ),
162+ includeParentEnvironment: false ,
163+ workingDirectory: _testPackageFlutterPluginPath, perLine: (s) {
164+ output.writeln (s);
165+ });
166+ // Asynchronous exception, but we still need the output, too.
167+ expect (run, throwsA (new TypeMatcher <ProcessException >()));
168+ try {
169+ await run;
170+ } on ProcessException catch (_) {}
171+
172+ expect (
173+ output.toString (),
174+ contains (new RegExp (
175+ 'Top level package requires Flutter but FLUTTER_ROOT environment variable not set|test_package_flutter_plugin requires the Flutter SDK, version solving failed' )));
176+ expect (output.toString (), isNot (contains ('asynchronous gap' )));
177+ });
178+
179+ test ("Validate --version works" , () async {
180+ StringBuffer output = new StringBuffer ();
181+ var args = < String > [dartdocPath, '--version' ];
182+ await subprocessLauncher.runStreamed (Platform .resolvedExecutable, args,
183+ workingDirectory: _testPackagePath,
184+ perLine: (s) => output.writeln (s));
185+ PackageMeta dartdocMeta = new PackageMeta .fromFilename (dartdocPath);
186+ expect (output.toString (),
187+ endsWith ('dartdoc version: ${dartdocMeta .version }\n ' ));
188+ });
189+
190+ test ('Check for sample code in examples' , () async {
191+ StringBuffer output = new StringBuffer ();
192+ var args = < String > [
193+ dartdocPath,
194+ '--include' ,
195+ 'ex' ,
196+ '--no-include-source' ,
197+ '--output' ,
198+ tempDir.path
199+ ];
200+
201+ await subprocessLauncher.runStreamed (Platform .resolvedExecutable, args,
202+ workingDirectory: _testPackagePath,
203+ perLine: (s) => output.writeln (s));
204+
205+ // Examples are reported as unfound because we (purposefully)
206+ // did not use --example-path-prefix above.
207+ final sep = '.' ; // We don't care what the path separator character is
208+ final firstUnfoundExample =
209+ new RegExp ('warning: lib${sep }example.dart: '
210+ '@example file not found.*test_package${sep }dog${sep }food.md' );
211+ if (! output.toString ().contains (firstUnfoundExample)) {
212+ fail ('Should warn about unfound @example files' );
213+ }
214+ });
215+
216+ test ('Validate JSON output' , () async {
217+ var args = < String > [
218+ dartdocPath,
219+ '--include' ,
220+ 'ex' ,
221+ '--no-include-source' ,
222+ '--output' ,
223+ tempDir.path,
224+ '--json'
225+ ];
226+
227+ Iterable <Map > jsonValues = await subprocessLauncher.runStreamed (
228+ Platform .resolvedExecutable, args,
229+ workingDirectory: _testPackagePath);
230+
231+ expect (jsonValues, isNotEmpty,
232+ reason: 'All STDOUT lines should be JSON-encoded maps.' );
233+ }, timeout: new Timeout .factor (2 ));
234+
235+ test ('--footer-text includes text' , () async {
236+ String footerTextPath =
237+ pathLib.join (Directory .systemTemp.path, 'footer.txt' );
238+ new File (footerTextPath).writeAsStringSync (' footer text include ' );
239+
240+ var args = < String > [
241+ dartdocPath,
242+ '--footer-text=${footerTextPath }' ,
243+ '--include' ,
244+ 'ex' ,
245+ '--output' ,
246+ tempDir.path
247+ ];
248+
249+ await subprocessLauncher.runStreamed (Platform .resolvedExecutable, args,
250+ workingDirectory: _testPackagePath);
251+
252+ File outFile = new File (pathLib.join (tempDir.path, 'index.html' ));
253+ expect (outFile.readAsStringSync (), contains ('footer text include' ));
254+ });
255+ }, timeout: new Timeout .factor (3 ));
140256
141257 group ('Option handling with cross-linking' , () {
142258 DartdocResults results;
0 commit comments