Skip to content

Commit e7a128e

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
[CFE] Refactor incremental compiler test(s)
Change-Id: I538d5bb5f50af2409d0c99e8ab15b803b9e10fc1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120783 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
1 parent 46a9273 commit e7a128e

File tree

8 files changed

+109
-66
lines changed

8 files changed

+109
-66
lines changed

pkg/front_end/test/incremental_load_from_dill_test.dart

Lines changed: 97 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ import 'dart:io' show Directory, File;
88

99
import 'package:expect/expect.dart' show Expect;
1010

11-
import 'package:front_end/src/base/processed_options.dart'
12-
show ProcessedOptions;
13-
14-
import 'package:front_end/src/fasta/compiler_context.dart' show CompilerContext;
15-
1611
import 'package:front_end/src/api_prototype/compiler_options.dart'
1712
show CompilerOptions;
1813

@@ -22,9 +17,17 @@ import 'package:front_end/src/api_prototype/diagnostic_message.dart'
2217
import "package:front_end/src/api_prototype/memory_file_system.dart"
2318
show MemoryFileSystem;
2419

20+
import 'package:front_end/src/base/processed_options.dart'
21+
show ProcessedOptions;
22+
2523
import 'package:front_end/src/compute_platform_binaries_location.dart'
2624
show computePlatformBinariesLocation;
2725

26+
import 'package:front_end/src/fasta/compiler_context.dart' show CompilerContext;
27+
28+
import 'package:front_end/src/fasta/fasta_codes.dart'
29+
show DiagnosticMessageFromJson, FormattedMessage;
30+
2831
import 'package:front_end/src/fasta/incremental_compiler.dart'
2932
show IncrementalCompiler;
3033

@@ -59,9 +62,6 @@ import 'binary_md_dill_reader.dart' show DillComparer;
5962

6063
import "incremental_utils.dart" as util;
6164

62-
import 'package:front_end/src/fasta/fasta_codes.dart'
63-
show DiagnosticMessageFromJson, FormattedMessage;
64-
6565
import 'utils/io_utils.dart' show computeRepoDir;
6666

6767
main([List<String> arguments = const []]) =>
@@ -335,6 +335,7 @@ Future<Null> newWorldTest(
335335
}
336336
}
337337
}
338+
338339
bool brandNewWorld = true;
339340
if (world["worldType"] == "updated") {
340341
brandNewWorld = false;
@@ -428,10 +429,18 @@ Future<Null> newWorldTest(
428429
if (brandNewWorld) {
429430
if (world["fromComponent"] == true) {
430431
compiler = new TestIncrementalCompiler.fromComponent(
431-
options, entries.first, newestWholeComponent, outlineOnly);
432+
options,
433+
entries.first,
434+
(modulesToUse != null) ? sdk : newestWholeComponent,
435+
outlineOnly);
432436
} else {
433437
compiler = new TestIncrementalCompiler(
434438
options, entries.first, initializeFrom, outlineOnly);
439+
440+
if (modulesToUse != null) {
441+
throw "You probably shouldn't do this! "
442+
"Any modules will have another sdk loaded!";
443+
}
435444
}
436445
}
437446

@@ -559,6 +568,7 @@ Future<Null> newWorldTest(
559568
throw "Expected that initializedFromDill would be "
560569
"$expectInitializeFromDill but was ${compiler.initializedFromDill}";
561570
}
571+
562572
if (world["checkInvalidatedFiles"] != false) {
563573
Set<Uri> filteredInvalidated =
564574
compiler.getFilteredInvalidatedImportUrisForTesting(invalidated);
@@ -576,13 +586,18 @@ Future<Null> newWorldTest(
576586
}
577587
}
578588

579-
if (!noFullComponent) {
580-
Set<String> prevFormattedErrors = formattedErrors.toSet();
581-
Set<String> prevFormattedWarnings = formattedWarnings.toSet();
589+
Set<String> prevFormattedErrors = formattedErrors.toSet();
590+
Set<String> prevFormattedWarnings = formattedWarnings.toSet();
591+
592+
clearPrevErrorsEtc() {
582593
gotError = false;
583594
formattedErrors.clear();
584595
gotWarning = false;
585596
formattedWarnings.clear();
597+
}
598+
599+
if (!noFullComponent) {
600+
clearPrevErrorsEtc();
586601
Component component2 = await compiler.computeDelta(
587602
entryPoints: entries,
588603
fullComponent: true,
@@ -593,29 +608,8 @@ Future<Null> newWorldTest(
593608
print("*****\n\ncomponent2:\n"
594609
"${componentToStringSdkFiltered(component2)}\n\n\n");
595610
checkIsEqual(newestWholeComponentData, thisWholeComponent);
596-
if (prevFormattedErrors.length != formattedErrors.length) {
597-
Expect.fail("Previously had ${prevFormattedErrors.length} errors, "
598-
"now had ${formattedErrors.length}.\n\n"
599-
"Before:\n"
600-
"${prevFormattedErrors.join("\n")}"
601-
"\n\n"
602-
"Now:\n"
603-
"${formattedErrors.join("\n")}");
604-
}
605-
if ((prevFormattedErrors.toSet()..removeAll(formattedErrors))
606-
.isNotEmpty) {
607-
Expect.fail("Previously got error messages $prevFormattedErrors, "
608-
"now had ${formattedErrors}.");
609-
}
610-
if (prevFormattedWarnings.length != formattedWarnings.length) {
611-
Expect.fail("Previously had ${prevFormattedWarnings.length} errors, "
612-
"now had ${formattedWarnings.length}.");
613-
}
614-
if ((prevFormattedWarnings.toSet()..removeAll(formattedWarnings))
615-
.isNotEmpty) {
616-
Expect.fail("Previously got error messages $prevFormattedWarnings, "
617-
"now had ${formattedWarnings}.");
618-
}
611+
checkErrorsAndWarnings(prevFormattedErrors, formattedErrors,
612+
prevFormattedWarnings, formattedWarnings);
619613
}
620614

621615
if (world["expressionCompilation"] != null) {
@@ -626,6 +620,35 @@ Future<Null> newWorldTest(
626620
}
627621
}
628622

623+
void checkErrorsAndWarnings(
624+
Set<String> prevFormattedErrors,
625+
Set<String> formattedErrors,
626+
Set<String> prevFormattedWarnings,
627+
Set<String> formattedWarnings) {
628+
if (prevFormattedErrors.length != formattedErrors.length) {
629+
Expect.fail("Previously had ${prevFormattedErrors.length} errors, "
630+
"now had ${formattedErrors.length}.\n\n"
631+
"Before:\n"
632+
"${prevFormattedErrors.join("\n")}"
633+
"\n\n"
634+
"Now:\n"
635+
"${formattedErrors.join("\n")}");
636+
}
637+
if ((prevFormattedErrors.toSet()..removeAll(formattedErrors)).isNotEmpty) {
638+
Expect.fail("Previously got error messages $prevFormattedErrors, "
639+
"now had ${formattedErrors}.");
640+
}
641+
if (prevFormattedWarnings.length != formattedWarnings.length) {
642+
Expect.fail("Previously had ${prevFormattedWarnings.length} errors, "
643+
"now had ${formattedWarnings.length}.");
644+
}
645+
if ((prevFormattedWarnings.toSet()..removeAll(formattedWarnings))
646+
.isNotEmpty) {
647+
Expect.fail("Previously got error messages $prevFormattedWarnings, "
648+
"now had ${formattedWarnings}.");
649+
}
650+
}
651+
629652
void computeAllReachableLibrariesFor(Library lib, Set<Library> allLibraries) {
630653
Set<Library> libraries = new Set<Library>();
631654
List<Library> workList = <Library>[];
@@ -635,6 +658,7 @@ void computeAllReachableLibrariesFor(Library lib, Set<Library> allLibraries) {
635658
while (workList.isNotEmpty) {
636659
Library library = workList.removeLast();
637660
for (LibraryDependency dependency in library.dependencies) {
661+
if (dependency.targetLibrary.importUri.scheme == "dart") continue;
638662
if (libraries.add(dependency.targetLibrary)) {
639663
workList.add(dependency.targetLibrary);
640664
allLibraries.add(dependency.targetLibrary);
@@ -645,41 +669,49 @@ void computeAllReachableLibrariesFor(Library lib, Set<Library> allLibraries) {
645669

646670
void checkExpectedContent(YamlMap world, Component component) {
647671
if (world["expectedContent"] != null) {
648-
Map<String, Set<String>> actualContent = new Map<String, Set<String>>();
649-
for (Library lib in component.libraries) {
650-
Set<String> libContent =
651-
actualContent[lib.importUri.toString()] = new Set<String>();
652-
for (Class c in lib.classes) {
653-
libContent.add("Class ${c.name}");
654-
}
655-
for (Procedure p in lib.procedures) {
656-
libContent.add("Procedure ${p.name}");
657-
}
658-
for (Field f in lib.fields) {
659-
libContent.add("Field ${f.name}");
660-
}
661-
}
662-
672+
Map<String, Set<String>> actualContent = buildMapOfContent(component);
663673
Map expectedContent = world["expectedContent"];
674+
checkExpectedContentData(actualContent, expectedContent);
675+
}
676+
}
664677

665-
doThrow() {
666-
throw "Expected and actual content not the same.\n"
667-
"Expected $expectedContent.\n"
668-
"Got $actualContent";
669-
}
678+
void checkExpectedContentData(
679+
Map<String, Set<String>> actualContent, Map expectedContent) {
680+
doThrow() {
681+
throw "Expected and actual content not the same.\n"
682+
"Expected $expectedContent.\n"
683+
"Got $actualContent";
684+
}
670685

671-
if (actualContent.length != expectedContent.length) doThrow();
672-
Set<String> missingKeys = actualContent.keys.toSet()
673-
..removeAll(expectedContent.keys);
674-
if (missingKeys.isNotEmpty) doThrow();
675-
for (String key in expectedContent.keys) {
676-
Set<String> expected = new Set<String>.from(expectedContent[key]);
677-
Set<String> actual = actualContent[key].toSet();
678-
if (expected.length != actual.length) doThrow();
679-
actual.removeAll(expected);
680-
if (actual.isNotEmpty) doThrow();
686+
if (actualContent.length != expectedContent.length) doThrow();
687+
Set<String> missingKeys = actualContent.keys.toSet()
688+
..removeAll(expectedContent.keys);
689+
if (missingKeys.isNotEmpty) doThrow();
690+
for (String key in expectedContent.keys) {
691+
Set<String> expected = new Set<String>.from(expectedContent[key]);
692+
Set<String> actual = actualContent[key].toSet();
693+
if (expected.length != actual.length) doThrow();
694+
actual.removeAll(expected);
695+
if (actual.isNotEmpty) doThrow();
696+
}
697+
}
698+
699+
Map<String, Set<String>> buildMapOfContent(Component component) {
700+
Map<String, Set<String>> actualContent = new Map<String, Set<String>>();
701+
for (Library lib in component.libraries) {
702+
Set<String> libContent =
703+
actualContent[lib.importUri.toString()] = new Set<String>();
704+
for (Class c in lib.classes) {
705+
libContent.add("Class ${c.name}");
706+
}
707+
for (Procedure p in lib.procedures) {
708+
libContent.add("Procedure ${p.name}");
709+
}
710+
for (Field f in lib.fields) {
711+
libContent.add("Field ${f.name}");
681712
}
682713
}
714+
return actualContent;
683715
}
684716

685717
void checkNeededDillLibraries(

pkg/front_end/testcases/incremental_initialize_from_dill/changing_modules_10.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ modules:
2020
module:.
2121
worlds:
2222
- entry: main.dart
23+
fromComponent: true
2324
sources:
2425
main.dart: |
2526
import 'package:module/a.dart';

pkg/front_end/testcases/incremental_initialize_from_dill/changing_modules_11.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ modules:
2020
module:.
2121
worlds:
2222
- entry: main.dart
23+
fromComponent: true
2324
sources:
2425
main.dart: |
2526
import 'package:module/a.dart';

pkg/front_end/testcases/incremental_initialize_from_dill/changing_modules_12.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ modules:
2424
module:.
2525
worlds:
2626
- entry: main.dart
27+
fromComponent: true
2728
sources:
2829
main.dart: |
2930
class Foo {}

pkg/front_end/testcases/incremental_initialize_from_dill/changing_modules_13.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# for details. All rights reserved. Use of this source code is governed by a
33
# BSD-style license that can be found in the LICENSE.md file.
44

5-
# Reproduction fo https://github.com/flutter/flutter/issues/40966.
5+
# Reproduction of https://github.com/flutter/flutter/issues/40966.
66

77
type: newworld
88
target: None
@@ -17,6 +17,7 @@ modules:
1717
module:.
1818
worlds:
1919
- entry: main.dart
20+
fromComponent: true
2021
sources:
2122
main.dart: |
2223
import "package:module/a.dart";

pkg/front_end/testcases/incremental_initialize_from_dill/changing_modules_7.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ worlds:
7979
package:module/lib4.dart:
8080
- Class Class4
8181
- entry: compileme.dart
82+
fromComponent: true
83+
expectInitializeFromDill: false
8284
outlineOnly: true
8385
skipOutlineBodyCheck: true
8486
sources:

pkg/front_end/testcases/incremental_initialize_from_dill/changing_modules_9.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ modules:
2525
moduleB:.
2626
worlds:
2727
- entry: main.dart
28+
fromComponent: true
2829
sources:
2930
main.dart: |
3031
import "package:moduleA/a.dart";

pkg/front_end/testcases/incremental_initialize_from_dill/omit_platform_works_3.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ worlds:
7474
main() {
7575
print(lib() + "!!");
7676
}
77+
lib.dart: |
78+
lib() {
79+
return "hello";
80+
}
7781
expectedLibraryCount: 2
7882
expectsPlatform: true
7983
expectInitializeFromDill: true

0 commit comments

Comments
 (0)