pub mod chmod_world_writable_sensitive_path;
pub mod eval_on_array;
pub mod find_execdir_with_shell;
pub mod fork_bomb_pattern;
pub mod rm_glob_on_variable_path;
pub mod rm_rootish_target;
pub mod ssh_local_expansion;

#[cfg(test)]
mod tests {
    use std::path::Path;

    use test_case::test_case;

    use crate::test::test_path;
    use crate::{LinterSettings, Rule, assert_diagnostics};

    #[test_case(Rule::ChmodWorldWritableSensitivePath, Path::new("K007.sh"))]
    #[test_case(Rule::FindExecDirWithShell, Path::new("K004.sh"))]
    #[test_case(Rule::ForkBombPattern, Path::new("K008.sh"))]
    #[test_case(Rule::RmGlobOnVariablePath, Path::new("K001.sh"))]
    #[test_case(Rule::RmRootishTarget, Path::new("K006.sh"))]
    #[test_case(Rule::SshLocalExpansion, Path::new("K002.sh"))]
    #[test_case(Rule::EvalOnArray, Path::new("K003.sh"))]
    fn rules(rule: Rule, path: &Path) -> anyhow::Result<()> {
        let snapshot = format!("{}_{}", rule.code(), path.display());
        let (diagnostics, source) = test_path(
            Path::new("security").join(path).as_path(),
            &LinterSettings::for_rule(rule),
        )?;
        assert_diagnostics!(snapshot, diagnostics, &source);
        Ok(())
    }
}
