Skip to content

Commit

Permalink
Add package config URI into VM test entrypoints (#2245)
Browse files Browse the repository at this point in the history
Towards #2246 

This will allow a client of the VM service to evaluate the top level
variable and locate the package config used by the test runner.

Add a public `testBootstapContents` function in `test_compiler.dart`
which centralizes the bootstrap templates. Add an argument for the
package config URI and a `VmTestType` which is either "Vm" or
"Native".

Add the first test case in `test_core`. Add the pub dependency and
override for `package:test`, as well as the mono_repo configuration to
run unit tests. Other tests for `test_core` code is under the `test`
package but should be moved eventually.
  • Loading branch information
natebosch authored Jun 27, 2024
1 parent 329c6df commit 4da62ac
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 72 deletions.
122 changes: 97 additions & 25 deletions .github/workflows/dart.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 12 additions & 31 deletions pkgs/test_core/lib/src/runner/vm/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,12 @@ stderr: ${processResult.stderr}''');
if (!file.existsSync()) {
file
..createSync(recursive: true)
..writeAsStringSync(_bootstrapIsolateTestContents(
await absoluteUri(testPath), languageVersionComment));
..writeAsStringSync(testBootstrapContents(
testUri: await absoluteUri(testPath),
languageVersionComment: languageVersionComment,
packageConfigUri: await packageConfigUri,
testType: VmTestType.isolate,
));
}
return file.uri;
}
Expand All @@ -316,40 +320,17 @@ stderr: ${processResult.stderr}''');
if (!file.existsSync()) {
file
..createSync(recursive: true)
..writeAsStringSync(_bootstrapNativeTestContents(
await absoluteUri(testPath), languageVersionComment));
..writeAsStringSync(testBootstrapContents(
testUri: await absoluteUri(testPath),
languageVersionComment: languageVersionComment,
packageConfigUri: await packageConfigUri,
testType: VmTestType.process,
));
}
return file.path;
}
}

/// Creates bootstrap file contents for running [testUri] in a VM isolate.
String _bootstrapIsolateTestContents(
Uri testUri, String languageVersionComment) =>
'''
$languageVersionComment
import "dart:isolate";
import "package:test_core/src/bootstrap/vm.dart";
import "$testUri" as test;
void main(_, SendPort sendPort) {
internalBootstrapVmTest(() => test.main, sendPort);
}
''';

/// Creates bootstrap file contents for running [testUri] as a native
/// executable.
String _bootstrapNativeTestContents(
Uri testUri, String languageVersionComment) =>
'''
$languageVersionComment
import "dart:isolate";
import "package:test_core/src/bootstrap/vm.dart";
import "$testUri" as test;
void main(List<String> args) {
internalBootstrapNativeTest(() => test.main, args);
}
''';

Future<Map<String, dynamic>> _gatherCoverage(Environment environment) async {
final isolateId = Uri.parse(environment.observatoryUrl!.fragment)
.queryParameters['isolateId'];
Expand Down
Loading

0 comments on commit 4da62ac

Please sign in to comment.