Skip to content

Commit 6ccfb4b

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Update analyzer-cli test for summary2.
[email protected], [email protected] Change-Id: I671f22195ee7c6d0c1c5d43d33181ace6a581bfb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110133 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 11f5b34 commit 6ccfb4b

File tree

2 files changed

+89
-11
lines changed

2 files changed

+89
-11
lines changed

pkg/analyzer_cli/test/driver_test.dart

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'dart:io';
88
import 'package:analyzer/error/error.dart';
99
import 'package:analyzer/source/error_processor.dart';
1010
import 'package:analyzer/src/analysis_options/analysis_options_provider.dart';
11+
import 'package:analyzer/src/dart/analysis/driver.dart';
1112
import 'package:analyzer/src/error/codes.dart';
1213
import 'package:analyzer/src/generated/engine.dart';
1314
import 'package:analyzer/src/generated/source.dart';
@@ -488,13 +489,27 @@ class BuildModeTest extends AbstractBuildModeTest {
488489
PackageBundle bundle =
489490
new PackageBundle.fromBuffer(await output.readAsBytes());
490491
var testFileUri = 'file:///test_file.dart';
491-
expect(bundle.unlinkedUnitUris, equals([testFileUri]));
492-
expect(bundle.linkedLibraryUris, equals([testFileUri]));
492+
if (AnalysisDriver.useSummary2) {
493+
var bundle2 = bundle.bundle2;
494+
expect(_linkedLibraryUriList(bundle2), [testFileUri]);
495+
expect(
496+
_linkedLibraryUnitUriList(bundle2, testFileUri),
497+
[testFileUri],
498+
);
499+
} else {
500+
expect(bundle.unlinkedUnitUris, equals([testFileUri]));
501+
expect(bundle.linkedLibraryUris, equals([testFileUri]));
502+
}
493503
expect(exitCode, 0);
494504
});
495505
}
496506

497507
test_buildLinked_buildSummaryOutputSemantic() async {
508+
// All informative data is stored separately when summary2.
509+
if (AnalysisDriver.useSummary2) {
510+
return;
511+
}
512+
498513
await withTempDirAsync((tempDir) async {
499514
var testDart = path.join(tempDir, 'test.dart');
500515
var testSumFull = path.join(tempDir, 'test.sum.full');
@@ -534,6 +549,11 @@ class BuildModeTest extends AbstractBuildModeTest {
534549
}
535550

536551
test_buildLinked_fromUnlinked() async {
552+
// We don't use unlinked units with summary2.
553+
if (AnalysisDriver.useSummary2) {
554+
return;
555+
}
556+
537557
await withTempDirAsync((tempDir) async {
538558
var aDart = path.join(tempDir, 'a.dart');
539559
var bDart = path.join(tempDir, 'b.dart');
@@ -598,6 +618,11 @@ var b = a;
598618
}
599619

600620
test_buildUnlinked() async {
621+
// We don't use unlinked units with summary2.
622+
if (AnalysisDriver.useSummary2) {
623+
return;
624+
}
625+
601626
await withTempDirAsync((tempDir) async {
602627
var outputPath = path.join(tempDir, 'test_file.dart.sum');
603628
await _doDrive(path.join('data', 'test_file.dart'), additionalArgs: [
@@ -649,8 +674,14 @@ var b = new B();
649674
expect(exitCode, 0);
650675
var bytes = new File(aSum).readAsBytesSync();
651676
var bundle = new PackageBundle.fromBuffer(bytes);
652-
expect(bundle.unlinkedUnitUris, equals([aUri]));
653-
expect(bundle.linkedLibraryUris, equals([aUri]));
677+
if (AnalysisDriver.useSummary2) {
678+
var bundle2 = bundle.bundle2;
679+
expect(_linkedLibraryUriList(bundle2), [aUri]);
680+
expect(_linkedLibraryUnitUriList(bundle2, aUri), [aUri]);
681+
} else {
682+
expect(bundle.unlinkedUnitUris, equals([aUri]));
683+
expect(bundle.linkedLibraryUris, equals([aUri]));
684+
}
654685
}
655686

656687
// Analyze package:bbb/b.dart and compute summary.
@@ -662,8 +693,14 @@ var b = new B();
662693
expect(exitCode, 0);
663694
var bytes = new File(bSum).readAsBytesSync();
664695
var bundle = new PackageBundle.fromBuffer(bytes);
665-
expect(bundle.unlinkedUnitUris, equals([bUri]));
666-
expect(bundle.linkedLibraryUris, equals([bUri]));
696+
if (AnalysisDriver.useSummary2) {
697+
var bundle2 = bundle.bundle2;
698+
expect(_linkedLibraryUriList(bundle2), [bUri]);
699+
expect(_linkedLibraryUnitUriList(bundle2, bUri), [bUri]);
700+
} else {
701+
expect(bundle.unlinkedUnitUris, equals([bUri]));
702+
expect(bundle.linkedLibraryUris, equals([bUri]));
703+
}
667704
}
668705

669706
// Analyze package:ccc/c.dart and compute summary.
@@ -675,8 +712,14 @@ var b = new B();
675712
expect(exitCode, 0);
676713
var bytes = new File(cSum).readAsBytesSync();
677714
var bundle = new PackageBundle.fromBuffer(bytes);
678-
expect(bundle.unlinkedUnitUris, equals([cUri]));
679-
expect(bundle.linkedLibraryUris, equals([cUri]));
715+
if (AnalysisDriver.useSummary2) {
716+
var bundle2 = bundle.bundle2;
717+
expect(_linkedLibraryUriList(bundle2), [cUri]);
718+
expect(_linkedLibraryUnitUriList(bundle2, cUri), [cUri]);
719+
} else {
720+
expect(bundle.unlinkedUnitUris, equals([cUri]));
721+
expect(bundle.linkedLibraryUris, equals([cUri]));
722+
}
680723
}
681724
});
682725
}
@@ -704,6 +747,11 @@ var b = new B();
704747
}
705748

706749
test_error_linkedAsUnlinked() async {
750+
// We don't use unlinked units with summary2.
751+
if (AnalysisDriver.useSummary2) {
752+
return;
753+
}
754+
707755
await withTempDirAsync((tempDir) async {
708756
var aDart = path.join(tempDir, 'a.dart');
709757
var bDart = path.join(tempDir, 'b.dart');
@@ -751,6 +799,11 @@ var b = new B();
751799
}
752800

753801
test_error_unlinkedAsLinked() async {
802+
// We don't use unlinked units with summary2.
803+
if (AnalysisDriver.useSummary2) {
804+
return;
805+
}
806+
754807
await withTempDirAsync((tempDir) async {
755808
var aDart = path.join(tempDir, 'a.dart');
756809
var bDart = path.join(tempDir, 'b.dart');
@@ -824,6 +877,20 @@ var b = new B();
824877
expect(errorSink, isEmpty);
825878
});
826879
}
880+
881+
Iterable<String> _linkedLibraryUnitUriList(
882+
LinkedNodeBundle bundle2,
883+
String libraryUriStr,
884+
) {
885+
var libraries = bundle2.libraries;
886+
var library = libraries.singleWhere((l) => l.uriStr == libraryUriStr);
887+
return library.units.map((u) => u.uriStr).toList();
888+
}
889+
890+
Iterable<String> _linkedLibraryUriList(LinkedNodeBundle bundle2) {
891+
var libraries = bundle2.libraries;
892+
return libraries.map((l) => l.uriStr).toList();
893+
}
827894
}
828895

829896
@reflectiveTest

pkg/analyzer_cli/test/options_test.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:io';
77
import 'package:analyzer/src/dart/analysis/experiments.dart';
88
import 'package:analyzer/src/dart/analysis/experiments_impl.dart'
99
show overrideKnownFeatures;
10+
import 'package:analyzer/src/dart/analysis/driver.dart';
1011
import 'package:analyzer_cli/src/driver.dart';
1112
import 'package:analyzer_cli/src/options.dart';
1213
import 'package:telemetry/telemetry.dart' as telemetry;
@@ -418,9 +419,19 @@ class CommandLineOptionsTest extends AbstractStatusTest {
418419
'--build-summary-only-unlinked',
419420
'package:p/foo.dart|/path/to/p/lib/foo.dart'
420421
]);
421-
expect(options.buildMode, isTrue);
422-
expect(options.buildSummaryOnly, isTrue);
423-
expect(options.buildSummaryOnlyUnlinked, isTrue);
422+
if (AnalysisDriver.useSummary2) {
423+
expect(
424+
errorStringBuffer.toString(),
425+
contains(
426+
'The option --build-summary-only-unlinked can not be used '
427+
'together with summary2.',
428+
),
429+
);
430+
} else {
431+
expect(options.buildMode, isTrue);
432+
expect(options.buildSummaryOnly, isTrue);
433+
expect(options.buildSummaryOnlyUnlinked, isTrue);
434+
}
424435
}
425436

426437
test_buildSummaryOutput() {

0 commit comments

Comments
 (0)