From db884141314f78cff4127c7b416cd0dbdbe98bba Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Fri, 4 Aug 2017 16:33:38 -0700 Subject: [PATCH] Upgrade to the most recent test package. (#11526) Also, add tests to verify that our coverage is actually being tested! --- dev/automated_tests/flutter_test/README.md | 5 ++- .../flutter_test/trivial_test.dart | 9 ++++ dev/bots/test.dart | 14 +++++++ dev/devicelab/pubspec.yaml | 2 +- packages/flutter_driver/pubspec.yaml | 2 +- packages/flutter_test/pubspec.yaml | 7 +++- packages/flutter_tools/pubspec.yaml | 7 +++- .../test/commands/test_test.dart | 41 ++++++++++++++----- 8 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 dev/automated_tests/flutter_test/trivial_test.dart diff --git a/dev/automated_tests/flutter_test/README.md b/dev/automated_tests/flutter_test/README.md index efea7261f7..6c1ace4202 100644 --- a/dev/automated_tests/flutter_test/README.md +++ b/dev/automated_tests/flutter_test/README.md @@ -1,4 +1,5 @@ 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 -intentionally not true of the `flutter_tools` package). +intentionally not true of the `flutter_tools` package). Others are +here mostly out of peer pressure. diff --git a/dev/automated_tests/flutter_test/trivial_test.dart b/dev/automated_tests/flutter_test/trivial_test.dart new file mode 100644 index 0000000000..9efb063150 --- /dev/null +++ b/dev/automated_tests/flutter_test/trivial_test.dart @@ -0,0 +1,9 @@ +// 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', () { }); +} diff --git a/dev/bots/test.dart b/dev/bots/test.dart index c3d0be4edb..88da557870 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -145,9 +145,23 @@ Future _runCoverage() async { 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'), options: const ['--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'); } diff --git a/dev/devicelab/pubspec.yaml b/dev/devicelab/pubspec.yaml index dc7a7b61eb..22b27299e8 100644 --- a/dev/devicelab/pubspec.yaml +++ b/dev/devicelab/pubspec.yaml @@ -20,4 +20,4 @@ dependencies: dev_dependencies: # See packages/flutter_test/pubspec.yaml for why we're pinning this version. - test: 0.12.21 + test: 0.12.24+2 diff --git a/packages/flutter_driver/pubspec.yaml b/packages/flutter_driver/pubspec.yaml index 9a8dba941a..56af33718a 100644 --- a/packages/flutter_driver/pubspec.yaml +++ b/packages/flutter_driver/pubspec.yaml @@ -21,6 +21,6 @@ dependencies: sdk: flutter dev_dependencies: - test: 0.12.21 + test: any # pinned by flutter_test mockito: ^2.0.2 quiver: ^0.24.0 diff --git a/packages/flutter_test/pubspec.yaml b/packages/flutter_test/pubspec.yaml index 40e5ad2e8b..51b225aa70 100644 --- a/packages/flutter_test/pubspec.yaml +++ b/packages/flutter_test/pubspec.yaml @@ -3,8 +3,11 @@ version: 0.0.11-dev dependencies: # The flutter tools depend on very specific internal implementation # details of the 'test' package, which change between versions, so - # here we pin it precisely to avoid version skew across our packages. - test: 0.12.21 + # here we pin it precisely to avoid version skew across our + # 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. quiver: ^0.24.0 diff --git a/packages/flutter_tools/pubspec.yaml b/packages/flutter_tools/pubspec.yaml index 384295b519..b8219f3f99 100644 --- a/packages/flutter_tools/pubspec.yaml +++ b/packages/flutter_tools/pubspec.yaml @@ -35,8 +35,11 @@ dependencies: # We depend on very specific internal implementation details of the # 'test' package, which change between versions, so here we pin it - # precisely. - test: 0.12.21 + # precisely. When changing this, also update the pubspec.yaml files + # 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`. analyzer: any diff --git a/packages/flutter_tools/test/commands/test_test.dart b/packages/flutter_tools/test/commands/test_test.dart index 450e126727..52e3d15b89 100644 --- a/packages/flutter_tools/test/commands/test_test.dart +++ b/packages/flutter_tools/test/commands/test_test.dart @@ -47,18 +47,33 @@ void main() { testUsingContext('run a test when its name matches a regexp', () async { Cache.flutterRoot = '../..'; final ProcessResult result = await _runFlutterTest('filtering', automatedTestsDirectory, flutterTestDirectory, - extraArgs: const ["--name", "inc.*de"]); - if (!result.stdout.contains("+1: All tests passed")) - fail("unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n"); + extraArgs: const ['--name', 'inc.*de']); + if (!result.stdout.contains('+1: All tests passed')) + fail('unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n'); expect(result.exitCode, 0); }); testUsingContext('run a test when its name contains a string', () async { Cache.flutterRoot = '../..'; final ProcessResult result = await _runFlutterTest('filtering', automatedTestsDirectory, flutterTestDirectory, - extraArgs: const ["--plain-name", "include"]); - if (!result.stdout.contains("+1: All tests passed")) - fail("unexpected output from test:\n\n${result.stdout}\n-- end stdout --\n\n"); + extraArgs: const ['--plain-name', 'include']); + if (!result.stdout.contains('+1: All tests passed')) + 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 ['--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); }); @@ -69,7 +84,7 @@ Future _testFile(String testName, String workingDirectory, String testDire final String fullTestExpectation = fs.path.join(testDirectory, '${testName}_expectation.txt'); final File expectationFile = fs.file(fullTestExpectation); if (!expectationFile.existsSync()) - fail("missing expectation file: $expectationFile"); + fail('missing expectation file: $expectationFile'); while (_testExclusionLock != null) await _testExclusionLock; @@ -116,13 +131,17 @@ Future _testFile(String testName, String workingDirectory, String testDire expect(exec.stderr, ''); } -Future _runFlutterTest(String testName, String workingDirectory, String testDirectory, - {List extraArgs = const []}) async { - +Future _runFlutterTest( + String testName, + String workingDirectory, + String testDirectory, { + List extraArgs: const [], +}) async { + final String testFilePath = fs.path.join(testDirectory, '${testName}_test.dart'); final File testFile = fs.file(testFilePath); if (!testFile.existsSync()) - fail("missing test file: $testFile"); + fail('missing test file: $testFile'); final List args = [ fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')),