Skip to content

Commit 68aff12

Browse files
committed
fix: don't ignore errors
When capturing clang tools output, any error encountered should cause fast-failure behavior. Also adjust run_main() tests so that erroneous output is more helpful..
1 parent e7615fd commit 68aff12

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

cpp-linter/src/clang_tools/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,15 @@ pub async fn capture_clang_tools_output(
248248
}
249249

250250
while let Some(output) = executors.join_next().await {
251-
if let Ok(out) = output? {
252-
let (file_name, logs) = out;
253-
rest_api_client.start_log_group(format!("Analyzing {}", file_name.to_string_lossy()));
254-
for (level, msg) in logs {
255-
log::log!(level, "{}", msg);
256-
}
257-
rest_api_client.end_log_group();
251+
// output?? acts as a fast-fail for any error encountered.
252+
// This includes any `spawn()` error and any `analyze_single_file()` error.
253+
// Any unresolved tasks are aborted and dropped when an error is returned here.
254+
let (file_name, logs) = output??;
255+
rest_api_client.start_log_group(format!("Analyzing {}", file_name.to_string_lossy()));
256+
for (level, msg) in logs {
257+
log::log!(level, "{}", msg);
258258
}
259+
rest_api_client.end_log_group();
259260
}
260261
Ok(clang_versions)
261262
}

cpp-linter/src/run.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,56 +165,57 @@ mod test {
165165
unsafe {
166166
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
167167
}
168-
let result = run_main(vec![
168+
run_main(vec![
169169
"cpp-linter".to_string(),
170170
"-l".to_string(),
171171
"false".to_string(),
172172
"--repo-root".to_string(),
173173
"tests".to_string(),
174174
"demo/demo.cpp".to_string(),
175175
])
176-
.await;
177-
assert!(result.is_ok());
176+
.await
177+
.unwrap();
178178
}
179179

180180
#[tokio::test]
181181
async fn version_command() {
182182
unsafe {
183183
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
184184
}
185-
let result = run_main(vec!["cpp-linter".to_string(), "version".to_string()]).await;
186-
assert!(result.is_ok());
185+
run_main(vec!["cpp-linter".to_string(), "version".to_string()])
186+
.await
187+
.unwrap();
187188
}
188189

189190
#[tokio::test]
190191
async fn force_debug_output() {
191192
unsafe {
192193
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
193194
}
194-
let result = run_main(vec![
195+
run_main(vec![
195196
"cpp-linter".to_string(),
196197
"-l".to_string(),
197198
"false".to_string(),
198199
"-v".to_string(),
199200
"-i=target|benches/libgit2".to_string(),
200201
])
201-
.await;
202-
assert!(result.is_ok());
202+
.await
203+
.unwrap();
203204
}
204205

205206
#[tokio::test]
206207
async fn no_version_input() {
207208
unsafe {
208209
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
209210
}
210-
let result = run_main(vec![
211+
run_main(vec![
211212
"cpp-linter".to_string(),
212213
"-l".to_string(),
213214
"false".to_string(),
214215
"-V".to_string(),
215216
])
216-
.await;
217-
assert!(result.is_ok());
217+
.await
218+
.unwrap();
218219
}
219220

220221
#[tokio::test]
@@ -223,14 +224,14 @@ mod test {
223224
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
224225
env::set_var("PRE_COMMIT", "1");
225226
}
226-
let result = run_main(vec![
227+
run_main(vec![
227228
"cpp-linter".to_string(),
228229
"--lines-changed-only".to_string(),
229230
"false".to_string(),
230231
"--ignore=target|benches/libgit2".to_string(),
231232
])
232-
.await;
233-
assert!(result.is_err());
233+
.await
234+
.unwrap_err();
234235
}
235236

236237
// Verifies that the system gracefully handles cases where all analysis is disabled.
@@ -240,29 +241,29 @@ mod test {
240241
unsafe {
241242
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
242243
}
243-
let result = run_main(vec![
244+
run_main(vec![
244245
"cpp-linter".to_string(),
245246
"-l".to_string(),
246247
"false".to_string(),
247248
"--style".to_string(),
248249
String::new(),
249250
"--tidy-checks=-*".to_string(),
250251
])
251-
.await;
252-
assert!(result.is_ok());
252+
.await
253+
.unwrap();
253254
}
254255

255256
#[tokio::test]
256257
async fn bad_repo_root() {
257258
unsafe {
258259
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
259260
}
260-
let result = run_main(vec![
261+
run_main(vec![
261262
"cpp-linter".to_string(),
262263
"--repo-root".to_string(),
263264
"some-non-existent-dir".to_string(),
264265
])
265-
.await;
266-
assert!(result.is_err());
266+
.await
267+
.unwrap_err();
267268
}
268269
}

0 commit comments

Comments
 (0)