@@ -17,6 +17,35 @@ import 'package:test/test.dart';
1717
1818import 'src/utils.dart' ;
1919
20+ final Directory _testPackageDir = Directory ('testing/test_package' );
21+
22+ final _testPackageBadDir = Directory ('testing/test_package_bad' );
23+ final _testPackageMinimumDir = Directory ('testing/test_package_minimum' );
24+ final _testSkyEnginePackage = Directory ('testing/sky_engine' );
25+ final _testPackageWithNoReadme = Directory ('testing/test_package_small' );
26+ final _testPackageIncludeExclude =
27+ Directory ('testing/test_package_include_exclude' );
28+ final _testPackageImportExportError =
29+ Directory ('testing/test_package_import_export_error' );
30+ final _testPackageOptions = Directory ('testing/test_package_options' );
31+ final _testPackageOptionsImporter =
32+ Directory ('testing/test_package_options_importer' );
33+ final _testPackageCustomTemplates =
34+ Directory ('testing/test_package_custom_templates' );
35+
36+ /// Convenience factory to build a [DartdocGeneratorOptionContext] and associate
37+ /// it with a [DartdocOptionSet] based on the current working directory and/or
38+ /// the '--input' flag.
39+ Future <DartdocGeneratorOptionContext > _generatorContextFromArgv (
40+ List <String > argv) async {
41+ var optionSet = await DartdocOptionSet .fromOptionGenerators ('dartdoc' , [
42+ () => createDartdocOptions (pubPackageMetaProvider),
43+ createGeneratorOptions,
44+ ]);
45+ optionSet.parseArguments (argv);
46+ return DartdocGeneratorOptionContext (optionSet, null );
47+ }
48+
2049class DartdocLoggingOptionContext extends DartdocGeneratorOptionContext
2150 with LoggingContext {
2251 DartdocLoggingOptionContext (DartdocOptionSet optionSet, Directory dir)
@@ -28,7 +57,6 @@ void main() {
2857 Directory tempDir;
2958
3059 setUpAll (() async {
31- tempDir = Directory .systemTemp.createTempSync ('dartdoc.test.' );
3260 var optionSet = await DartdocOptionSet .fromOptionGenerators (
3361 'dartdoc' , [createLoggingOptions]);
3462 optionSet.parseArguments ([]);
@@ -45,7 +73,7 @@ void main() {
4573
4674 Future <Dartdoc > buildDartdoc (
4775 List <String > argv, Directory packageRoot, Directory tempDir) async {
48- var context = await generatorContextFromArgv (argv
76+ var context = await _generatorContextFromArgv (argv
4977 ..addAll (['--input' , packageRoot.path, '--output' , tempDir.path]));
5078 return await Dartdoc .fromContext (
5179 context,
@@ -61,15 +89,11 @@ void main() {
6189
6290 setUpAll (() async {
6391 tempDir = Directory .systemTemp.createTempSync ('dartdoc.test.' );
64- dartdoc = await buildDartdoc ([], testPackageOptions , tempDir);
92+ dartdoc = await buildDartdoc ([], _testPackageOptions , tempDir);
6593 results = await dartdoc.generateDocsBase ();
6694 p = results.packageGraph;
6795 });
6896
69- tearDownAll (() async {
70- tempDir.deleteSync (recursive: true );
71- });
72-
7397 test ('generator parameters' , () async {
7498 var favicon =
7599 File (path.joinAll ([tempDir.path, 'static-assets' , 'favicon.png' ]));
@@ -126,16 +150,12 @@ void main() {
126150 setUpAll (() async {
127151 tempDir = Directory .systemTemp.createTempSync ('dartdoc.test.' );
128152 results = await (await buildDartdoc (
129- ['--link-to-remote' ], testPackageOptionsImporter , tempDir))
153+ ['--link-to-remote' ], _testPackageOptionsImporter , tempDir))
130154 .generateDocsBase ();
131155 testPackageOptions = results.packageGraph.packages
132156 .firstWhere ((Package p) => p.name == 'test_package_options' );
133157 });
134158
135- tearDownAll (() async {
136- tempDir.deleteSync (recursive: true );
137- });
138-
139159 test ('linkToUrl' , () async {
140160 var main = testPackageOptions.allLibraries
141161 .firstWhere ((Library l) => l.name == 'main' );
@@ -161,7 +181,7 @@ void main() {
161181
162182 test ('with broken reexport chain' , () async {
163183 var dartdoc =
164- await buildDartdoc ([], testPackageImportExportError , tempDir);
184+ await buildDartdoc ([], _testPackageImportExportError , tempDir);
165185 var results = await dartdoc.generateDocsBase ();
166186 var p = results.packageGraph;
167187 var unresolvedExportWarnings = p
@@ -179,7 +199,7 @@ void main() {
179199 group ('include/exclude parameters' , () {
180200 test ('with config file' , () async {
181201 var dartdoc =
182- await buildDartdoc ([], testPackageIncludeExclude , tempDir);
202+ await buildDartdoc ([], _testPackageIncludeExclude , tempDir);
183203 var results = await dartdoc.generateDocs ();
184204 var p = results.packageGraph;
185205 expect (p.localPublicLibraries.map ((l) => l.name),
@@ -188,16 +208,16 @@ void main() {
188208
189209 test ('with include command line argument' , () async {
190210 var dartdoc = await buildDartdoc (['--include' , 'another_included' ],
191- testPackageIncludeExclude , tempDir);
211+ _testPackageIncludeExclude , tempDir);
192212 var results = await dartdoc.generateDocs ();
193213 var p = results.packageGraph;
194214 expect (p.localPublicLibraries.length, equals (1 ));
195215 expect (p.localPublicLibraries.first.name, equals ('another_included' ));
196216 });
197217
198218 test ('with exclude command line argument' , () async {
199- var dartdoc = await buildDartdoc (
200- [ '--exclude' , 'more_included' ], testPackageIncludeExclude , tempDir);
219+ var dartdoc = await buildDartdoc ([ '--exclude' , 'more_included' ],
220+ _testPackageIncludeExclude , tempDir);
201221 var results = await dartdoc.generateDocs ();
202222 var p = results.packageGraph;
203223 expect (p.localPublicLibraries.length, equals (1 ));
@@ -207,14 +227,14 @@ void main() {
207227 });
208228
209229 test ('package without version produces valid semver in docs' , () async {
210- var dartdoc = await buildDartdoc ([], testPackageMinimumDir , tempDir);
230+ var dartdoc = await buildDartdoc ([], _testPackageMinimumDir , tempDir);
211231 var results = await dartdoc.generateDocs ();
212232 var p = results.packageGraph;
213233 expect (p.defaultPackage.version, equals ('0.0.0-unknown' ));
214234 });
215235
216236 test ('basic interlinking test' , () async {
217- var dartdoc = await buildDartdoc ([], testPackageDir , tempDir);
237+ var dartdoc = await buildDartdoc ([], _testPackageDir , tempDir);
218238 var results = await dartdoc.generateDocs ();
219239 var p = results.packageGraph;
220240 var meta = p.publicPackages.firstWhere ((p) => p.name == 'meta' );
@@ -243,15 +263,11 @@ void main() {
243263
244264 setUpAll (() async {
245265 tempDir = Directory .systemTemp.createTempSync ('dartdoc.test.' );
246- dartdoc = await buildDartdoc ([], testPackageDir , tempDir);
266+ dartdoc = await buildDartdoc ([], _testPackageDir , tempDir);
247267 results = await dartdoc.generateDocs ();
248268 });
249269
250- tearDownAll (() async {
251- tempDir.deleteSync (recursive: true );
252- });
253-
254- test ('generate docs for ${path .basename (testPackageDir .path )} works' ,
270+ test ('generate docs for ${path .basename (_testPackageDir .path )} works' ,
255271 () async {
256272 expect (results.packageGraph, isNotNull);
257273 var packageGraph = results.packageGraph;
@@ -278,9 +294,9 @@ void main() {
278294 });
279295 });
280296
281- test ('generate docs for ${path .basename (testPackageBadDir .path )} fails' ,
297+ test ('generate docs for ${path .basename (_testPackageBadDir .path )} fails' ,
282298 () async {
283- var dartdoc = await buildDartdoc ([], testPackageBadDir , tempDir);
299+ var dartdoc = await buildDartdoc ([], _testPackageBadDir , tempDir);
284300
285301 try {
286302 await dartdoc.generateDocs ();
@@ -293,7 +309,7 @@ void main() {
293309 'from analysis_options' );
294310
295311 test ('generate docs for a package that does not have a readme' , () async {
296- var dartdoc = await buildDartdoc ([], testPackageWithNoReadme , tempDir);
312+ var dartdoc = await buildDartdoc ([], _testPackageWithNoReadme , tempDir);
297313
298314 var results = await dartdoc.generateDocs ();
299315 expect (results.packageGraph, isNotNull);
@@ -307,7 +323,7 @@ void main() {
307323
308324 test ('generate docs including a single library' , () async {
309325 var dartdoc =
310- await buildDartdoc (['--include' , 'fake' ], testPackageDir , tempDir);
326+ await buildDartdoc (['--include' , 'fake' ], _testPackageDir , tempDir);
311327
312328 var results = await dartdoc.generateDocs ();
313329 expect (results.packageGraph, isNotNull);
@@ -321,7 +337,7 @@ void main() {
321337
322338 test ('generate docs excluding a single library' , () async {
323339 var dartdoc =
324- await buildDartdoc (['--exclude' , 'fake' ], testPackageDir , tempDir);
340+ await buildDartdoc (['--exclude' , 'fake' ], _testPackageDir , tempDir);
325341
326342 var results = await dartdoc.generateDocs ();
327343 expect (results.packageGraph, isNotNull);
@@ -338,7 +354,7 @@ void main() {
338354 });
339355
340356 test ('generate docs for package with embedder yaml' , () async {
341- var dartdoc = await buildDartdoc ([], testSkyEnginePackage , tempDir);
357+ var dartdoc = await buildDartdoc ([], _testSkyEnginePackage , tempDir);
342358
343359 var results = await dartdoc.generateDocs ();
344360 expect (results.packageGraph, isNotNull);
@@ -370,9 +386,9 @@ void main() {
370386
371387 test ('generate docs with custom templates' , () async {
372388 var templatesDir =
373- path.join (testPackageCustomTemplates .path, 'templates' );
389+ path.join (_testPackageCustomTemplates .path, 'templates' );
374390 var dartdoc = await buildDartdoc (['--templates-dir' , templatesDir],
375- testPackageCustomTemplates , tempDir);
391+ _testPackageCustomTemplates , tempDir);
376392
377393 var results = await dartdoc.generateDocs ();
378394 expect (results.packageGraph, isNotNull);
@@ -390,7 +406,7 @@ void main() {
390406 var templatesDir = path.join (path.current, 'test/templates' );
391407 try {
392408 await buildDartdoc (['--templates-dir' , templatesDir],
393- testPackageCustomTemplates , tempDir);
409+ _testPackageCustomTemplates , tempDir);
394410 fail ('dartdoc should fail with missing required template' );
395411 } catch (e) {
396412 expect (e is DartdocFailure , isTrue);
@@ -403,7 +419,7 @@ void main() {
403419 var badPath = path.join (tempDir.path, 'BAD' );
404420 try {
405421 await buildDartdoc (
406- ['--templates-dir' , badPath], testPackageCustomTemplates , tempDir);
422+ ['--templates-dir' , badPath], _testPackageCustomTemplates , tempDir);
407423 fail ('dartdoc should fail with bad templatesDir path' );
408424 } catch (e) {
409425 expect (e is DartdocFailure , isTrue);
@@ -412,15 +428,15 @@ void main() {
412428
413429 test ('generating markdown docs does not crash' , () async {
414430 var dartdoc =
415- await buildDartdoc (['--format' , 'md' ], testPackageDir , tempDir);
431+ await buildDartdoc (['--format' , 'md' ], _testPackageDir , tempDir);
416432 await dartdoc.generateDocsBase ();
417433 });
418434
419435 test ('rel canonical prefix does not include base href' , () async {
420436 // ignore: omit_local_variable_types
421437 final String prefix = 'foo.bar/baz' ;
422438 var dartdoc = await buildDartdoc (
423- ['--rel-canonical-prefix' , prefix], testPackageDir , tempDir);
439+ ['--rel-canonical-prefix' , prefix], _testPackageDir , tempDir);
424440 await dartdoc.generateDocsBase ();
425441
426442 // Verify files at different levels have correct <link> content.
@@ -438,7 +454,7 @@ void main() {
438454
439455 test ('generate docs with bad output format' , () async {
440456 try {
441- await buildDartdoc (['--format' , 'bad' ], testPackageDir , tempDir);
457+ await buildDartdoc (['--format' , 'bad' ], _testPackageDir , tempDir);
442458 fail ('dartdoc should fail with bad output format' );
443459 } catch (e) {
444460 expect (e is DartdocFailure , isTrue);
0 commit comments