mod common;
use std::process::Command;
#[test]
fn malformed_config_surfaces_parse_error_instead_of_silent_default() {
let bin = require_rledger!();
let dir = tempfile::tempdir().expect("tempdir");
std::fs::write(
dir.path().join(".rledger.toml"),
"[price.mapping.hy]\ntype = \"command\"\ncommand = [\"uv\", \"run\", \"pricedl\"]\n",
)
.expect("write config");
let output = Command::new(bin)
.args(["price", "hy"])
.current_dir(dir.path())
.env("HOME", dir.path())
.env("XDG_CONFIG_HOME", dir.path())
.env("APPDATA", dir.path())
.env("PROGRAMDATA", dir.path())
.env("USERPROFILE", dir.path())
.output()
.expect("run rledger price");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
!output.status.success(),
"a malformed config must fail, not exit 0 with defaults.\nstdout: {stdout}\nstderr: {stderr}"
);
assert!(
stderr.contains("Failed to parse config file"),
"stderr should name the config parse failure.\nstderr: {stderr}"
);
assert!(
!stdout.contains("no price source configured")
&& !stderr.contains("no price source configured"),
"the real parse error must replace the misleading 'no price source configured' message.\nstdout: {stdout}\nstderr: {stderr}"
);
}
#[test]
fn malformed_config_does_not_block_help() {
let bin = require_rledger!();
let dir = tempfile::tempdir().expect("tempdir");
std::fs::write(
dir.path().join(".rledger.toml"),
"[price.mapping.hy]\ntype = \"command\"\ncommand = [\"uv\", \"run\", \"pricedl\"]\n",
)
.expect("write config");
let output = Command::new(bin)
.arg("--help")
.current_dir(dir.path())
.env("HOME", dir.path())
.env("XDG_CONFIG_HOME", dir.path())
.env("APPDATA", dir.path())
.env("PROGRAMDATA", dir.path())
.env("USERPROFILE", dir.path())
.output()
.expect("run rledger --help");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
output.status.success(),
"--help must succeed despite a broken config (no bootstrap deadlock); \
stdout: {stdout}\nstderr: {}",
String::from_utf8_lossy(&output.stderr)
);
assert!(
stdout.contains("Usage") || stdout.contains("usage"),
"--help should print usage; stdout: {stdout}"
);
}