in src/output.rs [783:834]
fn test_covdir() {
let tmp_dir = tempfile::tempdir().expect("Failed to create temporary directory");
let file_name = "test_covdir.json";
let file_path = tmp_dir.path().join(file_name);
let results = vec![
(
PathBuf::from("foo/bar/a.cpp"),
PathBuf::from("foo/bar/a.cpp"),
CovResult {
lines: [(1, 10), (2, 11)].iter().cloned().collect(),
branches: BTreeMap::new(),
functions: FxHashMap::default(),
},
),
(
PathBuf::from("foo/bar/b.cpp"),
PathBuf::from("foo/bar/b.cpp"),
CovResult {
lines: [(1, 0), (2, 10), (4, 0)].iter().cloned().collect(),
branches: BTreeMap::new(),
functions: FxHashMap::default(),
},
),
(
PathBuf::from("foo/c.cpp"),
PathBuf::from("foo/c.cpp"),
CovResult {
lines: [(1, 10), (4, 1)].iter().cloned().collect(),
branches: BTreeMap::new(),
functions: FxHashMap::default(),
},
),
(
PathBuf::from("/foo/d.cpp"),
PathBuf::from("/foo/d.cpp"),
CovResult {
lines: [(1, 10), (2, 0)].iter().cloned().collect(),
branches: BTreeMap::new(),
functions: FxHashMap::default(),
},
),
];
output_covdir(&results, Some(&file_path), 2);
let results: Value = serde_json::from_str(&read_file(&file_path)).unwrap();
let expected_path = PathBuf::from("./test/").join(file_name);
let expected: Value = serde_json::from_str(&read_file(&expected_path)).unwrap();
assert_eq!(results, expected);
}