Unverified Commit bc20f2ee authored by Jia Hao's avatar Jia Hao Committed by GitHub

[flutter_tools] Fail fast when test dependencies are missing (#76679)

parent e4373882
......@@ -219,8 +219,7 @@ class TestCommand extends FlutterCommand {
final BuildInfo buildInfo = await getBuildInfo(forcedBuildMode: BuildMode.debug);
if (buildInfo.packageConfig['test_api'] == null) {
globals.printError(
'\n'
throwToolExit(
'Error: cannot run without a dependency on either "package:flutter_test" or "package:test". '
'Ensure the following lines are present in your pubspec.yaml:'
'\n\n'
......
......@@ -5,6 +5,7 @@
// @dart = 2.8
import 'dart:async';
import 'dart:convert';
import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
......@@ -25,6 +26,25 @@ import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/testbed.dart';
const String _pubspecContents = '''
dev_dependencies:
flutter_test:
sdk: flutter''';
final String _packageConfigContents = json.encode(<String, Object>{
'configVersion': 2,
'packages': <Map<String, Object>>[
<String, String>{
'name': 'test_api',
'rootUri': 'file:///path/to/pubcache/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.19',
'packageUri': 'lib/',
'languageVersion': '2.12'
}
],
'generated': '2021-02-24T07:55:20.084834Z',
'generator': 'pub',
'generatorVersion': '2.13.0-68.0.dev'
});
void main() {
Cache.disableLocking();
MemoryFileSystem fs;
......@@ -32,10 +52,34 @@ void main() {
setUp(() {
fs = MemoryFileSystem.test();
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
fs.file('pubspec.yaml').writeAsStringSync(_pubspecContents);
(fs.directory('.dart_tool')
.childFile('package_config.json')
..createSync(recursive: true))
.writeAsString(_packageConfigContents);
fs.directory('test').childFile('some_test.dart').createSync(recursive: true);
});
testUsingContext('Missing dependencies in pubspec',
() async {
// Clear the dependencies already added in [setUp].
fs.file('pubspec.yaml').writeAsStringSync('');
fs.directory('.dart_tool').childFile('package_config.json').writeAsStringSync('');
final FakePackageTest fakePackageTest = FakePackageTest();
final TestCommand testCommand = TestCommand(testWrapper: fakePackageTest);
final CommandRunner<void> commandRunner =
createTestCommandRunner(testCommand);
expect(() => commandRunner.run(const <String>[
'test',
'--no-pub',
]), throwsToolExit());
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Pipes test-randomize-ordering-seed to package:test',
() async {
final FakePackageTest fakePackageTest = FakePackageTest();
......
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