Implement config file parsing and precedence with CLI

This commit is contained in:
2026-03-31 01:22:08 +02:00
parent f1d7a14b8d
commit 0119834d5a
9 changed files with 746 additions and 135 deletions

View File

@@ -9,6 +9,12 @@ fn sandbox(extra_args: &[&str]) -> Command {
cmd
}
fn write_config(dir: &TempDir, content: &str) -> String {
let path = dir.path().join("config.toml");
fs::write(&path, content).expect("failed to write config");
path.to_str().unwrap().to_string()
}
fn read_sid_from_stat(stat: &str) -> u32 {
stat.trim()
.split_whitespace()
@@ -538,3 +544,36 @@ fn rw_missing_path_errors() {
"expected path in error message, got: {stderr}"
);
}
#[test]
fn config_missing_file_errors() {
let output = sandbox(&["--config", "/nonexistent/config.toml"])
.args(["--", "true"])
.output()
.expect("failed to execute");
assert!(!output.status.success());
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("/nonexistent/config.toml"),
"expected config path in error, got: {stderr}"
);
}
#[test]
fn config_invalid_toml_errors() {
let dir = TempDir::new().unwrap();
let cfg = write_config(&dir, "not valid {{{{ toml");
let output = sandbox(&["--config", &cfg])
.args(["--", "true"])
.output()
.expect("failed to execute");
assert!(!output.status.success());
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("cannot parse"),
"expected parse error, got: {stderr}"
);
}