Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Isolate.packageConfig,
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 Isolate.packageConfig,
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
56 changes: 40 additions & 16 deletions pkgs/test_core/lib/src/runner/vm/test_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';

import 'package:async/async.dart';
import 'package:frontend_server_client/frontend_server_client.dart';
Expand Down Expand Up @@ -85,21 +86,6 @@ class _TestCompilerForLanguageVersion {
: _dillCachePath = '$dillCachePrefix.'
'${_dillCacheSuffix(_languageVersionComment, enabledExperiments)}';

String _generateEntrypoint(Uri testUri) {
return '''
$_languageVersionComment
import "dart:isolate";

import "package:test_core/src/bootstrap/vm.dart";

import "$testUri" as test;

void main(_, SendPort sendPort) {
internalBootstrapVmTest(() => test.main, sendPort);
}
''';
}

Future<CompilationResponse> compile(Uri mainUri) =>
_compilePool.withResource(() => _compile(mainUri));

Expand All @@ -108,7 +94,12 @@ class _TestCompilerForLanguageVersion {
if (_closeMemo.hasRun) return CompilationResponse._wasShutdown;
CompileResult? compilerOutput;
final tempFile = File(p.join(_outputDillDirectory.path, 'test.dart'))
..writeAsStringSync(_generateEntrypoint(mainUri));
..writeAsStringSync(testBootstrapContents(
testUri: mainUri,
packageConfigUri: await Isolate.packageConfig,
languageVersionComment: _languageVersionComment,
testType: VmTestType.isolate,
));
final testCache = File(_dillCachePath);

try {
Expand Down Expand Up @@ -211,3 +202,36 @@ String _dillCacheSuffix(
}
return base64.encode(utf8.encode(identifierString.toString()));
}

/// Creates bootstrap file contents for running [testUri].
///
/// The [bootstrapType] argument should be either 'Vm' or 'Native' depending on
/// which `internalBootstrap*Test` function should be used.
String testBootstrapContents({
required Uri testUri,
required String languageVersionComment,
required Uri? packageConfigUri,
required VmTestType testType,
}) {
final (argType, argName, bootstrapType) = switch (testType) {
VmTestType.isolate => ('_, SendPort', 'sendPort', 'Vm'),
VmTestType.process => ('List<String>', 'args', 'Native'),
};
return '''
$languageVersionComment

import 'dart:isolate';

import 'package:test_core/src/bootstrap/vm.dart';

import '$testUri' as test;

const packageConfigLocation = '$packageConfigUri';

void main($argType $argName) {
internalBootstrap${bootstrapType}Test(() => test.main, $argName);
}
''';
}

enum VmTestType { isolate, process }