4ee5fd243f
This eliminates a lot of really noisy boilerplate in the upcoming FantasyRepo implementation. The test only verifies that the pathway works, we rely on MultiFutureTracker working to actually restrict properly. Change-Id: Ia88d0b24dd739ab1cd4a661325214395bf37eef3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133742 Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Janice Collins <jcollins@google.com>
132 lines
4.1 KiB
Dart
132 lines
4.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:nnbd_migration/src/utilities/subprocess_launcher.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:test/test.dart';
|
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
main() {
|
|
defineReflectiveSuite(() {
|
|
defineReflectiveTests(SubprocessLauncherTest);
|
|
});
|
|
}
|
|
|
|
@reflectiveTest
|
|
class SubprocessLauncherTest {
|
|
Function(String) outputCallback;
|
|
List<String> output;
|
|
Directory tempDir;
|
|
|
|
void setUp() async {
|
|
output = [];
|
|
outputCallback = output.add;
|
|
tempDir = await Directory.systemTemp.createTemp();
|
|
}
|
|
|
|
void tearDown() async {
|
|
await tempDir.delete(recursive: true);
|
|
}
|
|
|
|
Future<void> test_subprocessWorksViaParallelSubprocessLimit() async {
|
|
SubprocessLauncher launcher =
|
|
SubprocessLauncher('test_subprocessWorksViaParallelSubprocessLimit');
|
|
|
|
await launcher.runStreamed(Platform.resolvedExecutable, ['--version'],
|
|
perLine: outputCallback);
|
|
expect(output, anyElement(contains('Dart')));
|
|
}
|
|
|
|
Future<void> test_subprocessRunsValidExecutable() async {
|
|
SubprocessLauncher launcher =
|
|
SubprocessLauncher('test_subprocessRunsValidExecutable');
|
|
|
|
await launcher.runStreamedImmediate(
|
|
Platform.resolvedExecutable, ['--version'],
|
|
perLine: outputCallback);
|
|
expect(output, anyElement(contains('Dart')));
|
|
}
|
|
|
|
Future<void> test_subprocessPassesArgs() async {
|
|
SubprocessLauncher launcher =
|
|
SubprocessLauncher('test_subprocessPassesArgs');
|
|
File testScript =
|
|
File(path.join(tempDir.path, 'subprocess_test_script.dart'));
|
|
await testScript.writeAsString(r'''
|
|
import 'dart:io';
|
|
|
|
main(List<String> args) {
|
|
print('args: $args');
|
|
}''');
|
|
|
|
await launcher.runStreamedImmediate(
|
|
Platform.resolvedExecutable, [testScript.path, 'testArgument'],
|
|
perLine: outputCallback);
|
|
expect(output, anyElement(contains('args: [testArgument]')));
|
|
}
|
|
|
|
Future<void> test_subprocessPassesEnvironment() async {
|
|
SubprocessLauncher launcher =
|
|
SubprocessLauncher('test_subprocessPassesEnvironment');
|
|
File testScript =
|
|
File(path.join(tempDir.path, 'subprocess_test_script.dart'));
|
|
await testScript.writeAsString(r'''
|
|
import 'dart:io';
|
|
|
|
main(List<String> args) {
|
|
print('environment: ${Platform.environment}');
|
|
}''');
|
|
|
|
await launcher.runStreamedImmediate(
|
|
Platform.resolvedExecutable, [testScript.path],
|
|
environment: {'__SUBPROCESS_PASSES_ENVIRONMENT_TEST': 'yes'},
|
|
perLine: outputCallback);
|
|
expect(
|
|
output,
|
|
anyElement(contains(RegExp(
|
|
'^environment: .*__SUBPROCESS_PASSES_ENVIRONMENT_TEST: yes'))));
|
|
}
|
|
|
|
Future<void> test_subprocessSetsWorkingDirectory() async {
|
|
SubprocessLauncher launcher =
|
|
SubprocessLauncher('test_subprocessSetsWorkingDirectory');
|
|
File testScript =
|
|
File(path.join(tempDir.path, 'subprocess_test_script.dart'));
|
|
await testScript.writeAsString(r'''
|
|
import 'dart:io';
|
|
|
|
main() {
|
|
print('working directory: ${Directory.current.path}');
|
|
}''');
|
|
|
|
await launcher.runStreamedImmediate(
|
|
Platform.resolvedExecutable, [testScript.path],
|
|
workingDirectory: tempDir.path, perLine: outputCallback);
|
|
expect(
|
|
output,
|
|
anyElement(contains(
|
|
'working directory: ${tempDir.resolveSymbolicLinksSync()}')));
|
|
}
|
|
|
|
Future<void> test_subprocessThrowsOnNonzeroExitCode() async {
|
|
SubprocessLauncher launcher =
|
|
SubprocessLauncher('test_subprocessThrowsOnNonzeroExitCode');
|
|
File testScript =
|
|
File(path.join(tempDir.path, 'subprocess_test_script.dart'));
|
|
await testScript.writeAsString(r'''
|
|
import 'dart:io';
|
|
|
|
main() {
|
|
exit(1);
|
|
}''');
|
|
await expectLater(
|
|
() async => await launcher.runStreamedImmediate(
|
|
Platform.resolvedExecutable, [testScript.path],
|
|
perLine: outputCallback),
|
|
throwsA(TypeMatcher<ProcessException>()));
|
|
}
|
|
}
|