#[cfg(test)]
mod utils;
#[cfg(test)]
mod init_tests {
use crate::utils::treeflow_command::TreeflowCommand;
use assert_cmd::Command;
use predicates::prelude::predicate;
use tempdir::TempDir;
use test_case::test_case;
#[test_case(true)]
#[test_case(false)]
fn init_bash_is_valid(enable_shorthands: bool) {
let config_dir = TempDir::new("config_dir").expect("should be able to create temp config dir");
let stdout = TreeflowCommand::new(config_dir.path().to_path_buf())
.init("bash", enable_shorthands)
.cmd()
.assert()
.success()
.stdout(predicate::str::starts_with("#!/usr/bin/env sh"))
.get_output()
.stdout
.clone();
let init_script = String::from_utf8(stdout).expect("should be valid UTF-8");
if enable_shorthands {
assert!(init_script.contains("# Static aliases"), "Script should contain static aliases comment when shorthands are enabled");
} else {
assert!(!init_script.contains("# Static aliases"), "Script should not contain static aliases comment when shorthands are disabled");
}
Command::new("bash")
.args(["-c", &format!("complete() {{ :; }}\n_complete_alias() {{ :; }}\n{}", init_script)]) .assert()
.success()
.stdout(predicate::str::is_empty())
.stderr(predicate::str::is_empty());
}
#[test_case(true)]
#[test_case(false)]
fn init_zsh_is_valid(enable_shorthands: bool) {
Command::new("zsh")
.arg("--version")
.assert()
.success();
let config_dir = TempDir::new("config_dir").expect("should be able to create temp config dir");
let stdout = TreeflowCommand::new(config_dir.path().to_path_buf())
.init("zsh", enable_shorthands)
.cmd()
.assert()
.success()
.stdout(predicate::str::starts_with("#!/usr/bin/env zsh"))
.get_output()
.stdout
.clone();
let init_script = String::from_utf8(stdout).expect("should be valid UTF-8");
if enable_shorthands {
assert!(init_script.contains("# Static aliases"), "Script should contain static aliases comment when shorthands are enabled");
} else {
assert!(!init_script.contains("# Static aliases"), "Script should not contain static aliases comment when shorthands are disabled");
}
Command::new("zsh")
.args(["-c", &format!("complete() {{ :; }}\n_complete_alias() {{ :; }}\ncompdef() {{ :; }}\n{}", init_script)]) .assert()
.success()
.stdout(predicate::str::is_empty())
.stderr(predicate::str::is_empty());
}
}