Make clang_tidy test more hermetic (flutter/engine#26910)
This commit is contained in:
@@ -107,8 +107,11 @@ class ClangTidy {
|
||||
}
|
||||
}
|
||||
|
||||
final List<dynamic> buildCommandsData = jsonDecode(
|
||||
options.buildCommandsPath.readAsStringSync(),
|
||||
) as List<dynamic>;
|
||||
final List<Command> changedFileBuildCommands = getLintCommandsForChangedFiles(
|
||||
options.buildCommandsPath,
|
||||
buildCommandsData,
|
||||
changedFiles,
|
||||
);
|
||||
|
||||
@@ -163,14 +166,11 @@ class ClangTidy {
|
||||
/// compute the lint commands to run.
|
||||
@visibleForTesting
|
||||
List<Command> getLintCommandsForChangedFiles(
|
||||
io.File buildCommandsPath,
|
||||
List<dynamic> buildCommandsData,
|
||||
List<io.File> changedFiles,
|
||||
) {
|
||||
final List<dynamic> buildCommandMaps = jsonDecode(
|
||||
buildCommandsPath.readAsStringSync(),
|
||||
) as List<dynamic>;
|
||||
final List<Command> buildCommands = <Command>[
|
||||
for (final dynamic c in buildCommandMaps)
|
||||
for (final dynamic c in buildCommandsData)
|
||||
Command.fromMap(c as Map<String, dynamic>),
|
||||
];
|
||||
|
||||
|
||||
@@ -159,8 +159,16 @@ Future<int> main(List<String> args) async {
|
||||
outSink: outBuffer,
|
||||
errSink: errBuffer,
|
||||
);
|
||||
const String filePath = '/path/to/a/source_file.cc';
|
||||
final List<dynamic> buildCommandsData = <Map<String, dynamic>>[
|
||||
<String, dynamic>{
|
||||
'directory': '/unused',
|
||||
'command': '../../buildtools/mac-x64/clang/bin/clang $filePath',
|
||||
'file': filePath,
|
||||
},
|
||||
];
|
||||
final List<Command> commands = clangTidy.getLintCommandsForChangedFiles(
|
||||
clangTidy.options.buildCommandsPath,
|
||||
buildCommandsData,
|
||||
<io.File>[],
|
||||
);
|
||||
|
||||
@@ -177,13 +185,17 @@ Future<int> main(List<String> args) async {
|
||||
outSink: outBuffer,
|
||||
errSink: errBuffer,
|
||||
);
|
||||
final List<io.File> fileList = await clangTidy.computeChangedFiles();
|
||||
final io.File file = fileList.firstWhere((io.File f) {
|
||||
return f.path.endsWith('.cc');
|
||||
});
|
||||
const String filePath = '/path/to/a/source_file.cc';
|
||||
final List<dynamic> buildCommandsData = <Map<String, dynamic>>[
|
||||
<String, dynamic>{
|
||||
'directory': '/unused',
|
||||
'command': '../../buildtools/mac-x64/clang/bin/clang $filePath',
|
||||
'file': filePath,
|
||||
},
|
||||
];
|
||||
final List<Command> commands = clangTidy.getLintCommandsForChangedFiles(
|
||||
clangTidy.options.buildCommandsPath,
|
||||
<io.File>[file],
|
||||
buildCommandsData,
|
||||
<io.File>[io.File(filePath)],
|
||||
);
|
||||
|
||||
expect(commands, isNotEmpty);
|
||||
|
||||
Reference in New Issue
Block a user