mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 23:51:55 +08:00
[tool] Use 'flutter pub get' for Flutter packages (#4397)
Extracts common logic for running `pub get`, and switches commands to use it. The common logic always uses `flutter pub get` for Flutter packages, rather than `dart pub get`, since the latter will fail if someone has a non-Flutter `dart` in their path before `flutter` (e.g., Dart team members contributing PRs).
This commit is contained in:
104
script/tool/test/common/pub_utils_test.dart
Normal file
104
script/tool/test/common/pub_utils_test.dart
Normal file
@ -0,0 +1,104 @@
|
||||
// Copyright 2013 The Flutter 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:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_plugin_tools/src/common/pub_utils.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../mocks.dart';
|
||||
import '../util.dart';
|
||||
|
||||
void main() {
|
||||
late FileSystem fileSystem;
|
||||
late Directory packagesDir;
|
||||
late RecordingProcessRunner processRunner;
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem();
|
||||
packagesDir = createPackagesDirectory(fileSystem: fileSystem);
|
||||
processRunner = RecordingProcessRunner();
|
||||
});
|
||||
|
||||
test('runs with Dart for a non-Flutter package by default', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePackage('a_package', packagesDir);
|
||||
final MockPlatform platform = MockPlatform();
|
||||
|
||||
await runPubGet(package, processRunner, platform);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall('dart', const <String>['pub', 'get'], package.path),
|
||||
]));
|
||||
});
|
||||
|
||||
test('runs with Flutter for a Flutter package by default', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePackage('a_package', packagesDir, isFlutter: true);
|
||||
final MockPlatform platform = MockPlatform();
|
||||
|
||||
await runPubGet(package, processRunner, platform);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall('flutter', const <String>['pub', 'get'], package.path),
|
||||
]));
|
||||
});
|
||||
|
||||
test('runs with Flutter for a Dart package when requested', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePackage('a_package', packagesDir);
|
||||
final MockPlatform platform = MockPlatform();
|
||||
|
||||
await runPubGet(package, processRunner, platform, alwaysUseFlutter: true);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall('flutter', const <String>['pub', 'get'], package.path),
|
||||
]));
|
||||
});
|
||||
|
||||
test('uses the correct Flutter command on Windows', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePackage('a_package', packagesDir, isFlutter: true);
|
||||
final MockPlatform platform = MockPlatform(isWindows: true);
|
||||
|
||||
await runPubGet(package, processRunner, platform);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall(
|
||||
'flutter.bat', const <String>['pub', 'get'], package.path),
|
||||
]));
|
||||
});
|
||||
|
||||
test('reports success', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePackage('a_package', packagesDir);
|
||||
final MockPlatform platform = MockPlatform();
|
||||
|
||||
final bool result = await runPubGet(package, processRunner, platform);
|
||||
|
||||
expect(result, true);
|
||||
});
|
||||
|
||||
test('reports failure', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePackage('a_package', packagesDir);
|
||||
final MockPlatform platform = MockPlatform();
|
||||
|
||||
processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(exitCode: 1), <String>['pub', 'get'])
|
||||
];
|
||||
|
||||
final bool result = await runPubGet(package, processRunner, platform);
|
||||
|
||||
expect(result, false);
|
||||
});
|
||||
}
|
@ -88,7 +88,7 @@ void main() {
|
||||
final Iterable<ProcessCall> pubGetCalls =
|
||||
plugin1.getExamples().map((RepositoryPackage example) {
|
||||
return ProcessCall(
|
||||
'dart',
|
||||
getFlutterCommand(mockPlatform),
|
||||
const <String>['pub', 'get'],
|
||||
example.path,
|
||||
);
|
||||
@ -117,6 +117,7 @@ void main() {
|
||||
createFakePlugin('plugin_tools_test_package_a', packagesDir);
|
||||
|
||||
processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
|
||||
FakeProcessInfo(MockProcess(exitCode: 1, stdout: 'Some error from pub'),
|
||||
<String>['pub', 'publish'])
|
||||
];
|
||||
@ -205,7 +206,8 @@ void main() {
|
||||
'Packages with an SDK constraint on a pre-release of the Dart '
|
||||
'SDK should themselves be published as a pre-release version.');
|
||||
processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(process, <String>['pub', 'publish'])
|
||||
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
|
||||
FakeProcessInfo(process, <String>['pub', 'publish']),
|
||||
];
|
||||
|
||||
expect(
|
||||
@ -223,7 +225,8 @@ void main() {
|
||||
'Packages with an SDK constraint on a pre-release of the Dart '
|
||||
'SDK should themselves be published as a pre-release version.');
|
||||
processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(process, <String>['pub', 'publish'])
|
||||
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
|
||||
FakeProcessInfo(process, <String>['pub', 'publish']),
|
||||
];
|
||||
|
||||
Error? commandError;
|
||||
@ -247,6 +250,7 @@ void main() {
|
||||
createFakePlugin('d', packagesDir);
|
||||
|
||||
processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
|
||||
FakeProcessInfo(MockProcess(stdout: 'Package has 0 warnings.'),
|
||||
<String>['pub', 'publish']),
|
||||
];
|
||||
|
@ -429,7 +429,7 @@ dev_dependencies:
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('dart pub get failed'),
|
||||
contains('Fetching dependencies failed'),
|
||||
contains('Failed to update pigeon files'),
|
||||
]),
|
||||
);
|
||||
@ -545,7 +545,7 @@ dev_dependencies:
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('dart pub get failed'),
|
||||
contains('Fetching dependencies failed'),
|
||||
contains('Failed to update mocks'),
|
||||
]),
|
||||
);
|
||||
|
@ -48,7 +48,7 @@ void main() {
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
containsAll(<ProcessCall>[
|
||||
ProcessCall('dart', const <String>['pub', 'get'], example.path),
|
||||
ProcessCall('flutter', const <String>['pub', 'get'], example.path),
|
||||
ProcessCall(
|
||||
'dart',
|
||||
const <String>[
|
||||
@ -218,7 +218,7 @@ void main() {
|
||||
final RepositoryPackage package = createFakePlugin('a_package', packagesDir,
|
||||
extraFiles: <String>[kReadmeExcerptConfigPath]);
|
||||
|
||||
processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
|
||||
processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(exitCode: 1), <String>['pub', 'get'])
|
||||
];
|
||||
|
||||
@ -249,7 +249,7 @@ void main() {
|
||||
createFakePlugin('a_package', packagesDir,
|
||||
extraFiles: <String>[kReadmeExcerptConfigPath]);
|
||||
|
||||
processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
|
||||
processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(exitCode: 1), <String>['pub', 'get'])
|
||||
];
|
||||
|
||||
@ -274,7 +274,6 @@ void main() {
|
||||
extraFiles: <String>[kReadmeExcerptConfigPath]);
|
||||
|
||||
processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
|
||||
FakeProcessInfo(MockProcess(exitCode: 1), <String>['run', 'build_runner'])
|
||||
];
|
||||
|
||||
@ -299,7 +298,6 @@ void main() {
|
||||
extraFiles: <String>[kReadmeExcerptConfigPath]);
|
||||
|
||||
processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
|
||||
FakeProcessInfo(MockProcess(), <String>['run', 'build_runner']),
|
||||
FakeProcessInfo(
|
||||
MockProcess(exitCode: 1), <String>['run', 'code_excerpt_updater']),
|
||||
@ -326,7 +324,6 @@ void main() {
|
||||
extraFiles: <String>[kReadmeExcerptConfigPath, 'example/README.md']);
|
||||
|
||||
processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
|
||||
FakeProcessInfo(MockProcess(), <String>['run', 'build_runner']),
|
||||
FakeProcessInfo(MockProcess(), <String>['run', 'code_excerpt_updater']),
|
||||
FakeProcessInfo(
|
||||
|
Reference in New Issue
Block a user