use std::process::{Command, Stdio};
#[test]
fn malformed_config_named_by_the_flag_fails_to_parse() {
let dir = tempfile::tempdir().expect("create tempdir");
let config_path = dir.path().join("bad.toml");
std::fs::write(&config_path, "this is not = = valid toml [[[\n").expect("write bad config");
let output = Command::new(env!("CARGO_BIN_EXE_repon"))
.arg("--config")
.arg(&config_path)
.stdin(Stdio::null())
.output()
.expect("run repon");
assert_eq!(output.status.code(), Some(1), "expected a non-zero exit");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("could not parse") && stderr.contains(config_path.to_str().unwrap()),
"expected a parse error naming {}, got: {stderr}",
config_path.display(),
);
assert!(
output.stdout.is_empty(),
"expected no terminal bytes on stdout, got: {:?}",
output.stdout
);
}
#[test]
fn a_bad_value_in_a_known_key_fails_to_parse_and_reports_its_position() {
let dir = tempfile::tempdir().expect("create tempdir");
let config_path = dir.path().join("bad_value.toml");
std::fs::write(&config_path, "[refresh]\npoll_interval = 2\n").expect("write bad config");
let output = Command::new(env!("CARGO_BIN_EXE_repon"))
.arg("--config")
.arg(&config_path)
.stdin(Stdio::null())
.output()
.expect("run repon");
assert_eq!(output.status.code(), Some(1), "expected a non-zero exit");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("could not parse") && stderr.contains("duration"),
"expected a duration type error, got: {stderr}",
);
assert!(
stderr.contains("line 2, column 17"),
"expected the offending value's position, got: {stderr}",
);
assert!(
output.stdout.is_empty(),
"expected no terminal bytes on stdout, got: {:?}",
output.stdout
);
}