[flutter_plugin_tools] If clang-format does not run, fall back to other executables in PATH (#6853)

* If clang-format does not run, fall back to other executables in PATH

* Review edits
This commit is contained in:
Jenn Magder
2022-12-16 13:05:49 -08:00
committed by GitHub
parent a50448ac47
commit c1ec012a22
6 changed files with 90 additions and 13 deletions

View File

@ -332,6 +332,44 @@ void main() {
]));
});
test('falls back to working clang-format in the path', () async {
const List<String> files = <String>[
'linux/foo_plugin.cc',
'macos/Classes/Foo.h',
];
final RepositoryPackage plugin = createFakePlugin(
'a_plugin',
packagesDir,
extraFiles: files,
);
processRunner.mockProcessesForExecutable['clang-format'] = <io.Process>[
MockProcess(exitCode: 1)
];
processRunner.mockProcessesForExecutable['which'] = <io.Process>[
MockProcess(
stdout: '/usr/local/bin/clang-format\n/path/to/working-clang-format')
];
processRunner.mockProcessesForExecutable['/usr/local/bin/clang-format'] =
<io.Process>[MockProcess(exitCode: 1)];
await runCapturingPrint(runner, <String>['format']);
expect(
processRunner.recordedCalls,
containsAll(<ProcessCall>[
const ProcessCall(
'/path/to/working-clang-format', <String>['--version'], null),
ProcessCall(
'/path/to/working-clang-format',
<String>[
'-i',
'--style=file',
...getPackagesDirRelativePaths(plugin, files)
],
packagesDir.path),
]));
});
test('honors --clang-format flag', () async {
const List<String> files = <String>[
'windows/foo_plugin.cpp',