Skip to content

[tools] Some of the matcher logic of FakeCommand has the expected and actual values swapped. #125782

@andrewkolos

Description

@andrewkolos

FakeCommand allows the test author to make sure that a command is invoked with a particular workingDirectory, environment, and/or encoding. However, the expect calls have their parameters swapped.

For example, a test including this snippet:

processManager.addCommand(
  const FakeCommand(
    command: <String>[sdkManagerPath, '--licenses'],
    exitCode: 1,
    environment: <String, String>{
      'JAVA_HOME': 'expected value'
    },
    stderr: 'crash',
  ),
);

Can result in output looking like this:

00:01 +0 -1: uses JDK bundled with Android Studio when validating license acceptance [E]                      
  Expected: {}
    Actual: {'JAVA_HOME': 'expected value'}
     Which: has different length and has extra map key 'JAVA_HOME'

Relevant code:

void _matches(
List<String> command,
String? workingDirectory,
Map<String, String>? environment,
Encoding? encoding,
) {
final List<dynamic> matchers = this.command.map((Pattern x) => x is String ? x : matches(x)).toList();
expect(command, matchers);
if (this.workingDirectory != null) {
expect(this.workingDirectory, workingDirectory);
}
if (this.environment != null) {
expect(this.environment, environment);
}
if (this.encoding != null) {
expect(this.encoding, encoding);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    toolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions