99cff54882
This CL introduces a test runner and test cases under `pkg/dynamic_modules/test/`. These tests are end-to-end tests that specifically target the dynamic modules semantics. This includes: * semantics expecations on the program evolutions (e.g. libraries defined only once) * individual cases around the dynamic interface (callable, extensible, overrides). We should continue to add more test as we discover coner cases worth validating (e.g. mixins, constants, etc). The suite is not yet integrated to the test matrix, my plan is to do so after we have some initial targets set up. Change-Id: I2a63946c36d99baacb6fb7edc01c4ef377ce20b6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379921 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Sigmund Cherem <sigmund@google.com>
59 lines
2.0 KiB
Dart
59 lines
2.0 KiB
Dart
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
import 'model.dart';
|
|
|
|
/// Returns the [DynamicModuleTest] associated with a folder under [uri].
|
|
DynamicModuleTest loadTest(Uri uri) {
|
|
var folder = Directory.fromUri(uri);
|
|
var testUri = folder.uri; // normalized in case the trailing '/' was missing.
|
|
final name = testUri.pathSegments.lastWhere((s) => s.isNotEmpty);
|
|
String? main;
|
|
String? interface;
|
|
final dynamicModules = <String, String>{};
|
|
for (var entry in folder.listSync(recursive: true)) {
|
|
var entryUri = entry.uri;
|
|
if (entry is! File) continue;
|
|
var filePath = entryUri.path.substring(testUri.path.length);
|
|
|
|
if (filePath == 'dynamic_interface.yaml') {
|
|
interface = filePath;
|
|
continue;
|
|
}
|
|
|
|
if (!filePath.endsWith('.dart')) continue;
|
|
if (filePath == 'main.dart') {
|
|
main = filePath;
|
|
} else if (filePath.startsWith('modules/entry')) {
|
|
var moduleName = filePath.substring('modules/'.length);
|
|
assert(!dynamicModules.containsKey(moduleName));
|
|
dynamicModules[moduleName] = filePath;
|
|
}
|
|
}
|
|
|
|
// Validate the test is well structured
|
|
if (main == null) {
|
|
throw UnsupportedError("missing main.dart entrypoint in '$name'");
|
|
}
|
|
if (interface == null) {
|
|
throw UnsupportedError("missing dynamic_interface.yaml in '$name'");
|
|
}
|
|
if (dynamicModules.isEmpty) {
|
|
throw UnsupportedError("no dynamic modules found in '$name'");
|
|
}
|
|
return DynamicModuleTest(name, testUri, main, interface, dynamicModules);
|
|
}
|
|
|
|
/// Returns all [DynamicModuleTests]s under [uri], one per subfolder.
|
|
List<DynamicModuleTest> loadAllTests(Uri uri) {
|
|
var folder = Directory.fromUri(uri);
|
|
final result = <DynamicModuleTest>[];
|
|
for (var entry in folder.listSync(recursive: false)) {
|
|
if (entry is! Directory) continue;
|
|
result.add(loadTest(entry.uri));
|
|
}
|
|
return result;
|
|
}
|