Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5829fc7

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[analyzer,cfe,dart2js] Add marker.options files to automate running id tests on all configurations
Change-Id: Ib5eb7f3967634721047f8dcc57b9e6c350b91a41 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136226 Reviewed-by: Dmitry Stefantsov <dmitryas@google.com> Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
1 parent d986ab8 commit 5829fc7

File tree

62 files changed

+168
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+168
-40
lines changed

pkg/_fe_analyzer_shared/lib/src/testing/id_testing.dart

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,20 +628,95 @@ typedef Future<Map<String, TestResult<T>>> RunTestFunction<T>(TestData testData,
628628
Map<String, List<String>> skipMap,
629629
Uri nullUri});
630630

631+
class MarkerOptions {
632+
final Map<String, Uri> markers;
633+
634+
MarkerOptions.internal(this.markers);
635+
636+
factory MarkerOptions.fromFile(File file, {bool isUsingShards: false}) {
637+
File script = new File.fromUri(Platform.script);
638+
if (!file.existsSync()) {
639+
throw new ArgumentError("Marker option file '$file' doesn't exist.");
640+
}
641+
642+
Map<String, Uri> markers = {};
643+
String text = file.readAsStringSync();
644+
bool isScriptFound = false;
645+
for (String line in text.split('\n')) {
646+
line = line.trim();
647+
if (line.isEmpty || line.startsWith('#')) continue;
648+
int eqPos = line.indexOf('=');
649+
if (eqPos == -1) {
650+
throw new ArgumentError(
651+
"Unsupported marker option '$line' in ${file.uri}");
652+
}
653+
String marker = line.substring(0, eqPos);
654+
String tester = line.substring(eqPos + 1);
655+
File testerFile = new File(tester);
656+
if (!testerFile.existsSync()) {
657+
throw new ArgumentError(
658+
"Tester '$tester' does not exist for marker '$marker' in "
659+
"${file.uri}");
660+
}
661+
if (markers.containsKey(marker)) {
662+
throw new ArgumentError("Duplicate marker '$marker' in ${file.uri}");
663+
}
664+
markers[marker] = testerFile.uri;
665+
if (testerFile.absolute.uri == script.absolute.uri) {
666+
isScriptFound = true;
667+
}
668+
}
669+
if (!isUsingShards && !isScriptFound) {
670+
throw new ArgumentError(
671+
"Script '${script.uri}' not found in ${file.uri}");
672+
}
673+
return new MarkerOptions.internal(markers);
674+
}
675+
676+
Iterable<String> get supportedMarkers => markers.keys;
677+
678+
Future<void> runAll(List<String> args) async {
679+
Set<Uri> testers = markers.values.toSet();
680+
bool allOk = true;
681+
for (Uri tester in testers) {
682+
print('================================================================');
683+
print('Running tester: $tester ${args.join(' ')}');
684+
print('================================================================');
685+
Process process = await Process.start(
686+
Platform.resolvedExecutable, [tester.toString(), ...args],
687+
mode: ProcessStartMode.inheritStdio);
688+
if (await process.exitCode != 0) {
689+
allOk = false;
690+
}
691+
}
692+
if (!allOk) {
693+
throw "Error(s) occurred.";
694+
}
695+
}
696+
}
697+
631698
/// Check code for all tests in [dataDir] using [runTest].
632699
Future<void> runTests<T>(Directory dataDir,
633700
{List<String> args: const <String>[],
634701
int shards: 1,
635702
int shardIndex: 0,
636703
void onTest(Uri uri),
637-
Iterable<String> supportedMarkers,
638704
Uri createUriForFileName(String fileName),
639705
void onFailure(String message),
640706
RunTestFunction<T> runTest,
641707
List<String> skipList,
642708
Map<String, List<String>> skipMap}) async {
709+
File markerOptionsFile =
710+
new File.fromUri(dataDir.uri.resolve('marker.options'));
711+
MarkerOptions markerOptions =
712+
new MarkerOptions.fromFile(markerOptionsFile, isUsingShards: shards != 1);
643713
// TODO(johnniwinther): Support --show to show actual data for an input.
644714
args = args.toList();
715+
bool runAll = args.remove('--run-all');
716+
if (runAll) {
717+
await markerOptions.runAll(args);
718+
return;
719+
}
645720
bool verbose = args.remove('-v');
646721
bool succinct = args.remove('-s');
647722
bool shouldContinue = args.remove('-c');
@@ -653,8 +728,11 @@ Future<void> runTests<T>(Directory dataDir,
653728

654729
String relativeDir = dataDir.uri.path.replaceAll(Uri.base.path, '');
655730
print('Data dir: ${relativeDir}');
656-
List<FileSystemEntity> entities =
657-
dataDir.listSync().where((entity) => !entity.path.endsWith('~')).toList();
731+
List<FileSystemEntity> entities = dataDir
732+
.listSync()
733+
.where((entity) =>
734+
!entity.path.endsWith('~') && !entity.path.endsWith('marker.options'))
735+
.toList();
658736
if (shards > 1) {
659737
int start = entities.length * shardIndex ~/ shards;
660738
int end = entities.length * (shardIndex + 1) ~/ shards;
@@ -688,7 +766,7 @@ Future<void> runTests<T>(Directory dataDir,
688766
}
689767

690768
TestData testData = computeTestData(entity,
691-
supportedMarkers: supportedMarkers,
769+
supportedMarkers: markerOptions.supportedMarkers,
692770
createTestUri: createTestUri,
693771
onFailure: onFailure);
694772
print('Test: ${testData.testFileUri}');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cfe=pkg/front_end/test/id_tests/constant_test.dart
2+
analyzer=pkg/analyzer/test/id_tests/constant_test.dart
3+
dart2js=tests/compiler/dart2js/model/cfe_constant_test.dart
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cfe=pkg/front_end/test/id_tests/assigned_variables_test.dart
2+
analyzer=pkg/analyzer/test/id_tests/assigned_variables_test.dart
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cfe=pkg/front_end/test/id_tests/definite_assignment_test.dart
2+
analyzer=pkg/analyzer/test/id_tests/definite_assignment_test.dart
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cfe=pkg/front_end/test/id_tests/nullability_test.dart
2+
analyzer=pkg/analyzer/test/id_tests/nullability_test.dart
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cfe=pkg/front_end/test/id_tests/reachability_test.dart
2+
analyzer=pkg/analyzer/test/id_tests/reachability_test.dart
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cfe=pkg/front_end/test/id_tests/type_promotion_test.dart
2+
analyzer=pkg/analyzer/test/id_tests/type_promotion_test.dart
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cfe=pkg/front_end/test/id_tests/inheritance_test.dart
2+
cfe:builder=pkg/front_end/test/id_tests/inheritance_test.dart

pkg/analyzer/test/id_tests/assigned_variables_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ main(List<String> args) async {
2323
await NullSafetyUnderstandingFlag.enableNullSafetyTypes(() {
2424
return runTests<_Data>(dataDir,
2525
args: args,
26-
supportedMarkers: cfeAnalyzerMarkers,
2726
createUriForFileName: createUriForFileName,
2827
onFailure: onFailure,
2928
runTest: runTestFor(

pkg/analyzer/test/id_tests/constant_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ main(List<String> args) async {
2222
await NullSafetyUnderstandingFlag.enableNullSafetyTypes(() {
2323
return runTests<String>(dataDir,
2424
args: args,
25-
supportedMarkers: sharedMarkers,
2625
createUriForFileName: createUriForFileName,
2726
onFailure: onFailure,
2827
runTest: runTestFor(

0 commit comments

Comments
 (0)