use panic_attacker::types::*;
use panic_attacker::xray;
use std::path::Path;
#[test]
fn test_xray_vulnerable_program() {
let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/vulnerable_program.rs");
let report = xray::analyze(&example).expect("analysis should succeed");
assert_eq!(report.language, Language::Rust);
assert!(
!report.weak_points.is_empty(),
"vulnerable_program.rs should produce weak points"
);
for wp in &report.weak_points {
assert!(
wp.location.is_some(),
"weak point {:?} should have a file location, got None",
wp.category
);
}
assert!(report.statistics.total_lines > 0);
assert!(
report.statistics.unwrap_calls > 0,
"vulnerable_program.rs contains .unwrap() calls"
);
assert!(
report.statistics.unsafe_blocks > 0,
"vulnerable_program.rs contains unsafe blocks"
);
assert!(
report.statistics.threading_constructs > 0,
"vulnerable_program.rs uses std::sync"
);
}
#[test]
fn test_xray_no_duplicates() {
let examples_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples");
let report = xray::analyze(&examples_dir).expect("analysis should succeed");
let mut seen = std::collections::HashSet::new();
for wp in &report.weak_points {
let key = (format!("{:?}", wp.category), wp.location.clone());
assert!(
seen.insert(key.clone()),
"duplicate weak point: {:?} at {:?}",
key.0,
key.1
);
}
}
#[test]
fn test_xray_per_file_stats() {
let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/vulnerable_program.rs");
let report = xray::analyze(&example).expect("analysis should succeed");
assert!(
!report.file_statistics.is_empty(),
"file_statistics should contain entries for files with findings"
);
for fs in &report.file_statistics {
assert!(!fs.file_path.is_empty(), "file_path should not be empty");
assert!(fs.lines > 0, "lines should be > 0 for source files");
}
}