Skip to content

Commit a298d6c

Browse files
committed
test clang-tidy --extra-arg is appended to command args
also adjust testing CI workflow (typo & remove default option)
1 parent c72a344 commit a298d6c

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

.github/workflows/run-dev-tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
with:
4949
tool: cargo-nextest,cargo-llvm-cov,cargo-binstall
5050

51-
- name: Install llvm-cov-pretty (HTL report generator)
51+
- name: Install llvm-cov-pretty (HTML report generator)
5252
run: cargo binstall -y llvm-cov-pretty
5353

5454
- uses: actions/setup-python@v5
@@ -90,7 +90,7 @@ jobs:
9090
working-directory: cpp-linter-lib
9191
env:
9292
CLANG_VERSION: ${{ matrix.version }}
93-
run: cargo llvm-cov --hide-instantiations --lib --no-report nextest
93+
run: cargo llvm-cov --lib --no-report nextest
9494

9595
- name: Generate Coverage HTML report
9696
working-directory: cpp-linter-lib

cpp-linter-lib/src/clang_tools/clang_tidy.rs

+43-2
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,20 @@ pub fn run_clang_tidy(
204204

205205
#[cfg(test)]
206206
mod test {
207+
use std::{env, path::PathBuf, process::Command};
208+
209+
use regex::Regex;
210+
211+
use crate::{clang_tools::get_clang_tool_exe, common_fs::FileObj};
212+
213+
use super::run_clang_tidy;
214+
215+
// ***************** test for regex parsing of clang-tidy stdout
216+
207217
#[test]
208218
fn test_capture() {
209219
let src = "tests/demo/demo.hpp:11:11: warning: use a trailing return type for this function [modernize-use-trailing-return-type]";
210-
let pat =
211-
regex::Regex::new(r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+)\]$").unwrap();
220+
let pat = Regex::new(r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+)\]$").unwrap();
212221
let cap = pat.captures(src).unwrap();
213222
assert_eq!(
214223
cap.get(0).unwrap().as_str(),
@@ -224,4 +233,36 @@ mod test {
224233
.as_str()
225234
)
226235
}
236+
237+
#[test]
238+
fn use_extra_args() {
239+
let exe_path = get_clang_tool_exe(
240+
"clang-tidy",
241+
env::var("CLANG_VERSION").unwrap_or("".to_string()).as_str(),
242+
)
243+
.unwrap();
244+
let mut cmd = Command::new(exe_path);
245+
let file = FileObj::new(PathBuf::from("tests/demo/demo.cpp"));
246+
let extra_args = vec!["-std=c++17", "-Wall"];
247+
let tidy_advice = run_clang_tidy(
248+
&mut cmd,
249+
&file,
250+
"", // use .clang-tidy config file
251+
0, // check all lines
252+
&None, // no database path
253+
&Some(extra_args), // <---- the reason for this test
254+
&None, // no deserialized database
255+
);
256+
// since `cmd` was passed as a mutable reference, we can inspect the args that were added
257+
let mut args = cmd
258+
.get_args()
259+
.map(|arg| arg.to_str().unwrap())
260+
.collect::<Vec<&str>>();
261+
assert_eq!(file.name.to_string_lossy(), args.pop().unwrap());
262+
assert_eq!(
263+
vec!["--extra-arg", "\"-std=c++17\"", "--extra-arg", "\"-Wall\""],
264+
args
265+
);
266+
assert!(!tidy_advice.is_empty());
267+
}
227268
}

cpp-linter-lib/src/rest_api/github_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl RestApiClient for GithubApiClient {
105105
.expect("GITHUB_OUTPUT file could not be opened");
106106
if let Err(e) = writeln!(
107107
gh_out_file,
108-
"checks-failed={}\nformat-checks-failed={}\ntidy-checks-failed={}\n",
108+
"checks-failed={}\nformat-checks-failed={}\ntidy-checks-failed={}",
109109
checks_failed,
110110
format_checks_failed.unwrap_or(0),
111111
tidy_checks_failed.unwrap_or(0),

0 commit comments

Comments
 (0)