1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-29 00:22:26 +01:00

Fix help/version/diagnostic commands with invalid config

This commit is contained in:
Keith Hall
2025-09-27 23:33:10 +03:00
parent 2c87b9480f
commit f605db22e3
2 changed files with 90 additions and 3 deletions

View File

@@ -1286,6 +1286,81 @@ fn diagnostic_sanity_check() {
.stderr("");
}
#[test]
fn help_works_with_invalid_config() {
let tmp_dir = tempdir().expect("can create temporary directory");
let tmp_config_path = tmp_dir.path().join("invalid-config.conf");
// Write an invalid config file
std::fs::write(&tmp_config_path, "--invalid-option").expect("can write config file");
// --help should work despite invalid config
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("A cat(1) clone with syntax highlighting"));
// -h should also work
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("-h")
.assert()
.success()
.stdout(predicate::str::contains("A cat(1) clone with wings"));
}
#[test]
fn version_works_with_invalid_config() {
let tmp_dir = tempdir().expect("can create temporary directory");
let tmp_config_path = tmp_dir.path().join("invalid-config.conf");
// Write an invalid config file
std::fs::write(&tmp_config_path, "--invalid-option").expect("can write config file");
// --version should work despite invalid config
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("--version")
.assert()
.success()
.stdout(predicate::str::contains("bat "));
// -V should also work
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("-V")
.assert()
.success()
.stdout(predicate::str::contains("bat "));
}
#[test]
fn diagnostic_works_with_invalid_config() {
let tmp_dir = tempdir().expect("can create temporary directory");
let tmp_config_path = tmp_dir.path().join("invalid-config.conf");
// Write an invalid config file
std::fs::write(&tmp_config_path, "--invalid-option").expect("can write config file");
// --diagnostic should work despite invalid config
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("--diagnostic")
.assert()
.success()
.stdout(predicate::str::contains("#### Software version"));
// --diagnostics (alias) should also work
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("--diagnostics")
.assert()
.success()
.stdout(predicate::str::contains("#### Software version"));
}
#[test]
fn config_location_test() {
bat_with_config()