2016-05-16 19:53:13 +00:00
|
|
|
// Copyright 2015 The Chromium 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:async';
|
2017-02-06 06:58:49 +00:00
|
|
|
import 'dart:io' as io;
|
2016-05-16 19:53:13 +00:00
|
|
|
|
2017-01-07 00:51:44 +00:00
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
2017-01-09 16:37:00 +00:00
|
|
|
import 'package:flutter_tools/src/base/io.dart';
|
2016-05-16 19:53:13 +00:00
|
|
|
import 'package:flutter_tools/src/cache.dart';
|
|
|
|
import 'package:flutter_tools/src/dart/sdk.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
import 'src/context.dart';
|
|
|
|
|
|
|
|
// This test depends on some files in ///dev/automated_tests/flutter_test/*
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
group('test', () {
|
2017-02-14 01:45:50 +00:00
|
|
|
final String automatedTestsDirectory = fs.path.join('..', '..', 'dev', 'automated_tests');
|
|
|
|
final String flutterTestDirectory = fs.path.join(automatedTestsDirectory, 'flutter_test');
|
2017-01-10 19:31:24 +00:00
|
|
|
|
2016-05-16 19:53:13 +00:00
|
|
|
testUsingContext('TestAsyncUtils guarded function test', () async {
|
|
|
|
Cache.flutterRoot = '../..';
|
2017-01-10 19:31:24 +00:00
|
|
|
return _testFile('test_async_utils_guarded', 1, automatedTestsDirectory, flutterTestDirectory);
|
2016-05-16 19:53:13 +00:00
|
|
|
});
|
|
|
|
testUsingContext('TestAsyncUtils unguarded function test', () async {
|
|
|
|
Cache.flutterRoot = '../..';
|
2017-01-10 19:31:24 +00:00
|
|
|
return _testFile('test_async_utils_unguarded', 1, automatedTestsDirectory, flutterTestDirectory);
|
|
|
|
});
|
|
|
|
testUsingContext('Missing flutter_test dependency', () async {
|
2017-02-14 01:45:50 +00:00
|
|
|
final String missingDependencyTests = fs.path.join('..', '..', 'dev', 'missing_dependency_tests');
|
2017-01-10 19:31:24 +00:00
|
|
|
Cache.flutterRoot = '../..';
|
|
|
|
return _testFile('trivial', 1, missingDependencyTests, missingDependencyTests);
|
2016-05-16 19:53:13 +00:00
|
|
|
});
|
2017-02-06 06:58:49 +00:00
|
|
|
}, skip: io.Platform.isWindows); // TODO(goderbauer): enable when sky_shell is available
|
2016-05-16 19:53:13 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 19:31:24 +00:00
|
|
|
Future<Null> _testFile(String testName, int wantedExitCode, String workingDirectory, String testDirectory) async {
|
2017-02-14 01:45:50 +00:00
|
|
|
final String fullTestName = fs.path.join(testDirectory, '${testName}_test.dart');
|
2017-01-07 00:51:44 +00:00
|
|
|
final File testFile = fs.file(fullTestName);
|
2016-05-16 19:53:13 +00:00
|
|
|
expect(testFile.existsSync(), true);
|
2017-02-14 01:45:50 +00:00
|
|
|
final String fullTestExpectation = fs.path.join(testDirectory, '${testName}_expectation.txt');
|
2017-01-07 00:51:44 +00:00
|
|
|
final File expectationFile = fs.file(fullTestExpectation);
|
2016-05-16 19:53:13 +00:00
|
|
|
expect(expectationFile.existsSync(), true);
|
2017-01-09 16:37:00 +00:00
|
|
|
final ProcessResult exec = await Process.run(
|
2017-02-14 01:45:50 +00:00
|
|
|
fs.path.join(dartSdkPath, 'bin', 'dart'),
|
2016-05-16 19:53:13 +00:00
|
|
|
<String>[
|
2017-02-14 01:45:50 +00:00
|
|
|
fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')),
|
2016-05-16 19:53:13 +00:00
|
|
|
'test',
|
2016-06-14 17:16:08 +00:00
|
|
|
'--no-color',
|
2016-05-16 19:53:13 +00:00
|
|
|
fullTestName
|
|
|
|
],
|
2017-01-10 19:31:24 +00:00
|
|
|
workingDirectory: workingDirectory
|
2016-05-16 19:53:13 +00:00
|
|
|
);
|
2016-06-14 17:16:08 +00:00
|
|
|
expect(exec.exitCode, wantedExitCode);
|
2016-05-16 19:53:13 +00:00
|
|
|
final List<String> output = exec.stdout.split('\n');
|
2017-01-10 19:31:24 +00:00
|
|
|
output.add('<<stderr>>');
|
|
|
|
output.addAll(exec.stderr.split('\n'));
|
2017-01-07 00:51:44 +00:00
|
|
|
final List<String> expectations = fs.file(fullTestExpectation).readAsLinesSync();
|
2016-05-16 19:53:13 +00:00
|
|
|
bool allowSkip = false;
|
|
|
|
int expectationLineNumber = 0;
|
|
|
|
int outputLineNumber = 0;
|
2017-01-10 19:31:24 +00:00
|
|
|
bool haveSeenStdErrMarker = false;
|
2016-05-16 19:53:13 +00:00
|
|
|
while (expectationLineNumber < expectations.length) {
|
|
|
|
expect(output, hasLength(greaterThan(outputLineNumber)));
|
|
|
|
final String expectationLine = expectations[expectationLineNumber];
|
|
|
|
final String outputLine = output[outputLineNumber];
|
|
|
|
if (expectationLine == '<<skip until matching line>>') {
|
|
|
|
allowSkip = true;
|
|
|
|
expectationLineNumber += 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (allowSkip) {
|
|
|
|
if (!new RegExp(expectationLine).hasMatch(outputLine)) {
|
|
|
|
outputLineNumber += 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
allowSkip = false;
|
|
|
|
}
|
2017-01-10 19:31:24 +00:00
|
|
|
if (expectationLine == '<<stderr>>') {
|
|
|
|
expect(haveSeenStdErrMarker, isFalse);
|
|
|
|
haveSeenStdErrMarker = true;
|
|
|
|
}
|
2017-02-03 21:55:07 +00:00
|
|
|
expect(outputLine, matches(expectationLine), verbose: true, reason: 'Full output:\n- - - -----8<----- - - -\n${output.join("\n")}\n- - - -----8<----- - - -');
|
2016-05-16 19:53:13 +00:00
|
|
|
expectationLineNumber += 1;
|
|
|
|
outputLineNumber += 1;
|
|
|
|
}
|
|
|
|
expect(allowSkip, isFalse);
|
2017-01-10 19:31:24 +00:00
|
|
|
if (!haveSeenStdErrMarker)
|
|
|
|
expect(exec.stderr, '');
|
2016-05-16 19:53:13 +00:00
|
|
|
}
|