Skip to content

Commit df3dc8a

Browse files
authored
test: cover wheel-tag parsing and clang advice tallying (#465)
## Summary Adds unit tests that raise coverage of existing, unmodified behavior. No source or configuration behavior is changed. ## Tests added 11 deterministic, offline unit tests: - `clang-tools-manager/src/downloader/pypi.rs` (8) — `PlatformTag::from_str` branches (`win32`, `win_<arch>`, the missing‑arch error, `macosx`, `musllinux_`, `manylinux_`, and the dotted `.manylinux` alternative) plus a `WheelTags::from_str` success case. - `cpp-linter/src/clang_tools/clang_tidy.rs` (2) — `tally_tidy_advice` and `TidyAdvice::get_suggestion_help`. - `cpp-linter/src/clang_tools/clang_format.rs` (1) — `tally_format_advice`. ## Coverage Base project coverage is 92.74% (Codecov, `main`). These tests exercise wheel‑tag parsing branches and the advice‑tally / suggestion‑help helpers that had no prior unit tests; the official project delta is measured by CI/Codecov on this PR. ## Verification - `cargo nextest run` (the new tests and sibling pure tests) — all pass against the unmodified source. - `cargo fmt --check` and `cargo clippy --features bin -- -D warnings` — clean. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Expanded coverage for recognizing package wheel filenames across Windows, macOS, and Linux variants, including malformed tags. * Added checks for how formatting and linting advice is counted, including empty advice and filename matching. * Added checks for the guidance shown when linting suggestions are available or when a matching suggestion is not found. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 13f9f8f commit df3dc8a

3 files changed

Lines changed: 148 additions & 1 deletion

File tree

‎clang-tools-manager/src/downloader/pypi.rs‎

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ const EXTRACTED_CHUNK_SIZE: u64 = 1024;
613613
mod test {
614614
use std::str::FromStr;
615615

616-
use super::{PlatformTag, PyPiReleaseInfo, WheelTags};
616+
use super::{LinuxLibC, PlatformOs, PlatformTag, PyPiReleaseInfo, WheelTags};
617617

618618
#[test]
619619
fn bad_json_digest() {
@@ -655,4 +655,77 @@ mod test {
655655
let err = WheelTags::from_str(bad_wheel_name).unwrap_err();
656656
println!("{}", err);
657657
}
658+
659+
#[test]
660+
fn win32_tag() {
661+
let tag = PlatformTag::from_str("win32").unwrap();
662+
assert!(matches!(tag.os, PlatformOs::Windows));
663+
assert_eq!(tag.arch.as_str(), "x86");
664+
}
665+
666+
#[test]
667+
fn win_amd64_tag() {
668+
let tag = PlatformTag::from_str("win_amd64").unwrap();
669+
assert!(matches!(tag.os, PlatformOs::Windows));
670+
assert_eq!(tag.arch.as_str(), "amd64");
671+
}
672+
673+
#[test]
674+
fn win_missing_arch_tag() {
675+
// "win" prefix without an "_<arch>" suffix is malformed.
676+
let err = PlatformTag::from_str("win").unwrap_err();
677+
println!("{}", err);
678+
}
679+
680+
#[test]
681+
fn macosx_tag() {
682+
let tag = PlatformTag::from_str("macosx_11_0_arm64").unwrap();
683+
assert!(matches!(tag.os, PlatformOs::MacOS));
684+
assert_eq!(tag.arch.as_str(), "arm64");
685+
}
686+
687+
#[test]
688+
fn musllinux_tag() {
689+
let tag = PlatformTag::from_str("musllinux_1_2_x86_64").unwrap();
690+
assert!(matches!(
691+
tag.os,
692+
PlatformOs::Linux {
693+
lib_c: LinuxLibC::Musl { .. }
694+
}
695+
));
696+
assert_eq!(tag.arch.as_str(), "x86_64");
697+
}
698+
699+
#[test]
700+
fn manylinux2_tag() {
701+
let tag = PlatformTag::from_str("manylinux_2_17_x86_64").unwrap();
702+
assert!(matches!(
703+
tag.os,
704+
PlatformOs::Linux {
705+
lib_c: LinuxLibC::Glibc { .. }
706+
}
707+
));
708+
assert_eq!(tag.arch.as_str(), "x86_64");
709+
}
710+
711+
#[test]
712+
fn manylinux_dotted_tag() {
713+
// A combined tag like "manylinux_2_17_x86_64.manylinux2014_x86_64" should
714+
// select the "manylinux_" variant from the dotted alternatives.
715+
let tag = PlatformTag::from_str("manylinux_2_17_x86_64.manylinux2014_x86_64").unwrap();
716+
assert!(matches!(
717+
tag.os,
718+
PlatformOs::Linux {
719+
lib_c: LinuxLibC::Glibc { .. }
720+
}
721+
));
722+
assert_eq!(tag.arch.as_str(), "x86_64");
723+
}
724+
725+
#[test]
726+
fn valid_wheel_tags() {
727+
let wheel_name = "clang_format-17.0.0-py3-none-manylinux_2_17_x86_64.whl";
728+
let tags = WheelTags::from_str(wheel_name).unwrap();
729+
assert_eq!(tags.platform.arch.as_str(), "x86_64");
730+
}
658731
}

‎cpp-linter/src/clang_tools/clang_format.rs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,34 @@ mod tests {
338338
formalize_style("file", "Custom");
339339
}
340340

341+
#[test]
342+
fn tally_counts_only_nonempty_advice() {
343+
use std::sync::{Arc, Mutex};
344+
345+
use super::{FormatAdvice, tally_format_advice};
346+
use crate::common_fs::FileObj;
347+
348+
let mut with_advice = FileObj::new(std::path::PathBuf::from("demo.cpp"));
349+
#[allow(clippy::single_range_in_vec_init)]
350+
{
351+
with_advice.format_advice = Some(FormatAdvice {
352+
replacements: vec![1..=2],
353+
});
354+
}
355+
let mut empty_advice = FileObj::new(std::path::PathBuf::from("empty.cpp"));
356+
empty_advice.format_advice = Some(FormatAdvice {
357+
replacements: vec![],
358+
});
359+
// a third file with no advice at all is also ignored
360+
let no_advice = FileObj::new(std::path::PathBuf::from("none.cpp"));
361+
let files = vec![
362+
Arc::new(Mutex::new(with_advice)),
363+
Arc::new(Mutex::new(empty_advice)),
364+
Arc::new(Mutex::new(no_advice)),
365+
];
366+
assert_eq!(tally_format_advice(&files).unwrap(), 1);
367+
}
368+
341369
#[test]
342370
fn three_way_diff_mixed() {
343371
const OG_SRC: &str =

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,52 @@ TrenchBroom/TrenchBroom/common/test/src/mdl/tst_ReadFreeImageTexture.cpp:44:48:
603603
}
604604
}
605605

606+
fn dummy_note(filename: &str, fixed_lines: Vec<u32>) -> TidyNotification {
607+
TidyNotification {
608+
filename: filename.to_string(),
609+
line: 5,
610+
cols: 1,
611+
severity: String::from("warning"),
612+
rationale: String::from("a dummy rationale"),
613+
diagnostic: String::from("modernize-use-auto"),
614+
suggestion: vec![],
615+
fixed_lines,
616+
}
617+
}
618+
619+
#[test]
620+
fn tally_counts_matching_notes() {
621+
use super::{TidyAdvice, tally_tidy_advice};
622+
623+
let mut file = FileObj::new(PathBuf::from("demo.cpp"));
624+
file.tidy_advice = Some(TidyAdvice {
625+
notes: vec![
626+
// matches the file name -> counted
627+
dummy_note("demo.cpp", vec![]),
628+
// does not match the file name -> not counted
629+
dummy_note("other.cpp", vec![]),
630+
],
631+
});
632+
let files = vec![Arc::new(Mutex::new(file))];
633+
assert_eq!(tally_tidy_advice(&files).unwrap(), 1);
634+
}
635+
636+
#[test]
637+
fn suggestion_help_with_and_without_fixes() {
638+
use super::TidyAdvice;
639+
640+
let advice = TidyAdvice {
641+
notes: vec![dummy_note("demo.cpp", vec![5])],
642+
};
643+
// A fixed line within the range yields a "diagnostic(s)" header plus the rationale.
644+
let help = advice.get_suggestion_help(1, 10);
645+
assert!(help.contains("clang-tidy diagnostic(s)"));
646+
assert!(help.contains("a dummy rationale"));
647+
// No fixed line within the range falls back to a plain "suggestion" header.
648+
let help = advice.get_suggestion_help(20, 30);
649+
assert!(help.contains("clang-tidy suggestion"));
650+
}
651+
606652
#[test]
607653
fn restore_on_drop_fires() {
608654
let tmp = tempfile::tempdir().unwrap();

0 commit comments

Comments
 (0)