use super::common::*;
#[test]
fn test_python_check_good_file() {
if !has_ruff() {
eprintln!("Skipping test_python_check_good_file: ruff not available");
return;
}
let temp = create_temp_project();
write_fixture(temp.path(), "good.py", PYTHON_GOOD);
let output = linthis_cmd()
.args(["-c", "-i", "good.py"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
}
#[test]
fn test_python_check_bad_file() {
if !has_ruff() {
eprintln!("Skipping test_python_check_bad_file: ruff not available");
return;
}
let temp = create_temp_project();
write_fixture(temp.path(), "bad.py", PYTHON_BAD);
let output = linthis_cmd()
.args(["-c", "-i", "bad.py"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let _ = output.status;
}
#[test]
fn test_check_with_language_flag() {
if !has_ruff() {
eprintln!("Skipping test_check_with_language_flag: ruff not available");
return;
}
let temp = create_temp_project();
write_fixture(temp.path(), "test.py", PYTHON_GOOD);
write_fixture(temp.path(), "test.rs", RUST_GOOD);
let output = linthis_cmd()
.args(["-c", "--lang", "python", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
}
#[test]
fn test_check_with_exclude() {
if !has_ruff() {
eprintln!("Skipping test_check_with_exclude: ruff not available");
return;
}
let temp = create_temp_project();
write_fixture(temp.path(), "src/good.py", PYTHON_GOOD);
write_fixture(temp.path(), "vendor/bad.py", PYTHON_BAD);
let output = linthis_cmd()
.args(["-c", "--exclude", "vendor/**", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
}
#[test]
fn test_check_quiet_mode() {
let temp = create_temp_project();
write_fixture(temp.path(), "test.py", PYTHON_GOOD);
let output = linthis_cmd()
.args(["-c", "--quiet", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.len() < 500,
"Quiet mode should have minimal output, got {} bytes",
stdout.len()
);
}
#[test]
fn test_check_verbose_mode() {
let temp = create_temp_project();
write_fixture(temp.path(), "test.py", PYTHON_GOOD);
let output = linthis_cmd()
.args(["-c", "--verbose", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("Mode:") || stderr.contains("linthis"),
"Verbose mode should show extra info"
);
}
#[test]
fn test_check_json_output() {
if !has_ruff() {
eprintln!("Skipping test_check_json_output: ruff not available");
return;
}
let temp = create_temp_project();
write_fixture(temp.path(), "test.py", PYTHON_GOOD);
let output = linthis_cmd()
.args(["-c", "--output", "json", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.contains("{") || stdout.is_empty() || stdout.contains("issues"),
"JSON output should be valid JSON format"
);
}
#[test]
fn test_check_nonexistent_file() {
let output = linthis_cmd()
.args(["-c", "-i", "/nonexistent/path/file.py"])
.output()
.expect("Failed to run linthis");
let _ = output.status;
}
#[test]
fn test_check_empty_directory() {
let temp = create_temp_project();
let output = linthis_cmd()
.args(["-c", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
}
#[test]
fn test_check_multiple_files() {
if !has_ruff() {
eprintln!("Skipping test_check_multiple_files: ruff not available");
return;
}
let temp = create_temp_project();
write_fixture(temp.path(), "a.py", PYTHON_GOOD);
write_fixture(temp.path(), "b.py", PYTHON_GOOD);
write_fixture(temp.path(), "c.py", PYTHON_GOOD);
let output = linthis_cmd()
.args(["-c", "-i", "a.py", "-i", "b.py", "-i", "c.py"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
}
#[test]
fn test_check_no_save_result() {
if !has_ruff() {
eprintln!("Skipping test_check_no_save_result: ruff not available");
return;
}
let temp = create_temp_project();
write_fixture(temp.path(), "test.py", PYTHON_GOOD);
let output = linthis_cmd()
.args(["-c", "--no-save-result", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
let result_dir = temp.path().join(".linthis").join("result");
if result_dir.exists() {
let entries: Vec<_> = std::fs::read_dir(&result_dir)
.unwrap()
.filter_map(|e| e.ok())
.collect();
assert!(
entries.is_empty(),
"No result files should be saved with --no-save-result"
);
}
}