[flutter_tools] Make setting of CWD consistent for flutter test (#74622)
This commit is contained in:
parent
2eeeba9c09
commit
22f1700427
@ -0,0 +1 @@
|
|||||||
|
[0-9]+:[0-9]+ [+]1: All tests passed!
|
12
dev/automated_tests/flutter_test/working_directory_test.dart
Normal file
12
dev/automated_tests/flutter_test/working_directory_test.dart
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. 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:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('working directory is the root of this package', () {
|
||||||
|
expect(Directory.current.path, endsWith('automated_tests'));
|
||||||
|
});
|
||||||
|
}
|
@ -10,8 +10,6 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:vitool/vitool.dart';
|
import 'package:vitool/vitool.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
const String kPackagePath = '..';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
test('parsePixels', () {
|
test('parsePixels', () {
|
||||||
@ -694,5 +692,5 @@ class PathAnimationMatcher extends Matcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String testAsset(String name) {
|
String testAsset(String name) {
|
||||||
return path.join(kPackagePath, 'test_assets', name);
|
return path.join('test_assets', name);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
|
|
||||||
import '../test_utils.dart';
|
import '../test_utils.dart';
|
||||||
|
|
||||||
final String rootDirectoryPath = Directory.current.parent.path;
|
final String rootDirectoryPath = Directory.current.path;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
for (final String language in kCupertinoSupportedLanguages) {
|
for (final String language in kCupertinoSupportedLanguages) {
|
||||||
|
@ -13,7 +13,7 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
|
|
||||||
import '../test_utils.dart';
|
import '../test_utils.dart';
|
||||||
|
|
||||||
final String rootDirectoryPath = Directory.current.parent.path;
|
final String rootDirectoryPath = Directory.current.path;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
for (final String language in kMaterialSupportedLanguages) {
|
for (final String language in kMaterialSupportedLanguages) {
|
||||||
|
@ -140,7 +140,6 @@ Future<void> run(List<String> args) async {
|
|||||||
exitCode = await const FlutterTestRunner().runTests(
|
exitCode = await const FlutterTestRunner().runTests(
|
||||||
const TestWrapper(),
|
const TestWrapper(),
|
||||||
tests.keys.toList(),
|
tests.keys.toList(),
|
||||||
workDir: testDirectory,
|
|
||||||
watcher: collector,
|
watcher: collector,
|
||||||
ipv6: false,
|
ipv6: false,
|
||||||
enableObservatory: collector != null,
|
enableObservatory: collector != null,
|
||||||
|
@ -219,18 +219,17 @@ class TestCommand extends FlutterCommand {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory workDir;
|
|
||||||
if (files.isEmpty) {
|
if (files.isEmpty) {
|
||||||
// We don't scan the entire package, only the test/ subdirectory, so that
|
// 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.
|
// files with names like like "hit_test.dart" don't get run.
|
||||||
workDir = globals.fs.directory('test');
|
final Directory testDir = globals.fs.directory('test');
|
||||||
if (!workDir.existsSync()) {
|
if (!testDir.existsSync()) {
|
||||||
throwToolExit('Test directory "${workDir.path}" not found.');
|
throwToolExit('Test directory "${testDir.path}" not found.');
|
||||||
}
|
}
|
||||||
files = _findTests(workDir).toList();
|
files = _findTests(testDir).toList();
|
||||||
if (files.isEmpty) {
|
if (files.isEmpty) {
|
||||||
throwToolExit(
|
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".'
|
'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(
|
final int result = await testRunner.runTests(
|
||||||
testWrapper,
|
testWrapper,
|
||||||
files,
|
files,
|
||||||
workDir: workDir,
|
|
||||||
names: names,
|
names: names,
|
||||||
plainNames: plainNames,
|
plainNames: plainNames,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
|
@ -27,7 +27,6 @@ abstract class FlutterTestRunner {
|
|||||||
Future<int> runTests(
|
Future<int> runTests(
|
||||||
TestWrapper testWrapper,
|
TestWrapper testWrapper,
|
||||||
List<String> testFiles, {
|
List<String> testFiles, {
|
||||||
Directory workDir,
|
|
||||||
List<String> names = const <String>[],
|
List<String> names = const <String>[],
|
||||||
List<String> plainNames = const <String>[],
|
List<String> plainNames = const <String>[],
|
||||||
String tags,
|
String tags,
|
||||||
@ -64,7 +63,6 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
|||||||
Future<int> runTests(
|
Future<int> runTests(
|
||||||
TestWrapper testWrapper,
|
TestWrapper testWrapper,
|
||||||
List<String> testFiles, {
|
List<String> testFiles, {
|
||||||
Directory workDir,
|
|
||||||
List<String> names = const <String>[],
|
List<String> names = const <String>[],
|
||||||
List<String> plainNames = const <String>[],
|
List<String> plainNames = const <String>[],
|
||||||
String tags,
|
String tags,
|
||||||
@ -206,14 +204,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
|||||||
additionalArguments: additionalArguments,
|
additionalArguments: additionalArguments,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Call package:test's main method in the appropriate directory.
|
|
||||||
final Directory saved = globals.fs.currentDirectory;
|
|
||||||
try {
|
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');
|
globals.printTrace('running test package with arguments: $testArgs');
|
||||||
await testWrapper.main(testArgs);
|
await testWrapper.main(testArgs);
|
||||||
|
|
||||||
@ -222,7 +213,6 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
|||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
} finally {
|
} finally {
|
||||||
globals.fs.currentDirectory = saved.path;
|
|
||||||
await platform.close();
|
await platform.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,10 @@ void main() {
|
|||||||
return _testFile('trivial_widget', automatedTestsDirectory, flutterTestDirectory, exitCode: isZero);
|
return _testFile('trivial_widget', automatedTestsDirectory, flutterTestDirectory, exitCode: isZero);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWithoutContext('flutter test set the working directory correctly', () async {
|
||||||
|
return _testFile('working_directory', automatedTestsDirectory, flutterTestDirectory, exitCode: isZero);
|
||||||
|
});
|
||||||
|
|
||||||
testWithoutContext('flutter test should report nice errors for exceptions thrown within testWidgets()', () async {
|
testWithoutContext('flutter test should report nice errors for exceptions thrown within testWidgets()', () async {
|
||||||
return _testFile('exception_handling', automatedTestsDirectory, flutterTestDirectory);
|
return _testFile('exception_handling', automatedTestsDirectory, flutterTestDirectory);
|
||||||
});
|
});
|
||||||
|
@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
final String bat = Platform.isWindows ? '.bat' : '';
|
final String bat = Platform.isWindows ? '.bat' : '';
|
||||||
final String _flutterBin = path.join(Directory.current.parent.parent.parent.path, 'bin', 'flutter$bat');
|
final String _flutterBin = path.join(Directory.current.parent.parent.path, 'bin', 'flutter$bat');
|
||||||
const String _integrationResultsPrefix =
|
const String _integrationResultsPrefix =
|
||||||
'IntegrationTestWidgetsFlutterBinding test results:';
|
'IntegrationTestWidgetsFlutterBinding test results:';
|
||||||
const String _failureExcerpt = r'Expected: <false>\n Actual: <true>';
|
const String _failureExcerpt = r'Expected: <false>\n Actual: <true>';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user