Commit db884141 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Upgrade to the most recent test package. (#11526)

Also, add tests to verify that our coverage is actually being tested!
parent 1e53d320
The files in this directory are used as part of tests in the The files in this directory are used as part of tests in the
`flutter_tools` package. They are here because here these tests need a `flutter_tools` package. Some are here because here these tests need a
`pubspec.yaml` that references the flutter framework (which is `pubspec.yaml` that references the flutter framework (which is
intentionally not true of the `flutter_tools` package). intentionally not true of the `flutter_tools` package). Others are
here mostly out of peer pressure.
// Copyright 2017 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 'package:test/test.dart';
void main() {
test('trivial', () { });
}
...@@ -145,9 +145,23 @@ Future<Null> _runCoverage() async { ...@@ -145,9 +145,23 @@ Future<Null> _runCoverage() async {
return; return;
} }
final File coverageFile = new File(path.join(flutterRoot, 'packages', 'flutter', 'coverage', 'lcov.info'));
if (!coverageFile.existsSync()) {
print('${red}Coverage file not found.$reset');
print('Expected to find: ${coverageFile.absolute}');
print('This file is normally obtained by running `flutter update-packages`.');
exit(1);
}
coverageFile.deleteSync();
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter'), await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter'),
options: const <String>['--coverage'], options: const <String>['--coverage'],
); );
if (!coverageFile.existsSync()) {
print('${red}Coverage file not found.$reset');
print('Expected to find: ${coverageFile.absolute}');
print('This file should have been generated by the `flutter test --coverage` script, but was not.');
exit(1);
}
print('${bold}DONE: Coverage collection successful.$reset'); print('${bold}DONE: Coverage collection successful.$reset');
} }
......
...@@ -20,4 +20,4 @@ dependencies: ...@@ -20,4 +20,4 @@ dependencies:
dev_dependencies: dev_dependencies:
# See packages/flutter_test/pubspec.yaml for why we're pinning this version. # See packages/flutter_test/pubspec.yaml for why we're pinning this version.
test: 0.12.21 test: 0.12.24+2
...@@ -21,6 +21,6 @@ dependencies: ...@@ -21,6 +21,6 @@ dependencies:
sdk: flutter sdk: flutter
dev_dependencies: dev_dependencies:
test: 0.12.21 test: any # pinned by flutter_test
mockito: ^2.0.2 mockito: ^2.0.2
quiver: ^0.24.0 quiver: ^0.24.0
...@@ -3,8 +3,11 @@ version: 0.0.11-dev ...@@ -3,8 +3,11 @@ version: 0.0.11-dev
dependencies: dependencies:
# The flutter tools depend on very specific internal implementation # The flutter tools depend on very specific internal implementation
# details of the 'test' package, which change between versions, so # details of the 'test' package, which change between versions, so
# here we pin it precisely to avoid version skew across our packages. # here we pin it precisely to avoid version skew across our
test: 0.12.21 # packages. When changing this, also update the pubspec.yaml files
# for the flutter_tools and devicelab packages. All other packages
# should depend on this one to transitively get the pinned version.
test: 0.12.24+2
# We use FakeAsync and other testing utilities. # We use FakeAsync and other testing utilities.
quiver: ^0.24.0 quiver: ^0.24.0
......
...@@ -35,8 +35,11 @@ dependencies: ...@@ -35,8 +35,11 @@ dependencies:
# We depend on very specific internal implementation details of the # We depend on very specific internal implementation details of the
# 'test' package, which change between versions, so here we pin it # 'test' package, which change between versions, so here we pin it
# precisely. # precisely. When changing this, also update the pubspec.yaml files
test: 0.12.21 # for the flutter_test and devicelab packages. All other packages
# should depend on flutter_test to transitively get the pinned
# version.
test: 0.12.24+2
# Version from the vended Dart SDK as defined in `dependency_overrides`. # Version from the vended Dart SDK as defined in `dependency_overrides`.
analyzer: any analyzer: any
......
...@@ -47,18 +47,33 @@ void main() { ...@@ -47,18 +47,33 @@ void main() {
testUsingContext('run a test when its name matches a regexp', () async { testUsingContext('run a test when its name matches a regexp', () async {
Cache.flutterRoot = '../..'; Cache.flutterRoot = '../..';
final ProcessResult result = await _runFlutterTest('filtering', automatedTestsDirectory, flutterTestDirectory, final ProcessResult result = await _runFlutterTest('filtering', automatedTestsDirectory, flutterTestDirectory,
extraArgs: const <String>["--name", "inc.*de"]); extraArgs: const <String>['--name', 'inc.*de']);
if (!result.stdout.contains("+1: All tests passed")) if (!result.stdout.contains('+1: All tests passed'))
fail("unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n"); fail('unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n');
expect(result.exitCode, 0); expect(result.exitCode, 0);
}); });
testUsingContext('run a test when its name contains a string', () async { testUsingContext('run a test when its name contains a string', () async {
Cache.flutterRoot = '../..'; Cache.flutterRoot = '../..';
final ProcessResult result = await _runFlutterTest('filtering', automatedTestsDirectory, flutterTestDirectory, final ProcessResult result = await _runFlutterTest('filtering', automatedTestsDirectory, flutterTestDirectory,
extraArgs: const <String>["--plain-name", "include"]); extraArgs: const <String>['--plain-name', 'include']);
if (!result.stdout.contains("+1: All tests passed")) if (!result.stdout.contains('+1: All tests passed'))
fail("unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n"); fail('unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n');
expect(result.exitCode, 0);
});
testUsingContext('test runs to completion', () async {
Cache.flutterRoot = '../..';
final ProcessResult result = await _runFlutterTest('trivial', automatedTestsDirectory, flutterTestDirectory,
extraArgs: const <String>['--verbose']);
if ((!result.stdout.contains('+1: All tests passed')) ||
(!result.stdout.contains('test 0: starting shell process')) ||
(!result.stdout.contains('test 0: deleting temporary directory')) ||
(!result.stdout.contains('test 0: finished')) ||
(!result.stdout.contains('test package returned with exit code 0')))
fail('unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n');
if (result.stderr.isNotEmpty)
fail('unexpected error output from test:\n\n${result.stderr}\n-- end stderr --\n\n');
expect(result.exitCode, 0); expect(result.exitCode, 0);
}); });
...@@ -69,7 +84,7 @@ Future<Null> _testFile(String testName, String workingDirectory, String testDire ...@@ -69,7 +84,7 @@ Future<Null> _testFile(String testName, String workingDirectory, String testDire
final String fullTestExpectation = fs.path.join(testDirectory, '${testName}_expectation.txt'); final String fullTestExpectation = fs.path.join(testDirectory, '${testName}_expectation.txt');
final File expectationFile = fs.file(fullTestExpectation); final File expectationFile = fs.file(fullTestExpectation);
if (!expectationFile.existsSync()) if (!expectationFile.existsSync())
fail("missing expectation file: $expectationFile"); fail('missing expectation file: $expectationFile');
while (_testExclusionLock != null) while (_testExclusionLock != null)
await _testExclusionLock; await _testExclusionLock;
...@@ -116,13 +131,17 @@ Future<Null> _testFile(String testName, String workingDirectory, String testDire ...@@ -116,13 +131,17 @@ Future<Null> _testFile(String testName, String workingDirectory, String testDire
expect(exec.stderr, ''); expect(exec.stderr, '');
} }
Future<ProcessResult> _runFlutterTest(String testName, String workingDirectory, String testDirectory, Future<ProcessResult> _runFlutterTest(
{List<String> extraArgs = const <String>[]}) async { String testName,
String workingDirectory,
String testDirectory, {
List<String> extraArgs: const <String>[],
}) async {
final String testFilePath = fs.path.join(testDirectory, '${testName}_test.dart'); final String testFilePath = fs.path.join(testDirectory, '${testName}_test.dart');
final File testFile = fs.file(testFilePath); final File testFile = fs.file(testFilePath);
if (!testFile.existsSync()) if (!testFile.existsSync())
fail("missing test file: $testFile"); fail('missing test file: $testFile');
final List<String> args = <String>[ final List<String> args = <String>[
fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')), fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment