Shim package:test to avoid matcher issues (#20602)
* Upgrade everything except matcher. * Roll matcher (and test) * Adjust tests that depend on flutter:test directly to depend on a shim * Require use of package:test shim and remove other references to package:test
This commit is contained in:
committed by
Todd Volkert
parent
8de0e15e4f
commit
686d8f8a22
@@ -5,39 +5,39 @@ dependencies:
|
||||
path: 1.6.2
|
||||
args: 1.5.0
|
||||
meta: 1.1.5
|
||||
process: 3.0.3
|
||||
platform: 2.1.2
|
||||
process: 3.0.5
|
||||
platform: 2.2.0
|
||||
http: 0.11.3+17
|
||||
http_parser: 3.1.3
|
||||
|
||||
async: 2.0.8 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
charcode: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
collection: 1.14.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
file: 5.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
file: 5.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
intl: 0.15.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
source_span: 1.4.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
string_scanner: 1.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
string_scanner: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
typed_data: 1.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
|
||||
dev_dependencies:
|
||||
test: 0.12.41
|
||||
test: 0.12.42
|
||||
mockito: 3.0.0-beta
|
||||
|
||||
analyzer: 0.32.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
boolean_selector: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
convert: 2.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
crypto: 2.0.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
csslib: 0.14.4+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
csslib: 0.14.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
front_end: 0.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
glob: 1.1.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
html: 0.13.3+2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
html: 0.13.3+3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
http_multi_server: 2.0.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
io: 0.3.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
js: 0.6.1+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
json_rpc_2: 2.0.9 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
kernel: 0.3.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
logging: 0.11.3+2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
matcher: 0.12.2+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
matcher: 0.12.3+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
mime: 0.9.6+2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
multi_server_socket: 1.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
node_preamble: 1.4.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@@ -61,4 +61,4 @@ dev_dependencies:
|
||||
web_socket_channel: 1.0.9 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
yaml: 2.1.15 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
|
||||
# PUBSPEC CHECKSUM: 5a94
|
||||
# PUBSPEC CHECKSUM: b541
|
||||
|
||||
@@ -160,6 +160,7 @@ Future<Null> _checkForTrailingSpaces() async {
|
||||
}
|
||||
|
||||
Future<Null> _analyzeRepo() async {
|
||||
await _verifyNoTestPackageImports(flutterRoot);
|
||||
await _verifyGeneratedPluginRegistrants(flutterRoot);
|
||||
await _verifyNoBadImportsInFlutter(flutterRoot);
|
||||
await _verifyNoBadImportsInFlutterTools(flutterRoot);
|
||||
@@ -528,6 +529,81 @@ Future<Null> _runFlutterAnalyze(String workingDirectory, {
|
||||
);
|
||||
}
|
||||
|
||||
Future<Null> _verifyNoTestPackageImports(String workingDirectory) async {
|
||||
// TODO(ianh): Remove this whole test once https://github.com/dart-lang/matcher/issues/98 is fixed.
|
||||
final List<String> shims = <String>[];
|
||||
final List<String> errors = new Directory(workingDirectory)
|
||||
.listSync(recursive: true)
|
||||
.where((FileSystemEntity entity) {
|
||||
return entity is File && entity.path.endsWith('.dart');
|
||||
})
|
||||
.map<String>((FileSystemEntity entity) {
|
||||
final File file = entity;
|
||||
final String data = file.readAsStringSync();
|
||||
final String name = path.relative(file.path, from: workingDirectory);
|
||||
if (name.startsWith('bin/cache') ||
|
||||
name == 'dev/bots/test.dart')
|
||||
return null;
|
||||
if (data.contains("import 'package:test/test.dart'")) {
|
||||
if (data.contains("// Defines a 'package:test' shim.")) {
|
||||
shims.add(' $name');
|
||||
if (!data.contains('https://github.com/dart-lang/matcher/issues/98'))
|
||||
return ' $name: Shims must link to the isInstanceOf issue.';
|
||||
if (data.contains("import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;") &&
|
||||
data.contains("export 'package:test/test.dart' hide TypeMatcher, isInstanceOf;"))
|
||||
return null;
|
||||
return ' $name: Shim seems to be missing the expected import/export lines.';
|
||||
}
|
||||
final int count = 'package:test'.allMatches(data).length;
|
||||
if (file.path.contains('/test_driver/') ||
|
||||
name.startsWith('dev/missing_dependency_tests/') ||
|
||||
name.startsWith('dev/automated_tests/') ||
|
||||
name.startsWith('packages/flutter/test/engine/') ||
|
||||
name.startsWith('examples/layers/test/smoketests/raw/') ||
|
||||
name.startsWith('examples/layers/test/smoketests/rendering/') ||
|
||||
name.startsWith('examples/flutter_gallery/test/calculator')) {
|
||||
// We only exempt driver tests, some of our special trivial tests.
|
||||
// Driver tests aren't typically expected to use TypeMatcher and company.
|
||||
// The trivial tests don't typically do anything at all and it would be
|
||||
// a pain to have to give them a shim.
|
||||
if (!data.contains("import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;"))
|
||||
return ' $name: test does not hide TypeMatcher and isInstanceOf from package:test; consider using a shim instead.';
|
||||
assert(count > 0);
|
||||
if (count == 1)
|
||||
return null;
|
||||
return ' $name: uses \'package:test\' $count times.';
|
||||
}
|
||||
if (name.startsWith('packages/flutter_test/')) {
|
||||
// flutter_test has deep ties to package:test
|
||||
return null;
|
||||
}
|
||||
if (data.contains("import 'package:test/test.dart' as test_package;") ||
|
||||
data.contains("import 'package:test/test.dart' as test_package show ")) {
|
||||
if (count == 1)
|
||||
return null;
|
||||
}
|
||||
return ' $name: uses \'package:test\' directly.';
|
||||
}
|
||||
})
|
||||
.where((String line) => line != null)
|
||||
.toList()
|
||||
..sort();
|
||||
|
||||
// Fail if any errors
|
||||
if (errors.isNotEmpty) {
|
||||
print('$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset');
|
||||
final String s1 = errors.length == 1 ? 's' : '';
|
||||
final String s2 = errors.length == 1 ? '' : 's';
|
||||
print('${bold}The following file$s2 depend$s1 on \'package:test\' directly:$reset');
|
||||
print(errors.join('\n'));
|
||||
print('Rather than depending on \'package:test\' directly, use one of the shims:');
|
||||
print(shims.join('\n'));
|
||||
print('This insulates us from breaking changes in \'package:test\'.');
|
||||
print('$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset\n');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> _verifyNoBadImportsInFlutter(String workingDirectory) async {
|
||||
final List<String> errors = <String>[];
|
||||
final String libPath = path.join(workingDirectory, 'packages', 'flutter', 'lib');
|
||||
|
||||
14
dev/bots/test/common.dart
Normal file
14
dev/bots/test/common.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright 2018 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' hide TypeMatcher, isInstanceOf;
|
||||
import 'package:test/test.dart' as test_package show TypeMatcher;
|
||||
|
||||
export 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||
|
||||
// Defines a 'package:test' shim.
|
||||
// TODO(ianh): Remove this file once https://github.com/dart-lang/matcher/issues/98 is fixed
|
||||
|
||||
/// A matcher that compares the type of the actual value to the type argument T.
|
||||
Matcher isInstanceOf<T>() => new test_package.TypeMatcher<T>(); // ignore: prefer_const_constructors, https://github.com/dart-lang/sdk/issues/32544
|
||||
@@ -8,7 +8,8 @@ import 'dart:io';
|
||||
|
||||
import 'package:process/process.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
/// A mock that can be used to fake a process manager that runs commands
|
||||
/// and returns results.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'common.dart';
|
||||
|
||||
import 'fake_process_manager.dart';
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ import 'dart:io' hide Platform;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:platform/platform.dart' show FakePlatform;
|
||||
|
||||
import '../prepare_package.dart';
|
||||
import 'common.dart';
|
||||
import 'fake_process_manager.dart';
|
||||
|
||||
void main() {
|
||||
@@ -25,7 +25,7 @@ void main() {
|
||||
expectAsync1((List<String> commandLine) async {
|
||||
return processRunner.runProcess(commandLine);
|
||||
})(<String>['this_executable_better_not_exist_2857632534321']),
|
||||
throwsA(const isInstanceOf<ProcessRunnerException>()));
|
||||
throwsA(isInstanceOf<ProcessRunnerException>()));
|
||||
try {
|
||||
await processRunner.runProcess(<String>['this_executable_better_not_exist_2857632534321']);
|
||||
} on ProcessRunnerException catch (e) {
|
||||
@@ -62,7 +62,7 @@ void main() {
|
||||
expectAsync1((List<String> commandLine) async {
|
||||
return processRunner.runProcess(commandLine);
|
||||
})(<String>['echo', 'test']),
|
||||
throwsA(const isInstanceOf<ProcessRunnerException>()));
|
||||
throwsA(isInstanceOf<ProcessRunnerException>()));
|
||||
});
|
||||
});
|
||||
group('ArchiveCreator for $platformName', () {
|
||||
@@ -204,7 +204,7 @@ void main() {
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
expect(expectAsync0(creator.initializeRepo),
|
||||
throwsA(const isInstanceOf<ProcessRunnerException>()));
|
||||
throwsA(isInstanceOf<ProcessRunnerException>()));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user