use std::fs;
use std::process::{Command, Stdio};
use tempfile::TempDir;
fn run_kelora_in_dir(dir: &std::path::Path, args: &[&str], input: &str) -> (String, String, i32) {
let binary_path = if cfg!(debug_assertions) {
std::env::current_dir().unwrap().join("target/debug/kelora")
} else {
std::env::current_dir()
.unwrap()
.join("target/release/kelora")
};
let mut cmd = Command::new(&binary_path)
.current_dir(dir)
.env("HOME", dir) .env("XDG_CONFIG_HOME", dir.join(".config"))
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("Failed to start kelora");
if let Some(stdin) = cmd.stdin.as_mut() {
use std::io::Write;
stdin
.write_all(input.as_bytes())
.expect("Failed to write to stdin");
}
let output = cmd.wait_with_output().expect("Failed to read output");
(
String::from_utf8_lossy(&output.stdout).to_string(),
String::from_utf8_lossy(&output.stderr).to_string(),
output.status.code().unwrap_or(-1),
)
}
fn run_kelora_in_dir_with_env(
dir: &std::path::Path,
args: &[&str],
input: &str,
envs: &[(&str, &str)],
) -> (String, String, i32) {
let binary_path = if cfg!(debug_assertions) {
std::env::current_dir().unwrap().join("target/debug/kelora")
} else {
std::env::current_dir()
.unwrap()
.join("target/release/kelora")
};
let mut cmd = Command::new(&binary_path);
cmd.current_dir(dir)
.env("HOME", dir)
.env("XDG_CONFIG_HOME", dir.join(".config"))
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
for (key, value) in envs {
cmd.env(key, value);
}
let mut child = cmd.spawn().expect("Failed to start kelora");
if let Some(stdin) = child.stdin.as_mut() {
use std::io::Write;
stdin
.write_all(input.as_bytes())
.expect("Failed to write to stdin");
}
let output = child.wait_with_output().expect("Failed to read output");
(
String::from_utf8_lossy(&output.stdout).to_string(),
String::from_utf8_lossy(&output.stderr).to_string(),
output.status.code().unwrap_or(-1),
)
}
#[test]
fn test_config_file_with_defaults() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "defaults = -f json --with-stats\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, r#"{"level": "info", "msg": "test"}"#).unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(exit_code, 0, "kelora should exit successfully");
assert!(
stderr.contains("Events") || stderr.contains("processed"),
"Expected stats in output, got: {}",
stderr
);
}
#[test]
fn test_default_config_path_is_not_printed_on_normal_runs() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "defaults = -f line\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "hello\n").unwrap();
let (_stdout, stderr, exit_code) =
run_kelora_in_dir(temp_dir.path(), &[log_file.to_str().unwrap()], "");
assert_eq!(exit_code, 0, "kelora should exit successfully");
assert!(
!stderr.contains("Config:"),
"default config path should be suppressed on normal runs: {}",
stderr
);
assert!(
!stderr.contains("Defaults:"),
"default config expansion details should be suppressed on normal runs: {}",
stderr
);
}
#[test]
fn test_explicit_config_file_path_is_still_printed() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("custom.ini");
fs::write(&config_path, "defaults = -f line\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "hello\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(exit_code, 0, "kelora should exit successfully");
assert!(
stderr.contains("Config:"),
"explicit config file path should still be shown: {}",
stderr
);
}
#[test]
fn test_config_file_with_alias() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(
&config_path,
"[aliases]\nerrors = --filter \"e.level == \\\"error\\\"\"\n",
)
.unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(
&log_file,
r#"{"level": "info", "msg": "info message"}
{"level": "error", "msg": "error message"}
{"level": "info", "msg": "another info"}"#,
)
.unwrap();
let (stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
"-f",
"json",
"--alias",
"errors",
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(
exit_code, 0,
"kelora should exit successfully, stderr: {}",
stderr
);
assert!(
stdout.contains("error message"),
"Expected filtered error message, got: {}",
stdout
);
assert!(
!stdout.contains("info message"),
"Should not contain info messages"
);
}
#[test]
fn test_ignore_config_flag() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "defaults = --with-stats\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test log line\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&["--ignore-config", log_file.to_str().unwrap()],
"",
);
assert_eq!(exit_code, 0, "kelora should exit successfully");
assert!(
!stderr.contains("Events processed") && !stderr.contains("Events created"),
"Should not show stats when config ignored, got: {}",
stderr
);
}
#[test]
fn test_ignore_config_env_skips_ambient_project_and_user_config() {
let temp_dir = TempDir::new().unwrap();
let project_config = temp_dir.path().join(".kelora.ini");
let user_config_dir = temp_dir.path().join(".config").join("kelora");
let user_config = user_config_dir.join("kelora.ini");
fs::write(&project_config, "defaults = --with-stats\n").unwrap();
fs::create_dir_all(&user_config_dir).unwrap();
fs::write(&user_config, "defaults = --with-stats\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test log line\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir_with_env(
temp_dir.path(),
&[log_file.to_str().unwrap()],
"",
&[("KELORA_IGNORE_CONFIG", "1")],
);
assert_eq!(exit_code, 0, "kelora should exit successfully");
assert!(
!stderr.contains("Config:"),
"Should not show config expansion info, got: {}",
stderr
);
assert!(
!stderr.contains("Events processed") && !stderr.contains("Events created"),
"Should not apply ambient config defaults, got: {}",
stderr
);
}
#[test]
fn test_ignore_config_env_still_allows_explicit_config_file() {
let temp_dir = TempDir::new().unwrap();
let ambient_project_config = temp_dir.path().join(".kelora.ini");
let explicit_config = temp_dir.path().join("explicit.ini");
fs::write(&ambient_project_config, "defaults = -q\n").unwrap();
fs::write(&explicit_config, "defaults = --with-stats\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test log line\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir_with_env(
temp_dir.path(),
&[
"--config-file",
explicit_config.to_str().unwrap(),
log_file.to_str().unwrap(),
],
"",
&[("KELORA_IGNORE_CONFIG", "1")],
);
assert_eq!(exit_code, 0, "kelora should exit successfully");
assert!(
stderr.contains("Config:"),
"Expected explicit config file to load, got: {}",
stderr
);
assert!(
stderr.contains("Events") || stderr.contains("processed"),
"Expected explicit config defaults to apply, got: {}",
stderr
);
}
#[test]
fn test_project_config_precedence() {
let temp_dir = TempDir::new().unwrap();
let project_config = temp_dir.path().join(".kelora.ini");
fs::write(
&project_config,
"defaults = --with-stats\n[aliases]\ntest-alias = -q\n",
)
.unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test log line\n").unwrap();
let (_stdout, stderr, exit_code) =
run_kelora_in_dir(temp_dir.path(), &[log_file.to_str().unwrap()], "");
assert_eq!(exit_code, 0, "kelora should exit successfully");
assert!(
stderr.contains("Events") || stderr.contains("Stats"),
"Expected stats from project config, got: {}",
stderr
);
}
#[test]
fn test_custom_config_file_path() {
let temp_dir = TempDir::new().unwrap();
let custom_config = temp_dir.path().join("custom.ini");
fs::write(&custom_config, "defaults = --with-stats\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test log line\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
custom_config.to_str().unwrap(),
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(exit_code, 0, "kelora should exit successfully");
assert!(
stderr.contains("Events") || stderr.contains("Stats"),
"Expected stats from custom config, got: {}",
stderr
);
}
#[test]
fn test_invalid_config_produces_error() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "defaults = --filter 'unclosed quote\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test log line\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
log_file.to_str().unwrap(),
],
"",
);
assert_ne!(exit_code, 0, "Should fail with invalid config");
assert!(
stderr.to_lowercase().contains("fail")
|| stderr.to_lowercase().contains("error")
|| stderr.to_lowercase().contains("invalid"),
"Expected error message, got: {}",
stderr
);
}
#[test]
fn test_nonexistent_config_file_error() {
let temp_dir = TempDir::new().unwrap();
let nonexistent_config = temp_dir.path().join("does-not-exist.ini");
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test log line\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
nonexistent_config.to_str().unwrap(),
log_file.to_str().unwrap(),
],
"",
);
assert_ne!(exit_code, 0, "Should fail with nonexistent config");
assert!(
stderr.contains("Failed to read config file") || stderr.contains("No such file"),
"Expected file not found error, got: {}",
stderr
);
}
#[test]
fn test_recursive_alias_resolution() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(
&config_path,
"[aliases]\nbase = -f json\nerrors = --alias base --filter \"e.level == \\\"error\\\"\"\n",
)
.unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, r#"{"level": "error", "msg": "test"}"#).unwrap();
let (_stdout, _stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
"--alias",
"errors",
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(exit_code, 0, "Should resolve nested aliases");
}
#[test]
fn test_circular_alias_error() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(
&config_path,
"[aliases]\nalias1 = --alias alias2\nalias2 = --alias alias1\n",
)
.unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
"--alias",
"alias1",
log_file.to_str().unwrap(),
],
"",
);
assert_ne!(exit_code, 0, "Should fail on circular alias");
assert!(
stderr.to_lowercase().contains("circular"),
"Expected circular dependency error, got: {}",
stderr
);
}
#[test]
fn test_unknown_alias_error() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "[aliases]\nknown = -f json\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
"--alias",
"unknown",
log_file.to_str().unwrap(),
],
"",
);
assert_ne!(exit_code, 0, "Should fail on unknown alias");
assert!(
stderr.contains("Unknown alias") || stderr.to_lowercase().contains("unknown"),
"Expected unknown alias error, got: {}",
stderr
);
}
#[test]
fn test_defaults_with_cli_override() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "defaults = -f json\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "plain text log\n").unwrap();
let (_stdout, _stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
"-f",
"line",
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(exit_code, 0, "CLI override should work with defaults");
}
#[test]
fn test_alias_with_quoted_args() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path,
"[aliases]\ncomplex = --filter \"e.level == \\\"error\\\" && e.msg.matches(\\\"critical\\\")\"\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(
&log_file,
r#"{"level": "error", "msg": "critical error"}
{"level": "error", "msg": "normal error"}
{"level": "info", "msg": "critical info"}"#,
)
.unwrap();
let (stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
"-f",
"json",
"--alias",
"complex",
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(
exit_code, 0,
"kelora should exit successfully, stderr: {}",
stderr
);
assert!(
stdout.contains("critical error"),
"Should match critical error, got: {}",
stdout
);
assert!(
!stdout.contains("normal error"),
"Should not match normal error"
);
assert!(
!stdout.contains("critical info"),
"Should not match info level"
);
}
#[test]
fn test_empty_config_file() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test log line\n").unwrap();
let (_stdout, _stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(exit_code, 0, "Empty config should not cause errors");
}
#[test]
fn test_config_with_comments() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path,
"# This is a comment\ndefaults = --with-stats\n; Another comment\n[aliases]\n# Alias comment\nerrors = -l error\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, "test\n").unwrap();
let (_stdout, stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(exit_code, 0, "Config with comments should parse");
assert!(
stderr.contains("Events") || stderr.contains("Stats"),
"Should apply defaults from commented config, got: {}",
stderr
);
}
#[test]
fn test_show_config_displays_content() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
let config_content = "defaults = -f json\n[aliases]\ntest = --with-stats\n";
fs::write(&config_path, config_content).unwrap();
let (stdout, _stderr, exit_code) = run_kelora_in_dir(temp_dir.path(), &["--show-config"], "");
assert_eq!(
exit_code, 0,
"kelora --show-config should exit successfully"
);
assert!(
stdout.contains("defaults = -f json"),
"Should show defaults, got: {}",
stdout
);
assert!(stdout.contains("[aliases]"), "Should show aliases section");
assert!(stdout.contains("test = --with-stats"), "Should show alias");
}
#[test]
fn test_show_config_no_file_found() {
let temp_dir = TempDir::new().unwrap();
let (stdout, _stderr, exit_code) = run_kelora_in_dir(temp_dir.path(), &["--show-config"], "");
assert_eq!(
exit_code, 0,
"kelora --show-config should exit successfully even without config"
);
assert!(
stdout.contains("No config found") || stdout.contains("Example"),
"Should show helpful message when no config found, got: {}",
stdout
);
}
#[test]
fn test_multiple_aliases_in_one_command() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "[aliases]\njson-fmt = -f json\nquiet = -q\n").unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(&log_file, r#"{"level": "info", "msg": "test"}"#).unwrap();
let (_stdout, _stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
"--alias",
"json-fmt",
"--alias",
"quiet",
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(exit_code, 0, "Should handle multiple aliases");
}
#[test]
fn test_defaults_and_alias_combination() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(
&config_path,
"defaults = -f json\n[aliases]\nerrors = --filter \"e.level == \\\"error\\\"\"\n",
)
.unwrap();
let log_file = temp_dir.path().join("test.log");
fs::write(
&log_file,
r#"{"level": "info", "msg": "info"}
{"level": "error", "msg": "error"}"#,
)
.unwrap();
let (stdout, _stderr, exit_code) = run_kelora_in_dir(
temp_dir.path(),
&[
"--config-file",
config_path.to_str().unwrap(),
"--alias",
"errors",
log_file.to_str().unwrap(),
],
"",
);
assert_eq!(exit_code, 0, "kelora should exit successfully");
assert!(
stdout.contains("error"),
"Should show error level, got: {}",
stdout
);
assert!(!stdout.contains("info"), "Should not show info level");
}
#[test]
fn test_save_alias_update_with_self_reference() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "[aliases]\nerrors = -l error\n").unwrap();
let binary_path = if cfg!(debug_assertions) {
std::env::current_dir().unwrap().join("target/debug/kelora")
} else {
std::env::current_dir()
.unwrap()
.join("target/release/kelora")
};
let output = Command::new(&binary_path)
.args([
"--save-alias",
"errors",
"--config-file",
config_path.to_str().unwrap(),
"-a",
"errors",
"--stats",
])
.output()
.unwrap();
assert!(
output.status.success(),
"kelora should exit successfully, stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
let config_content = fs::read_to_string(&config_path).unwrap();
assert!(
config_content.contains("errors = -l error --stats"),
"Config should contain flattened alias, got: {}",
config_content
);
assert!(
!config_content.contains("-a errors") && !config_content.contains("--alias errors"),
"Config should not contain alias reference, got: {}",
config_content
);
}
#[test]
fn test_save_alias_compose_with_reference() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "[aliases]\nerrors = -l error\n").unwrap();
let binary_path = if cfg!(debug_assertions) {
std::env::current_dir().unwrap().join("target/debug/kelora")
} else {
std::env::current_dir()
.unwrap()
.join("target/release/kelora")
};
let output = Command::new(&binary_path)
.args([
"--save-alias",
"json-errors",
"--config-file",
config_path.to_str().unwrap(),
"-a",
"errors",
"-f",
"json",
])
.output()
.unwrap();
assert!(
output.status.success(),
"kelora should exit successfully, stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
let config_content = fs::read_to_string(&config_path).unwrap();
assert!(
config_content.contains("json-errors = -a errors -f json"),
"Config should preserve alias reference, got: {}",
config_content
);
}
#[test]
fn test_save_alias_error_on_unknown_reference() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(&config_path, "[aliases]\nknown = -l error\n").unwrap();
let binary_path = if cfg!(debug_assertions) {
std::env::current_dir().unwrap().join("target/debug/kelora")
} else {
std::env::current_dir()
.unwrap()
.join("target/release/kelora")
};
let output = Command::new(&binary_path)
.args([
"--save-alias",
"new-alias",
"--config-file",
config_path.to_str().unwrap(),
"-a",
"unknown",
"--stats",
])
.output()
.unwrap();
assert!(
!output.status.success(),
"kelora should fail when referencing unknown alias"
);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("Referenced alias 'unknown' does not exist") || stderr.contains("unknown"),
"Error message should mention unknown alias, got: {}",
stderr
);
}
#[test]
fn test_save_alias_nested_resolution_in_update() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
fs::write(
&config_path,
"[aliases]\nbase = -f json\nerrors = -a base -l error\n",
)
.unwrap();
let binary_path = if cfg!(debug_assertions) {
std::env::current_dir().unwrap().join("target/debug/kelora")
} else {
std::env::current_dir()
.unwrap()
.join("target/release/kelora")
};
let output = Command::new(&binary_path)
.args([
"--save-alias",
"errors",
"--config-file",
config_path.to_str().unwrap(),
"-a",
"errors",
"--stats",
])
.output()
.unwrap();
assert!(
output.status.success(),
"kelora should exit successfully, stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
let config_content = fs::read_to_string(&config_path).unwrap();
assert!(
config_content.contains("errors = -f json -l error --stats"),
"Config should contain fully resolved alias, got: {}",
config_content
);
assert!(
!config_content.contains("json-errors")
|| !config_content[config_content.find("errors = ").unwrap()..].contains("-a"),
"Errors alias should not contain -a reference, got: {}",
config_content
);
}
#[test]
fn test_save_alias_full_workflow() {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join(".kelora.ini");
let binary_path = if cfg!(debug_assertions) {
std::env::current_dir().unwrap().join("target/debug/kelora")
} else {
std::env::current_dir()
.unwrap()
.join("target/release/kelora")
};
Command::new(&binary_path)
.args([
"--save-alias",
"json",
"--config-file",
config_path.to_str().unwrap(),
"-f",
"json",
])
.output()
.unwrap();
Command::new(&binary_path)
.args([
"--save-alias",
"json-errors",
"--config-file",
config_path.to_str().unwrap(),
"-a",
"json",
"-l",
"error",
])
.output()
.unwrap();
let content = fs::read_to_string(&config_path).unwrap();
assert!(
content.contains("json = -f json"),
"Should have json alias, got: {}",
content
);
assert!(
content.contains("json-errors = -a json -l error"),
"Should have json-errors with reference, got: {}",
content
);
Command::new(&binary_path)
.args([
"--save-alias",
"json-errors",
"--config-file",
config_path.to_str().unwrap(),
"-a",
"json-errors",
"--stats",
])
.output()
.unwrap();
let content = fs::read_to_string(&config_path).unwrap();
assert!(
content.contains("json-errors = -f json -l error --stats"),
"Should have flattened json-errors, got: {}",
content
);
}