@@ -15,29 +15,6 @@ import 'task.dart' as task;
15
15
16
16
void main (List <String > args) => grind (args);
17
17
18
- /// Thrown on failure to find something in a file.
19
- class GrindTestFailure implements Exception {
20
- final String message;
21
-
22
- GrindTestFailure (this .message);
23
-
24
- @override
25
- String toString () => message;
26
- }
27
-
28
- /// Kind of an inefficient grepper for now.
29
- void expectFileContains (String path, List <Pattern > items) {
30
- var source = File (path);
31
- if (! source.existsSync ()) {
32
- throw GrindTestFailure ('file not found: $path ' );
33
- }
34
- for (var item in items) {
35
- if (! File (path).readAsStringSync ().contains (item)) {
36
- throw GrindTestFailure ('"$item " not found in $path ' );
37
- }
38
- }
39
- }
40
-
41
18
/// Enable the following experiments for language tests.
42
19
final List <String > languageExperiments =
43
20
(Platform .environment['LANGUAGE_EXPERIMENTS' ] ?? '' ).split (RegExp (r'\s+' ));
@@ -46,8 +23,6 @@ final List<String> languageExperiments =
46
23
Directory createTempSync (String prefix) =>
47
24
Directory .systemTemp.createTempSync (prefix);
48
25
49
- final String _dartdocDocsPath = createTempSync ('dartdoc' ).path;
50
-
51
26
final Directory _flutterDir = createTempSync ('flutter' );
52
27
53
28
Directory get testPackageFlutterPlugin => Directory (
@@ -88,33 +63,7 @@ void analyze() async {
88
63
void analyzeTestPackages () async => task.analyzeTestPackages ();
89
64
90
65
@Task ('Check for dart format cleanliness' )
91
- void checkFormat () async {
92
- if (Platform .version.contains ('dev' )) {
93
- var filesToFix = < String > [];
94
-
95
- log ('Validating dart format with version ${Platform .version }' );
96
- await SubprocessLauncher ('dart format' ).runStreamed (
97
- Platform .resolvedExecutable,
98
- [
99
- 'format' ,
100
- '-o' ,
101
- 'none' ,
102
- 'bin' ,
103
- 'lib' ,
104
- 'test' ,
105
- 'tool' ,
106
- 'web' ,
107
- ],
108
- );
109
- if (filesToFix.isNotEmpty) {
110
- fail (
111
- 'dart format found files needing reformatting. Use this command to reformat:\n '
112
- 'dart format ${filesToFix .map ((f ) => "'$f '" ).join (' ' )}' );
113
- }
114
- } else {
115
- log ('Skipping dart format check, requires latest dev version of SDK' );
116
- }
117
- }
66
+ void checkFormat () async => await task.validateFormat ();
118
67
119
68
@Task ('Run quick presubmit checks.' )
120
69
@Depends (
@@ -459,77 +408,13 @@ Future<void> servePubPackage() async => await task.servePackageDocs(
459
408
460
409
@Task ('Rebuild generated files' )
461
410
@Depends (clean)
462
- Future <void > build () async {
463
- if (Platform .isWindows) {
464
- // Built files only need to be built on Linux and MacOS, as there are path
465
- // issues with Windows.
466
- return ;
467
- }
468
- await task.buildWeb ();
469
- await task.buildRenderers ();
470
- await task.buildDartdocOptions ();
471
- }
411
+ Future <void > build () async => task.buildAll ();
472
412
473
413
@Task ('Build the web frontend' )
474
414
Future <void > buildWeb () async => await task.buildWeb ();
475
415
476
- /// Paths in this list are relative to lib/.
477
- final _generatedFilesList = < String > [
478
- '../dartdoc_options.yaml' ,
479
- 'src/generator/html_resources.g.dart' ,
480
- 'src/generator/templates.aot_renderers_for_html.dart' ,
481
- 'src/generator/templates.aot_renderers_for_md.dart' ,
482
- 'src/generator/templates.runtime_renderers.dart' ,
483
- 'src/version.dart' ,
484
- '../test/mustachio/foo.dart' ,
485
- ].map ((s) => p.joinAll (p.posix.split (s)));
486
-
487
416
@Task ('Verify generated files are up to date' )
488
- Future <void > checkBuild () async {
489
- var originalFileContents = < String , String > {};
490
- var differentFiles = < String > [];
491
-
492
- // Load original file contents into memory before running the builder; it
493
- // modifies them in place.
494
- for (var relPath in _generatedFilesList) {
495
- var origPath = p.joinAll (['lib' , relPath]);
496
- var oldVersion = File (origPath);
497
- if (oldVersion.existsSync ()) {
498
- originalFileContents[relPath] = oldVersion.readAsStringSync ();
499
- }
500
- }
501
-
502
- await build ();
503
-
504
- for (var relPath in _generatedFilesList) {
505
- var newVersion = File (p.join ('lib' , relPath));
506
- if (! newVersion.existsSync ()) {
507
- log ('${newVersion .path } does not exist\n ' );
508
- differentFiles.add (relPath);
509
- } else if (originalFileContents[relPath] !=
510
- await newVersion.readAsString ()) {
511
- log ('${newVersion .path } has changed to: \n ${newVersion .readAsStringSync ()})' );
512
- differentFiles.add (relPath);
513
- }
514
- }
515
-
516
- if (differentFiles.isNotEmpty) {
517
- fail ('The following generated files needed to be rebuilt:\n '
518
- ' ${differentFiles .map ((f ) => p .join ('lib' , f )).join ("\n " )}\n '
519
- 'Rebuild them with "grind build" and check the results in.' );
520
- }
521
-
522
- // Verify that the web frontend has been compiled.
523
- final currentCodeSig = await task.calcDartFilesSig (Directory ('web' ));
524
- final lastCompileSig =
525
- File (p.join ('web' , 'sig.txt' )).readAsStringSync ().trim ();
526
- if (currentCodeSig != lastCompileSig) {
527
- log ('current files: $currentCodeSig ' );
528
- log ('cached sig : $lastCompileSig ' );
529
- fail ('The web frontend (web/docs.dart) needs to be recompiled; rebuild it '
530
- 'with "grind build-web" or "grind build".' );
531
- }
532
- }
417
+ Future <void > checkBuild () async {}
533
418
534
419
@Task ('Dry run of publish to pub.dev' )
535
420
Future <void > tryPublish () async => await task.runTryPublish ();
@@ -557,76 +442,7 @@ Iterable<FileSystemEntity> get _nonRootPubData {
557
442
}
558
443
559
444
@Task ('Generate docs for dartdoc without link-to-remote' )
560
- Future <void > testDartdoc () async {
561
- var launcher = SubprocessLauncher ('test-dartdoc' );
562
- await launcher.runStreamed (Platform .resolvedExecutable, [
563
- '--enable-asserts' ,
564
- 'bin/dartdoc.dart' ,
565
- '--output' ,
566
- _dartdocDocsPath,
567
- '--no-link-to-remote' ,
568
- ]);
569
- expectFileContains (p.join (_dartdocDocsPath, 'index.html' ),
570
- ['<title>dartdoc - Dart API docs</title>' ]);
571
- var object = RegExp ('<li>Object</li>' , multiLine: true );
572
- expectFileContains (
573
- p.join (_dartdocDocsPath, 'dartdoc' , 'PubPackageMeta-class.html' ),
574
- [object]);
575
- }
445
+ Future <void > testDartdoc () async => await task.validateDartdocDocs ();
576
446
577
447
@Task ('Validate the SDK doc build.' )
578
- @Depends (buildSdkDocs)
579
- void validateSdkDocs () {
580
- const expectedLibCounts = 0 ;
581
- const expectedSubLibCount = {19 , 20 , 21 };
582
- const expectedTotalCount = {19 , 20 , 21 };
583
- var indexHtml = joinFile (task.sdkDocsDir, ['index.html' ]);
584
- if (! indexHtml.existsSync ()) {
585
- fail ("No 'index.html' found for the SDK docs" );
586
- }
587
- log ("Found 'index.html'" );
588
- var indexContents = indexHtml.readAsStringSync ();
589
- var foundLibs = _findCount (indexContents, ' <li><a href="dart-' );
590
- if (expectedLibCounts != foundLibs) {
591
- fail ("Expected $expectedLibCounts 'dart:' entries in 'index.html', but "
592
- 'found $foundLibs ' );
593
- }
594
- log ("Found $foundLibs 'dart:' entries in 'index.html'" );
595
-
596
- var foundSubLibs =
597
- _findCount (indexContents, '<li class="section-subitem"><a href="dart-' );
598
- if (! expectedSubLibCount.contains (foundSubLibs)) {
599
- fail ("Expected $expectedSubLibCount 'dart:' entries in 'index.html' to be "
600
- 'in categories, but found $foundSubLibs ' );
601
- }
602
- log ('$foundSubLibs index.html dart: entries in categories found' );
603
-
604
- // check for the existence of certain files/dirs
605
- var libsLength = task.sdkDocsDir
606
- .listSync ()
607
- .where ((fs) => fs.path.contains ('dart-' ))
608
- .length;
609
- if (! expectedTotalCount.contains (libsLength)) {
610
- fail ('Docs not generated for all the SDK libraries; expected '
611
- '$expectedTotalCount directories, but $libsLength directories were '
612
- 'generated' );
613
- }
614
- log ("Found $libsLength 'dart:' libraries" );
615
-
616
- var futureConstFile = joinFile (
617
- task.sdkDocsDir, [p.join ('dart-async' , 'Future' , 'Future.html' )]);
618
- if (! futureConstFile.existsSync ()) {
619
- fail ('no Future.html found for dart:async Future constructor' );
620
- }
621
- log ('found Future.async ctor' );
622
- }
623
-
624
- int _findCount (String str, String match) {
625
- var count = 0 ;
626
- var index = str.indexOf (match);
627
- while (index != - 1 ) {
628
- count++ ;
629
- index = str.indexOf (match, index + match.length);
630
- }
631
- return count;
632
- }
448
+ void validateSdkDocs () async => await task.validateSdkDocs ();
0 commit comments