mirror of
https://github.com/flutter/packages.git
synced 2025-08-24 03:18:54 +08:00

Consolidates the code to find all changed file paths into the `PackageLoopingCommand` class that is the base of almost all of the repo tooling commands. This in a preparatory PR for a future change to allow each command to define a list of files or file patterns that definitively *don't* affect that test, so that CI can be smarter about what tests to run (e.g., not running expensive integration tests for README changes). A side effect of this change is that tests of almost all commands now need a mock `GitDir` instance. This would add a lot of copy/pasted boilerplate to the test setup, and there is already too much of that, so instead this refactors common test setup: - Creating a memory file system - Populating it with a packages directory - Creating a RecordingProcessRunner to mock out process calls - Creating a mock GitDir that forwards to a RecordingProcessRunner into a helper method (using records and destructuring to easily return multiple values). While some tests don't need all of these steps, those that don't can easily ignore parts of it, and it will make it much easier to update tests in the future if they need them, and it makes the setup much more consistent which makes it easier to reason about test setup in general. Prep for https://github.com/flutter/flutter/issues/136394
178 lines
5.5 KiB
Dart
178 lines
5.5 KiB
Dart
// 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:flutter_plugin_tools/src/common/gradle.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import '../mocks.dart';
|
|
import '../util.dart';
|
|
|
|
void main() {
|
|
late Directory packagesDir;
|
|
late RecordingProcessRunner processRunner;
|
|
|
|
setUp(() {
|
|
(:packagesDir, :processRunner, gitProcessRunner: _, gitDir: _) =
|
|
configureBaseCommandMocks();
|
|
});
|
|
|
|
group('isConfigured', () {
|
|
test('reports true when configured on Windows', () async {
|
|
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
|
|
extraFiles: <String>['android/gradlew.bat']);
|
|
final GradleProject project = GradleProject(
|
|
plugin,
|
|
processRunner: processRunner,
|
|
platform: MockPlatform(isWindows: true),
|
|
);
|
|
|
|
expect(project.isConfigured(), true);
|
|
});
|
|
|
|
test('reports true when configured on non-Windows', () async {
|
|
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
|
|
extraFiles: <String>['android/gradlew']);
|
|
final GradleProject project = GradleProject(
|
|
plugin,
|
|
processRunner: processRunner,
|
|
platform: MockPlatform(isMacOS: true),
|
|
);
|
|
|
|
expect(project.isConfigured(), true);
|
|
});
|
|
|
|
test('reports false when not configured on Windows', () async {
|
|
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
|
|
extraFiles: <String>['android/foo']);
|
|
final GradleProject project = GradleProject(
|
|
plugin,
|
|
processRunner: processRunner,
|
|
platform: MockPlatform(isWindows: true),
|
|
);
|
|
|
|
expect(project.isConfigured(), false);
|
|
});
|
|
|
|
test('reports true when configured on non-Windows', () async {
|
|
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
|
|
extraFiles: <String>['android/foo']);
|
|
final GradleProject project = GradleProject(
|
|
plugin,
|
|
processRunner: processRunner,
|
|
platform: MockPlatform(isMacOS: true),
|
|
);
|
|
|
|
expect(project.isConfigured(), false);
|
|
});
|
|
});
|
|
|
|
group('runCommand', () {
|
|
test('runs without arguments', () async {
|
|
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
|
|
extraFiles: <String>['android/gradlew']);
|
|
final GradleProject project = GradleProject(
|
|
plugin,
|
|
processRunner: processRunner,
|
|
platform: MockPlatform(isMacOS: true),
|
|
);
|
|
|
|
final int exitCode = await project.runCommand('foo');
|
|
|
|
expect(exitCode, 0);
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall(
|
|
plugin
|
|
.platformDirectory(FlutterPlatform.android)
|
|
.childFile('gradlew')
|
|
.path,
|
|
const <String>[
|
|
'foo',
|
|
],
|
|
plugin.platformDirectory(FlutterPlatform.android).path),
|
|
]));
|
|
});
|
|
|
|
test('runs with arguments', () async {
|
|
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
|
|
extraFiles: <String>['android/gradlew']);
|
|
final GradleProject project = GradleProject(
|
|
plugin,
|
|
processRunner: processRunner,
|
|
platform: MockPlatform(isMacOS: true),
|
|
);
|
|
|
|
final int exitCode = await project.runCommand(
|
|
'foo',
|
|
arguments: <String>['--bar', '--baz'],
|
|
);
|
|
|
|
expect(exitCode, 0);
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall(
|
|
plugin
|
|
.platformDirectory(FlutterPlatform.android)
|
|
.childFile('gradlew')
|
|
.path,
|
|
const <String>[
|
|
'foo',
|
|
'--bar',
|
|
'--baz',
|
|
],
|
|
plugin.platformDirectory(FlutterPlatform.android).path),
|
|
]));
|
|
});
|
|
|
|
test('runs with the correct wrapper on Windows', () async {
|
|
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
|
|
extraFiles: <String>['android/gradlew.bat']);
|
|
final GradleProject project = GradleProject(
|
|
plugin,
|
|
processRunner: processRunner,
|
|
platform: MockPlatform(isWindows: true),
|
|
);
|
|
|
|
final int exitCode = await project.runCommand('foo');
|
|
|
|
expect(exitCode, 0);
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall(
|
|
plugin
|
|
.platformDirectory(FlutterPlatform.android)
|
|
.childFile('gradlew.bat')
|
|
.path,
|
|
const <String>[
|
|
'foo',
|
|
],
|
|
plugin.platformDirectory(FlutterPlatform.android).path),
|
|
]));
|
|
});
|
|
|
|
test('returns error codes', () async {
|
|
final RepositoryPackage plugin = createFakePlugin('plugin', packagesDir,
|
|
extraFiles: <String>['android/gradlew.bat']);
|
|
final GradleProject project = GradleProject(
|
|
plugin,
|
|
processRunner: processRunner,
|
|
platform: MockPlatform(isWindows: true),
|
|
);
|
|
|
|
processRunner.mockProcessesForExecutable[project.gradleWrapper.path] =
|
|
<FakeProcessInfo>[
|
|
FakeProcessInfo(MockProcess(exitCode: 1)),
|
|
];
|
|
|
|
final int exitCode = await project.runCommand('foo');
|
|
|
|
expect(exitCode, 1);
|
|
});
|
|
});
|
|
}
|