dart-sdk/tests/lib/isolate/no_package_test.dart
Alexander Markov 18b2f6db03 [test] Fix lib/isolate/no_package_test for Windows
The test was using file path as an URI, which is not correct on
Windows.

Change-Id: I097821a1090016994baf7bab66440ca83a58564f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167500
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2020-10-13 23:56:50 +00:00

69 lines
2.1 KiB
Dart

// Copyright (c) 2020, 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 "package:async_helper/async_minitest.dart";
void testNoPackages(String filePath, Uri uri, String expected) {
File mainIsolate = new File(filePath);
mainIsolate.writeAsStringSync('''
library spawn_tests;
import \'dart:isolate\';
void main() async {
const String debugName = \'spawnedIsolate\';
final exitPort = ReceivePort();
final port = new ReceivePort();
port.listen((msg) {
print(msg);
port.close();
});
final isolate = await Isolate.spawnUri(
Uri.parse(\'$uri\'),
[\'$expected\'],
port.sendPort,
paused: false,
debugName: debugName,
onExit: exitPort.sendPort);
// Explicitly await spawned isolate exit to enforce main isolate not
// completing (and the stand-alone runtime exiting) before the spawned
// isolate is done.
await exitPort.first;
}
''');
var exec = Platform.resolvedExecutable;
var args = <String>[];
args.add(mainIsolate.path);
var result = Process.runSync(exec, args);
print('stdout: ${result.stdout}');
print('stderr: ${result.stderr}');
expect(result.stdout.contains('$expected'), true);
}
void main() {
// Create temporary directory.
var tmpDir = Directory.systemTemp.createTempSync();
var tmpDirPath = tmpDir.path;
// Generate code for an isolate to run without any package specification.
File noPackageIsolate = new File("$tmpDirPath/no_package.dart");
noPackageIsolate.writeAsStringSync('''
library SpawnUriIsolate;
main(List<String> args, replyTo) {
var data = args[0];
replyTo.send(data);
}
''');
try {
// Isolate Spawning another Isolate without any package specification.
testNoPackages("$tmpDirPath/no_package_isolate.dart",
Uri.file(noPackageIsolate.path), 're: no package');
} finally {
tmpDir.deleteSync(recursive: true);
}
}