Add shell() function for running external commands (#2047)

This commit is contained in:
Saheed Adeleye
2024-05-20 01:24:27 +01:00
committed by GitHub
parent 198b37c020
commit c6612de760
9 changed files with 182 additions and 14 deletions

View File

@@ -759,6 +759,47 @@ fn just_pid() {
assert_eq!(stdout.parse::<u32>().unwrap(), pid);
}
#[test]
fn shell_no_argument() {
Test::new()
.justfile("var := shell()")
.args(["--evaluate"])
.stderr(
"
error: Function `shell` called with 0 arguments but takes 1 or more
——▶ justfile:1:8
1 │ var := shell()
│ ^^^^^
",
)
.status(EXIT_FAILURE)
.run();
}
#[test]
fn shell_minimal() {
assert_eval_eq("shell('echo $0 $1', 'justice', 'legs')", "justice legs");
}
#[test]
fn shell_error() {
Test::new()
.justfile("var := shell('exit 1')")
.args(["--evaluate"])
.stderr(
"
error: Call to function `shell` failed: Process exited with status code 1
——▶ justfile:1:8
1 │ var := shell('exit 1')
│ ^^^^^
",
)
.status(EXIT_FAILURE)
.run();
}
#[test]
fn blake3() {
Test::new()