use super::common::*;
#[test]
fn test_invalid_config_error() {
let temp = create_temp_project();
write_fixture(
temp.path(),
".linthis/linthis.toml",
"invalid = [ toml { syntax\n",
);
write_fixture(temp.path(), "test.py", PYTHON_GOOD);
let output = linthis_cmd()
.args(["-c", "-i", "test.py"])
.current_dir(temp.path())
.output()
.expect("Failed to execute linthis");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let combined = format!("{}{}", stdout, stderr);
assert!(
!output.status.success()
|| combined.contains("config")
|| combined.contains("TOML")
|| combined.contains("parse")
|| combined.contains("error")
|| combined.contains("warning")
|| combined.len() > 0,
"Should handle config error gracefully"
);
}
#[test]
fn test_missing_tool_graceful() {
let temp = create_temp_project();
write_fixture(temp.path(), "test.xyz123", "some content\n");
let output = linthis_cmd()
.args(["-c", "-i", "test.xyz123"])
.current_dir(temp.path())
.output()
.expect("Failed to execute linthis");
let _ = output.status;
}
#[test]
fn test_unsupported_language_handling() {
let temp = create_temp_project();
write_fixture(
temp.path(),
".linthis/linthis.toml",
r#"
[languages]
enabled = ["unsupported_lang_xyz"]
"#,
);
write_fixture(temp.path(), "test.txt", "some text\n");
let output = linthis_cmd()
.args(["-c", "-i", "test.txt"])
.current_dir(temp.path())
.output()
.expect("Failed to execute linthis");
let _ = output.status;
}
#[test]
fn test_file_not_found_error() {
let output = linthis_cmd()
.args(["-c", "/nonexistent/path/file.py"])
.output()
.expect("Failed to execute linthis");
let _ = output.status;
}
#[test]
fn test_checker_failure_continues() {
if !has_ruff() {
eprintln!("Skipping test_checker_failure_continues: ruff not available");
return;
}
let temp = create_temp_project();
write_fixture(temp.path(), "good.py", PYTHON_GOOD);
write_fixture(temp.path(), "bad.py", PYTHON_BAD);
write_fixture(temp.path(), "another_good.py", PYTHON_GOOD);
let output = linthis_cmd()
.args(["-c", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to execute linthis");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let combined = format!("{}{}", stdout, stderr);
assert!(
combined.contains("good.py")
|| combined.contains("bad.py")
|| combined.contains("files")
|| combined.len() > 0,
"Should process multiple files"
);
}
#[test]
fn test_formatter_failure_continues() {
if !has_ruff() {
eprintln!("Skipping test_formatter_failure_continues: ruff not available");
return;
}
let temp = create_temp_project();
write_fixture(temp.path(), "file1.py", PYTHON_UNFORMATTED);
write_fixture(temp.path(), "file2.py", PYTHON_GOOD);
let output = linthis_cmd()
.args(["-f", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to execute linthis");
let _ = output.status;
}
#[test]
fn test_verbose_error_output() {
if !has_ruff() {
eprintln!("Skipping test_verbose_error_output: 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", "-v"])
.current_dir(temp.path())
.output()
.expect("Failed to execute linthis");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stdout.len() > 0 || stderr.len() > 0,
"Verbose mode should produce output"
);
}
#[test]
fn test_empty_project() {
let temp = create_temp_project();
let output = linthis_cmd()
.args(["-c", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to execute linthis");
assert!(output.status.success());
}
#[test]
#[cfg(unix)]
fn test_permission_handling() {
use std::os::unix::fs::PermissionsExt;
let temp = create_temp_project();
let subdir = temp.path().join("restricted");
std::fs::create_dir(&subdir).expect("Failed to create subdir");
write_fixture(&subdir, "test.py", PYTHON_GOOD);
let mut perms = std::fs::metadata(&subdir)
.expect("Failed to get metadata")
.permissions();
perms.set_mode(0o000);
std::fs::set_permissions(&subdir, perms).expect("Failed to set permissions");
let output = linthis_cmd()
.args(["-c", "-i", "."])
.current_dir(temp.path())
.output()
.expect("Failed to execute linthis");
let mut perms = std::fs::metadata(&subdir)
.expect("Failed to get metadata")
.permissions();
perms.set_mode(0o755);
std::fs::set_permissions(&subdir, perms).expect("Failed to restore permissions");
let _ = output.status;
}