Make clang_tidy test more hermetic (flutter/engine#26910)

This commit is contained in:
Zachary Anderson
2021-06-23 14:48:11 -07:00
committed by GitHub
parent 9cca57abef
commit d4b386da55
2 changed files with 25 additions and 13 deletions

View File

@@ -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>),
];

View File

@@ -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);