Handle missing flutter_test dependency cleanly (#7421)

We now produce a more reasonable error message when we're missing the
flutter_test dependency in a test. Also, remove the flutter_tools stack traces
when the engine dies.

Fixes #6187
This commit is contained in:
Adam Barth
2017-01-10 11:31:24 -08:00
committed by GitHub
parent 2155fb74b6
commit b9f49a40f7
6 changed files with 63 additions and 14 deletions

View File

@@ -17,23 +17,30 @@ import 'src/context.dart';
void main() {
group('test', () {
final String automatedTestsDirectory = path.join('..', '..', 'dev', 'automated_tests');
final String flutterTestDirectory = path.join(automatedTestsDirectory, 'flutter_test');
testUsingContext('TestAsyncUtils guarded function test', () async {
Cache.flutterRoot = '../..';
return _testFile('test_async_utils_guarded', 1);
return _testFile('test_async_utils_guarded', 1, automatedTestsDirectory, flutterTestDirectory);
});
testUsingContext('TestAsyncUtils unguarded function test', () async {
Cache.flutterRoot = '../..';
return _testFile('test_async_utils_unguarded', 1);
return _testFile('test_async_utils_unguarded', 1, automatedTestsDirectory, flutterTestDirectory);
});
testUsingContext('Missing flutter_test dependency', () async {
final String missingDependencyTests = path.join('..', '..', 'dev', 'missing_dependency_tests');
Cache.flutterRoot = '../..';
return _testFile('trivial', 1, missingDependencyTests, missingDependencyTests);
});
}, timeout: new Timeout(const Duration(seconds: 5)));
}
Future<Null> _testFile(String testName, int wantedExitCode) async {
final String manualTestsDirectory = path.join('..', '..', 'dev', 'automated_tests');
final String fullTestName = path.join(manualTestsDirectory, 'flutter_test', '${testName}_test.dart');
Future<Null> _testFile(String testName, int wantedExitCode, String workingDirectory, String testDirectory) async {
final String fullTestName = path.join(testDirectory, '${testName}_test.dart');
final File testFile = fs.file(fullTestName);
expect(testFile.existsSync(), true);
final String fullTestExpectation = path.join(manualTestsDirectory, 'flutter_test', '${testName}_expectation.txt');
final String fullTestExpectation = path.join(testDirectory, '${testName}_expectation.txt');
final File expectationFile = fs.file(fullTestExpectation);
expect(expectationFile.existsSync(), true);
final ProcessResult exec = await Process.run(
@@ -44,14 +51,17 @@ Future<Null> _testFile(String testName, int wantedExitCode) async {
'--no-color',
fullTestName
],
workingDirectory: manualTestsDirectory
workingDirectory: workingDirectory
);
expect(exec.exitCode, wantedExitCode);
final List<String> output = exec.stdout.split('\n');
output.add('<<stderr>>');
output.addAll(exec.stderr.split('\n'));
final List<String> expectations = fs.file(fullTestExpectation).readAsLinesSync();
bool allowSkip = false;
int expectationLineNumber = 0;
int outputLineNumber = 0;
bool haveSeenStdErrMarker = false;
while (expectationLineNumber < expectations.length) {
expect(output, hasLength(greaterThan(outputLineNumber)));
final String expectationLine = expectations[expectationLineNumber];
@@ -68,10 +78,15 @@ Future<Null> _testFile(String testName, int wantedExitCode) async {
}
allowSkip = false;
}
if (expectationLine == '<<stderr>>') {
expect(haveSeenStdErrMarker, isFalse);
haveSeenStdErrMarker = true;
}
expect(outputLine, matches(expectationLine));
expectationLineNumber += 1;
outputLineNumber += 1;
}
expect(allowSkip, isFalse);
expect(exec.stderr, '');
if (!haveSeenStdErrMarker)
expect(exec.stderr, '');
}