Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5911a6d

Browse files
authored
Make clang_tidy test more hermetic (#26910)
1 parent 7aa61d6 commit 5911a6d

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

tools/clang_tidy/lib/clang_tidy.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ class ClangTidy {
107107
}
108108
}
109109

110+
final List<dynamic> buildCommandsData = jsonDecode(
111+
options.buildCommandsPath.readAsStringSync(),
112+
) as List<dynamic>;
110113
final List<Command> changedFileBuildCommands = getLintCommandsForChangedFiles(
111-
options.buildCommandsPath,
114+
buildCommandsData,
112115
changedFiles,
113116
);
114117

@@ -163,14 +166,11 @@ class ClangTidy {
163166
/// compute the lint commands to run.
164167
@visibleForTesting
165168
List<Command> getLintCommandsForChangedFiles(
166-
io.File buildCommandsPath,
169+
List<dynamic> buildCommandsData,
167170
List<io.File> changedFiles,
168171
) {
169-
final List<dynamic> buildCommandMaps = jsonDecode(
170-
buildCommandsPath.readAsStringSync(),
171-
) as List<dynamic>;
172172
final List<Command> buildCommands = <Command>[
173-
for (final dynamic c in buildCommandMaps)
173+
for (final dynamic c in buildCommandsData)
174174
Command.fromMap(c as Map<String, dynamic>),
175175
];
176176

tools/clang_tidy/test/clang_tidy_test.dart

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,16 @@ Future<int> main(List<String> args) async {
159159
outSink: outBuffer,
160160
errSink: errBuffer,
161161
);
162+
const String filePath = '/path/to/a/source_file.cc';
163+
final List<dynamic> buildCommandsData = <Map<String, dynamic>>[
164+
<String, dynamic>{
165+
'directory': '/unused',
166+
'command': '../../buildtools/mac-x64/clang/bin/clang $filePath',
167+
'file': filePath,
168+
},
169+
];
162170
final List<Command> commands = clangTidy.getLintCommandsForChangedFiles(
163-
clangTidy.options.buildCommandsPath,
171+
buildCommandsData,
164172
<io.File>[],
165173
);
166174

@@ -177,13 +185,17 @@ Future<int> main(List<String> args) async {
177185
outSink: outBuffer,
178186
errSink: errBuffer,
179187
);
180-
final List<io.File> fileList = await clangTidy.computeChangedFiles();
181-
final io.File file = fileList.firstWhere((io.File f) {
182-
return f.path.endsWith('.cc');
183-
});
188+
const String filePath = '/path/to/a/source_file.cc';
189+
final List<dynamic> buildCommandsData = <Map<String, dynamic>>[
190+
<String, dynamic>{
191+
'directory': '/unused',
192+
'command': '../../buildtools/mac-x64/clang/bin/clang $filePath',
193+
'file': filePath,
194+
},
195+
];
184196
final List<Command> commands = clangTidy.getLintCommandsForChangedFiles(
185-
clangTidy.options.buildCommandsPath,
186-
<io.File>[file],
197+
buildCommandsData,
198+
<io.File>[io.File(filePath)],
187199
);
188200

189201
expect(commands, isNotEmpty);

0 commit comments

Comments
 (0)