use super::*;
fn parse(code: &str) -> Vec<(String, String, syn::File)> {
vec![(
"test.rs".to_string(),
code.to_string(),
syn::parse_file(code).expect("parse failed"),
)]
}
fn run_dry(config: &crate::config::Config, code: &str) -> DryResults {
let parsed = parse(code);
let sups = std::collections::HashMap::new();
let api = std::collections::HashMap::new();
let test_helper = std::collections::HashMap::new();
let annotation_lines = AnnotationLines {
api: &api,
test_helper: &test_helper,
};
let cfg_test_files = std::collections::HashSet::new();
run_dry_detection(&parsed, config, &sups, &annotation_lines, &cfg_test_files)
}
#[test]
fn dead_code_detection_skipped_when_disabled() {
let mut config = crate::config::Config::default();
config.duplicates.detect_dead_code = false;
config.compile();
let dry = run_dry(&config, "fn unused() { let _ = 1; }");
assert!(
dry.dead_code.is_empty(),
"no dead-code warnings when detect_dead_code is off, got {:?}",
dry.dead_code
);
}
#[test]
fn wildcard_detection_skipped_when_duplicates_disabled() {
let mut config = crate::config::Config::default();
config.duplicates.enabled = false;
config.compile();
let dry = run_dry(&config, "use crate::foo::*;");
assert!(
dry.wildcard_warnings.is_empty(),
"no wildcard warnings when duplicates is disabled, got {:?}",
dry.wildcard_warnings
);
}