provide command to FakeCommand::onRun (#142206)
Part of work on [#101077](https://github.com/flutter/flutter/pull/141194). This is done as a separate PR to avoid a massive diff. ## Context 1. The `FakeCommand` class accepts a list of patterns that's used to match a command given to its `FakeProcessManager`. Since `FakeCommand` can match a list of patterns, not just specifically strings, it can be used to match commands where the exact value of some arguments can't (easily) known ahead of time. For example, a part of the tool may invoke a command with an argument that is the path of a temporarily file that has a randomly-generated basename. 2. The `FakeCommand` class provides on `onRun` parameter, which is a callback that is run when the `FakeProcessManager` runs a command that matches the `FakeCommand` in question. ## Issue In the event that a `FakeCommand` is constructed using patterns, the test code can't know the exact values used for arguments in the command. This PR proposes changing the type of `onRun` from `VoidCallback?` to `void Function(List<String>)?`. When run, the value `List<String>` parameter will be the full command that the `FakeCommand` matched. Example: ```dart FakeCommand( command: <Pattern>[ artifacts.getArtifactPath(Artifact.engineDartBinary), 'run', 'vector_graphics_compiler', RegExp(r'--input=/.*\.temp'), RegExp(r'--output=/.*\.temp'), ], onRun: (List<String> command) { final outputPath = (() { // code to parse `--output` from `command` })(); testFileSystem.file(outputPath).createSync(recursive: true); }, ) ```
This commit is contained in:
@@ -151,7 +151,7 @@ void main() {
|
||||
),
|
||||
FakeCommand(
|
||||
command: const <String>['git', 'checkout', workingBranch],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
final File file = fileSystem.file('$checkoutsParentDirectory/engine/.ci.yaml')
|
||||
..createSync(recursive: true);
|
||||
_initializeCiYamlFile(file);
|
||||
@@ -402,7 +402,7 @@ void main() {
|
||||
const FakeCommand(command: <String>['git', 'fetch', 'upstream']),
|
||||
FakeCommand(
|
||||
command: const <String>['git', 'checkout', workingBranch],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
final File file = fileSystem.file('$checkoutsParentDirectory/framework/.ci.yaml')
|
||||
..createSync();
|
||||
_initializeCiYamlFile(file);
|
||||
@@ -504,7 +504,7 @@ void main() {
|
||||
const FakeCommand(command: <String>['git', 'fetch', 'upstream']),
|
||||
FakeCommand(
|
||||
command: const <String>['git', 'checkout', workingBranch],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
final File file = fileSystem.file('$checkoutsParentDirectory/framework/.ci.yaml')
|
||||
..createSync();
|
||||
_initializeCiYamlFile(file);
|
||||
@@ -600,7 +600,7 @@ void main() {
|
||||
// we want merged upstream commit, not local working commit
|
||||
FakeCommand(
|
||||
command: const <String>['git', 'checkout', 'upstream/$candidateBranch'],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
final File file = fileSystem.file('$checkoutsParentDirectory/framework/.ci.yaml')
|
||||
..createSync();
|
||||
_initializeCiYamlFile(file);
|
||||
@@ -686,7 +686,7 @@ void main() {
|
||||
const FakeCommand(command: <String>['git', 'fetch', 'upstream']),
|
||||
FakeCommand(
|
||||
command: const <String>['git', 'checkout', workingBranch],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
final File file = fileSystem.file('$checkoutsParentDirectory/framework/.ci.yaml')
|
||||
..createSync();
|
||||
_initializeCiYamlFile(file);
|
||||
|
||||
@@ -254,7 +254,7 @@ vars = {
|
||||
]),
|
||||
FakeCommand(
|
||||
command: const <String>['git', 'checkout', candidateBranch, '--'],
|
||||
onRun: () => createdCandidateBranch = true,
|
||||
onRun: (_) => createdCandidateBranch = true,
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'checkout', 'stable', '--'],
|
||||
@@ -309,7 +309,7 @@ vars = {
|
||||
]),
|
||||
FakeCommand(
|
||||
command: const <String>['git', 'checkout', candidateBranch, '--'],
|
||||
onRun: () => createdCandidateBranch = true,
|
||||
onRun: (_) => createdCandidateBranch = true,
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'checkout', EngineRepository.defaultBranch],
|
||||
|
||||
@@ -159,7 +159,7 @@ void main() {
|
||||
EngineRepository.defaultUpstream,
|
||||
engine.path,
|
||||
],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
// Create the DEPS file which the tool will update
|
||||
engine.createSync(recursive: true);
|
||||
depsFile
|
||||
@@ -368,7 +368,7 @@ void main() {
|
||||
EngineRepository.defaultUpstream,
|
||||
engine.path,
|
||||
],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
// Create the DEPS file which the tool will update
|
||||
engine.createSync(recursive: true);
|
||||
depsFile
|
||||
@@ -554,7 +554,7 @@ void main() {
|
||||
EngineRepository.defaultUpstream,
|
||||
engine.path,
|
||||
],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
// Create the DEPS file which the tool will update
|
||||
engine.createSync(recursive: true);
|
||||
depsFile
|
||||
@@ -763,7 +763,7 @@ void main() {
|
||||
EngineRepository.defaultUpstream,
|
||||
engine.path,
|
||||
],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
// Create the DEPS file which the tool will update
|
||||
engine.createSync(recursive: true);
|
||||
depsFile
|
||||
@@ -972,7 +972,7 @@ void main() {
|
||||
EngineRepository.defaultUpstream,
|
||||
engine.path,
|
||||
],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
// Create the DEPS file which the tool will update
|
||||
engine.createSync(recursive: true);
|
||||
depsFile
|
||||
|
||||
@@ -403,7 +403,7 @@ void main() {
|
||||
'flutter,Dart,${apidocs.kPlatformIntegrationPackageName},flutter_test,flutter_driver',
|
||||
'--auto-include-dependencies',
|
||||
],
|
||||
onRun: () {
|
||||
onRun: (_) {
|
||||
for (final File canary in generator.canaries) {
|
||||
canary.createSync(recursive: true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user