feat: Default env variables

This commit is contained in:
2025-04-06 14:21:17 -04:00
parent ac948f193b
commit a5d442f7ff
4 changed files with 103 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
extern crate comlexr;
extern crate rstest;
use std::env;
use comlexr::cmd;
use rstest::rstest;
@@ -35,6 +37,37 @@ fn env_vars() {
assert_eq!(format!("{command:?}"), r#"TEST="test" "echo" "test""#);
}
#[test]
fn conditional_env_vars() {
env::set_var("TEST", "realvalue");
env::set_var("TEST2", "won't see");
let command = cmd!(
env {
"TEST":? "test",
"TEST2": "test2"
};
"echo",
"test",
);
assert_eq!(format!("{command:?}"), r#"TEST2="test2" "echo" "test""#);
let command = cmd!(
env {
"TEST": "test",
"TEST2": "test2"
};
"echo",
"test",
);
assert_eq!(
format!("{command:?}"),
r#"TEST="test" TEST2="test2" "echo" "test""#
);
}
#[test]
fn cd_env_vars() {
let command = cmd!(