Skip to content

Commit

Permalink
Add tests for cloned shell
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai committed Mar 27, 2024
1 parent 57c4d63 commit 8590604
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
41 changes: 23 additions & 18 deletions tests/it/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,34 @@ fn test_env() {
let v1 = "xshell_test_123";
let v2 = "xshell_test_456";

assert_env(cmd!(sh, "xecho -$ {v1}").env(v1, "123"), &[(v1, Some("123"))]);

assert_env(
cmd!(sh, "xecho -$ {v1} {v2}").envs([(v1, "123"), (v2, "456")].iter().copied()),
&[(v1, Some("123")), (v2, Some("456"))],
);
assert_env(
cmd!(sh, "xecho -$ {v1} {v2}")
.envs([(v1, "123"), (v2, "456")].iter().copied())
.env_remove(v2),
&[(v1, Some("123")), (v2, None)],
);
assert_env(
cmd!(sh, "xecho -$ {v1} {v2}")
.envs([(v1, "123"), (v2, "456")].iter().copied())
.env_remove("nothing"),
&[(v1, Some("123")), (v2, Some("456"))],
);
let cloned_sh = sh.clone();

for sh in [&sh, &cloned_sh] {
assert_env(cmd!(sh, "xecho -$ {v1}").env(v1, "123"), &[(v1, Some("123"))]);

assert_env(
cmd!(sh, "xecho -$ {v1} {v2}").envs([(v1, "123"), (v2, "456")].iter().copied()),
&[(v1, Some("123")), (v2, Some("456"))],
);
assert_env(
cmd!(sh, "xecho -$ {v1} {v2}")
.envs([(v1, "123"), (v2, "456")].iter().copied())
.env_remove(v2),
&[(v1, Some("123")), (v2, None)],
);
assert_env(
cmd!(sh, "xecho -$ {v1} {v2}")
.envs([(v1, "123"), (v2, "456")].iter().copied())
.env_remove("nothing"),
&[(v1, Some("123")), (v2, Some("456"))],
);
}

let _g1 = sh.push_env(v1, "foobar");
let _g2 = sh.push_env(v2, "quark");

assert_env(cmd!(sh, "xecho -$ {v1} {v2}"), &[(v1, Some("foobar")), (v2, Some("quark"))]);
assert_env(cmd!(cloned_sh, "xecho -$ {v1} {v2}"), &[(v1, None), (v2, None)]);

assert_env(
cmd!(sh, "xecho -$ {v1} {v2}").env(v1, "wombo"),
Expand Down
12 changes: 12 additions & 0 deletions tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,18 @@ fn test_push_env() {
assert_eq!(e5, e1);
}

#[test]
fn test_push_env_clone() {
let sh = setup();

assert!(sh.var_os(VAR).is_none());
let guard = sh.push_env(VAR, "1");
let cloned = sh.clone();
drop(guard);
assert_eq!(sh.var_os(VAR), None);
assert_eq!(cloned.var_os(VAR), Some("1".into()));
}

#[test]
fn test_push_env_and_set_var() {
let sh = setup();
Expand Down

0 comments on commit 8590604

Please sign in to comment.