diff --git a/crates/tests/src/lib.rs b/crates/tests/src/lib.rs index 191b506..acae14c 100644 --- a/crates/tests/src/lib.rs +++ b/crates/tests/src/lib.rs @@ -1080,30 +1080,60 @@ async fn variable_expansion() { .run() .await; + TestBuilder::new() + .command(r#"echo "${FOO:-5}""#) + .assert_stdout("5\n") + .run() + .await; + TestBuilder::new() .command(r#"FOO=1 && echo ${FOO:-5}"#) .assert_stdout("1\n") .run() .await; + TestBuilder::new() + .command(r#"FOO=1 && echo "${FOO:-5}""#) + .assert_stdout("1\n") + .run() + .await; + TestBuilder::new() .command(r#"echo ${FOO:-${BAR:-5}}"#) .assert_stdout("5\n") .run() .await; + TestBuilder::new() + .command(r#"echo "${FOO:-${BAR:-5}}""#) + .assert_stdout("5\n") + .run() + .await; + TestBuilder::new() .command("BAR=2 && echo ${FOO:-${BAR:-5}}") .assert_stdout("2\n") .run() .await; + TestBuilder::new() + .command(r#"BAR=2 && echo "${FOO:-${BAR:-5}}""#) + .assert_stdout("2\n") + .run() + .await; + TestBuilder::new() .command("echo ${BAR:-THE VALUE CAN CONTAIN SPACES}") .assert_stdout("THE VALUE CAN CONTAIN SPACES\n") .run() .await; + TestBuilder::new() + .command(r#"echo "${BAR:-THE VALUE CAN CONTAIN SPACES}""#) + .assert_stdout("THE VALUE CAN CONTAIN SPACES\n") + .run() + .await; + // ASSIGN DEFAULT EXPANSION TestBuilder::new() .command("echo ${FOO:=5} && echo $FOO") @@ -1111,18 +1141,36 @@ async fn variable_expansion() { .run() .await; + TestBuilder::new() + .command(r#"echo "${FOO:=5}" && echo "$FOO""#) + .assert_stdout("5\n5\n") + .run() + .await; + TestBuilder::new() .command(r#"FOO=1 && echo ${FOO:=5} && echo $FOO"#) .assert_stdout("1\n1\n") .run() .await; + TestBuilder::new() + .command(r#"FOO=1 && echo "${FOO:=5}" && echo "$FOO""#) + .assert_stdout("1\n1\n") + .run() + .await; + TestBuilder::new() .command(r#"echo ${FOO:=${BAR:=5}} && echo $FOO && echo $BAR"#) .assert_stdout("5\n5\n5\n") .run() .await; + TestBuilder::new() + .command(r#"echo "${FOO:=${BAR:=5}}" && echo "$FOO" && echo "$BAR""#) + .assert_stdout("5\n5\n5\n") + .run() + .await; + // SUBSTRING VARIABLE EXPANSION TestBuilder::new() .command(r#"FOO=12345 && echo ${FOO:1:3}"#) @@ -1130,18 +1178,36 @@ async fn variable_expansion() { .run() .await; + TestBuilder::new() + .command(r#"FOO=12345 && echo "${FOO:1:3}""#) + .assert_stdout("234\n") + .run() + .await; + TestBuilder::new() .command(r#"FOO=12345 && echo ${FOO:1}"#) .assert_stdout("2345\n") .run() .await; + TestBuilder::new() + .command(r#"FOO=12345 && echo "${FOO:1}""#) + .assert_stdout("2345\n") + .run() + .await; + TestBuilder::new() .command(r#"FOO=12345 && echo ${FOO:1:-1}"#) .assert_stdout("234\n") .run() .await; + TestBuilder::new() + .command(r#"FOO=12345 && echo "${FOO:1:-1}""#) + .assert_stdout("234\n") + .run() + .await; + // ALTERNATE VALUE EXPANSION TestBuilder::new() .command(r#"FOO=1 && echo ${FOO:+5}"#) @@ -1149,47 +1215,95 @@ async fn variable_expansion() { .run() .await; + TestBuilder::new() + .command(r#"FOO=1 && echo "${FOO:+5}""#) + .assert_stdout("5\n") + .run() + .await; + TestBuilder::new() .command(r#"echo ${FOO:+5}"#) .assert_stdout("\n") .run() .await; + TestBuilder::new() + .command(r#"echo "${FOO:+5}""#) + .assert_stdout("\n") + .run() + .await; + TestBuilder::new() .command(r#"FOO=1 && echo ${FOO:+${BAR:+5}}"#) .assert_stdout("\n") .run() .await; + TestBuilder::new() + .command(r#"FOO=1 && echo "${FOO:+${BAR:+5}}""#) + .assert_stdout("\n") + .run() + .await; + TestBuilder::new() .command(r#"FOO=1 && BAR=2 && echo ${FOO:+${BAR:+5}}"#) .assert_stdout("5\n") .run() .await; + TestBuilder::new() + .command(r#"FOO=1 && BAR=2 && echo "${FOO:+${BAR:+5}}""#) + .assert_stdout("5\n") + .run() + .await; + TestBuilder::new() .command("FOO=12345 && echo ${FOO:2:$((2+2))}") .assert_stdout("345\n") .run() .await; + TestBuilder::new() + .command(r#"FOO=12345 && echo "${FOO:2:$((2+2))}""#) + .assert_stdout("345\n") + .run() + .await; + TestBuilder::new() .command("FOO=12345 && echo ${FOO: -2:-1}") .assert_stdout("4\n") .run() .await; + TestBuilder::new() + .command(r#"FOO=12345 && echo "${FOO: -2:-1}""#) + .assert_stdout("4\n") + .run() + .await; + TestBuilder::new() .command("FOO=12345 && echo ${FOO: -2}") .assert_stdout("45\n") .run() .await; + TestBuilder::new() + .command(r#"FOO=12345 && echo "${FOO: -2}""#) + .assert_stdout("45\n") + .run() + .await; + TestBuilder::new() .command("FOO=12345 && echo ${FOO: -4: 2}") .assert_stdout("23\n") .run() .await; + + TestBuilder::new() + .command(r#"FOO=12345 && echo "${FOO: -4: 2}""#) + .assert_stdout("23\n") + .run() + .await; } #[cfg(test)]