[flutter_tools] Make setting of CWD consistent for flutter test (#74622)

This commit is contained in:
Jia Hao
2021-01-26 14:34:03 +08:00
committed by GitHub
parent 2eeeba9c09
commit 22f1700427
10 changed files with 26 additions and 24 deletions

View File

@@ -219,18 +219,17 @@ class TestCommand extends FlutterCommand {
);
}
Directory workDir;
if (files.isEmpty) {
// We don't scan the entire package, only the test/ subdirectory, so that
// files with names like like "hit_test.dart" don't get run.
workDir = globals.fs.directory('test');
if (!workDir.existsSync()) {
throwToolExit('Test directory "${workDir.path}" not found.');
final Directory testDir = globals.fs.directory('test');
if (!testDir.existsSync()) {
throwToolExit('Test directory "${testDir.path}" not found.');
}
files = _findTests(workDir).toList();
files = _findTests(testDir).toList();
if (files.isEmpty) {
throwToolExit(
'Test directory "${workDir.path}" does not appear to contain any test files.\n'
'Test directory "${testDir.path}" does not appear to contain any test files.\n'
'Test files must be in that directory and end with the pattern "_test.dart".'
);
}
@@ -269,7 +268,6 @@ class TestCommand extends FlutterCommand {
final int result = await testRunner.runTests(
testWrapper,
files,
workDir: workDir,
names: names,
plainNames: plainNames,
tags: tags,

View File

@@ -27,7 +27,6 @@ abstract class FlutterTestRunner {
Future<int> runTests(
TestWrapper testWrapper,
List<String> testFiles, {
Directory workDir,
List<String> names = const <String>[],
List<String> plainNames = const <String>[],
String tags,
@@ -64,7 +63,6 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
Future<int> runTests(
TestWrapper testWrapper,
List<String> testFiles, {
Directory workDir,
List<String> names = const <String>[],
List<String> plainNames = const <String>[],
String tags,
@@ -206,14 +204,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
additionalArguments: additionalArguments,
);
// Call package:test's main method in the appropriate directory.
final Directory saved = globals.fs.currentDirectory;
try {
if (workDir != null) {
globals.printTrace('switching to directory $workDir to run tests');
globals.fs.currentDirectory = workDir;
}
globals.printTrace('running test package with arguments: $testArgs');
await testWrapper.main(testArgs);
@@ -222,7 +213,6 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
return exitCode;
} finally {
globals.fs.currentDirectory = saved.path;
await platform.close();
}
}