Skip to main content

cc_audit/runtime/
context.rs

1//! Scan context management.
2//!
3//! Note: This is a skeleton for v1.x.
4
5use crate::config::Config;
6use std::path::PathBuf;
7
8/// Context for a scan operation.
9#[derive(Debug, Clone)]
10pub struct ScanContext {
11    /// Root paths to scan.
12    pub paths: Vec<PathBuf>,
13    /// Configuration for the scan.
14    pub config: Config,
15    /// Whether to run in verbose mode.
16    pub verbose: bool,
17    /// Whether to run in strict mode.
18    pub strict: bool,
19}
20
21impl ScanContext {
22    /// Create a new scan context.
23    pub fn new(paths: Vec<PathBuf>, config: Config) -> Self {
24        Self {
25            paths,
26            config,
27            verbose: false,
28            strict: false,
29        }
30    }
31
32    /// Set verbose mode.
33    pub fn with_verbose(mut self, verbose: bool) -> Self {
34        self.verbose = verbose;
35        self
36    }
37
38    /// Set strict mode.
39    pub fn with_strict(mut self, strict: bool) -> Self {
40        self.strict = strict;
41        self
42    }
43}
44
45impl Default for ScanContext {
46    fn default() -> Self {
47        Self::new(Vec::new(), Config::default())
48    }
49}
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_scan_context_builder() {
57        let ctx = ScanContext::new(vec![PathBuf::from(".")], Config::default())
58            .with_verbose(true)
59            .with_strict(true);
60
61        assert!(ctx.verbose);
62        assert!(ctx.strict);
63    }
64
65    #[test]
66    fn test_scan_context_default() {
67        let ctx = ScanContext::default();
68        assert!(ctx.paths.is_empty());
69        assert!(!ctx.verbose);
70        assert!(!ctx.strict);
71    }
72
73    #[test]
74    fn test_scan_context_new() {
75        let paths = vec![PathBuf::from("/test/path")];
76        let ctx = ScanContext::new(paths.clone(), Config::default());
77        assert_eq!(ctx.paths, paths);
78        assert!(!ctx.verbose);
79        assert!(!ctx.strict);
80    }
81
82    #[test]
83    fn test_scan_context_debug() {
84        let ctx = ScanContext::default();
85        let debug_str = format!("{:?}", ctx);
86        assert!(debug_str.contains("ScanContext"));
87    }
88
89    #[test]
90    fn test_scan_context_clone() {
91        let ctx = ScanContext::new(vec![PathBuf::from(".")], Config::default()).with_verbose(true);
92        let cloned = ctx.clone();
93        assert_eq!(ctx.paths, cloned.paths);
94        assert_eq!(ctx.verbose, cloned.verbose);
95    }
96}