Implement config file parsing and precedence with CLI
This commit is contained in:
@@ -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}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user