#![allow(clippy::unwrap_used)]
#![allow(clippy::expect_used)]
use super::*;
use std::path::PathBuf;
use tempfile::TempDir;
#[test]
fn test_cov_lint_single_clean_shell_file() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("clean.sh");
fs::write(&file, "#!/bin/sh\nset -eu\necho hello\n").unwrap();
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: None,
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
}
#[test]
fn test_cov_lint_json_format() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("test.sh");
fs::write(&file, "#!/bin/sh\necho hello\n").unwrap();
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Json,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: None,
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
}
#[test]
fn test_cov_lint_sarif_format() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("test.sh");
fs::write(&file, "#!/bin/sh\necho hello\n").unwrap();
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Sarif,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: None,
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
}
#[test]
fn test_cov_lint_quiet_mode() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("test.sh");
fs::write(&file, "#!/bin/sh\necho hello\n").unwrap();
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: true,
level: crate::cli::args::LintLevel::Warning,
ignore_rules: None,
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
}
#[test]
fn test_cov_lint_level_error() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("test.sh");
fs::write(&file, "#!/bin/sh\necho hello\n").unwrap();
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Error,
ignore_rules: None,
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
}
#[test]
fn test_cov_lint_ignore_rules() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("test.sh");
fs::write(&file, "#!/bin/sh\necho $RANDOM\n").unwrap();
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: Some("DET001,SEC001"),
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
}
#[test]
fn test_cov_lint_exclude_rules() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("test.sh");
fs::write(&file, "#!/bin/sh\necho $RANDOM\n").unwrap();
let excludes = vec!["DET001".to_string(), "SEC001".to_string()];
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: None,
exclude_rules: Some(&excludes),
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
}
#[test]
fn test_cov_lint_citl_export() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("test.sh");
fs::write(&file, "#!/bin/sh\necho $HOME\n").unwrap();
let citl_path = dir.path().join("diags.citl.json");
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: None,
exclude_rules: None,
citl_export_path: Some(&citl_path),
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
assert!(citl_path.exists());
}
#[test]
fn test_cov_lint_ci_mode() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("test.sh");
fs::write(&file, "#!/bin/sh\nset -eu\necho hello\n").unwrap();
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: None,
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
}
#[test]
fn test_cov_lint_no_inputs() {
let inputs: Vec<PathBuf> = vec![];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: None,
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let result = lint_command(opts);
assert!(result.is_err());
}
#[test]
fn test_cov_lint_makefile() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("Makefile");
fs::write(
&file,
".PHONY: all\nall:\n\t@echo building\n\tgcc -o main main.c\n",
)
.unwrap();
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: None,
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Standard,
ci: true,
fail_on: crate::cli::args::LintLevel::Error,
};
let _ = lint_command(opts);
}
#[test]
fn test_cov_lint_dockerfile() {
let dir = TempDir::new().unwrap();
let file = dir.path().join("Dockerfile");
fs::write(&file, "FROM ubuntu:22.04\nRUN apt-get update\n").unwrap();
let inputs = vec![file];
let opts = LintCommandOptions {
inputs: &inputs,
format: LintFormat::Human,
fix: false,
fix_assumptions: false,
output: None,
no_ignore: true,
ignore_file_path: None,
quiet: false,
level: crate::cli::args::LintLevel::Info,
ignore_rules: None,
exclude_rules: None,
citl_export_path: None,
profile: crate::cli::args::LintProfileArg::Coursera,
ci: true, fail_on: crate::cli::args::LintLevel::Error, };
let _ = lint_command(opts);
}
include!("command_tests_lint_cov_tests_cov_4.rs");