2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2020-09-17 19:43:04 -07:00
|
|
|
|
2023-01-16 00:42:34 -08:00
|
|
|
#[test]
|
|
|
|
fn env() {
|
|
|
|
Test::new()
|
|
|
|
.arg("--choose")
|
|
|
|
.env("JUST_CHOOSER", "head -n1")
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo foo
|
|
|
|
|
|
|
|
bar:
|
|
|
|
echo bar
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.stderr("echo bar\n")
|
|
|
|
.stdout("bar\n")
|
|
|
|
.run();
|
2020-09-17 19:43:04 -07:00
|
|
|
}
|
|
|
|
|
2023-01-16 00:42:34 -08:00
|
|
|
#[test]
|
|
|
|
fn chooser() {
|
|
|
|
Test::new()
|
|
|
|
.arg("--choose")
|
|
|
|
.arg("--chooser")
|
|
|
|
.arg("head -n1")
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo foo
|
|
|
|
|
|
|
|
bar:
|
|
|
|
echo bar
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.stderr("echo bar\n")
|
|
|
|
.stdout("bar\n")
|
|
|
|
.run();
|
2020-09-17 19:43:04 -07:00
|
|
|
}
|
|
|
|
|
2023-01-16 00:42:34 -08:00
|
|
|
#[test]
|
|
|
|
fn override_variable() {
|
|
|
|
Test::new()
|
|
|
|
.arg("--choose")
|
|
|
|
.arg("baz=B")
|
|
|
|
.env("JUST_CHOOSER", "head -n1")
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
baz := 'A'
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo foo
|
|
|
|
|
|
|
|
bar:
|
|
|
|
echo {{baz}}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.stderr("echo B\n")
|
|
|
|
.stdout("B\n")
|
|
|
|
.run();
|
2020-09-17 19:43:04 -07:00
|
|
|
}
|
|
|
|
|
2023-01-16 00:42:34 -08:00
|
|
|
#[test]
|
|
|
|
fn skip_private_recipes() {
|
|
|
|
Test::new()
|
|
|
|
.arg("--choose")
|
|
|
|
.env("JUST_CHOOSER", "head -n1")
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo foo
|
|
|
|
|
|
|
|
_bar:
|
|
|
|
echo bar
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.stderr("echo foo\n")
|
|
|
|
.stdout("foo\n")
|
|
|
|
.run();
|
2020-09-17 19:43:04 -07:00
|
|
|
}
|
|
|
|
|
2024-05-20 23:22:56 -07:00
|
|
|
#[test]
|
|
|
|
fn recipes_in_submodules_can_be_chosen() {
|
|
|
|
Test::new()
|
|
|
|
.args(["--unstable", "--choose"])
|
|
|
|
.env("JUST_CHOOSER", "head -n10")
|
|
|
|
.write("bar.just", "baz:\n echo BAZ")
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
mod bar
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.stderr("echo BAZ\n")
|
|
|
|
.stdout("BAZ\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2023-01-16 00:42:34 -08:00
|
|
|
#[test]
|
|
|
|
fn skip_recipes_that_require_arguments() {
|
|
|
|
Test::new()
|
|
|
|
.arg("--choose")
|
|
|
|
.env("JUST_CHOOSER", "head -n1")
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo foo
|
|
|
|
|
|
|
|
bar BAR:
|
|
|
|
echo {{BAR}}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.stderr("echo foo\n")
|
|
|
|
.stdout("foo\n")
|
|
|
|
.run();
|
2020-09-17 19:43:04 -07:00
|
|
|
}
|
|
|
|
|
2023-01-16 00:42:34 -08:00
|
|
|
#[test]
|
|
|
|
fn no_choosable_recipes() {
|
2023-10-16 20:07:09 -07:00
|
|
|
Test::new()
|
2023-01-16 00:42:34 -08:00
|
|
|
.arg("--choose")
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
_foo:
|
|
|
|
echo foo
|
|
|
|
|
|
|
|
bar BAR:
|
|
|
|
echo {{BAR}}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.stderr("error: Justfile contains no choosable recipes.\n")
|
|
|
|
.stdout("")
|
|
|
|
.run();
|
2020-09-17 19:43:04 -07:00
|
|
|
}
|
|
|
|
|
2023-01-16 00:42:34 -08:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn multiple_recipes() {
|
|
|
|
Test::new()
|
|
|
|
.arg("--choose")
|
|
|
|
.arg("--chooser")
|
|
|
|
.arg("echo foo bar")
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo foo
|
|
|
|
|
|
|
|
bar:
|
|
|
|
echo bar
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.stderr("echo foo\necho bar\n")
|
|
|
|
.stdout("foo\nbar\n")
|
|
|
|
.run();
|
2020-10-10 17:54:58 -07:00
|
|
|
}
|
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
#[test]
|
|
|
|
fn invoke_error_function() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo foo
|
|
|
|
|
|
|
|
bar:
|
|
|
|
echo bar
|
|
|
|
",
|
|
|
|
)
|
2023-01-28 00:24:54 -08:00
|
|
|
.stderr_regex(
|
2023-12-13 16:48:40 -08:00
|
|
|
r#"error: Chooser `/ -cu fzf --multi --preview 'just --unstable --color always --justfile ".*justfile" --show \{\}'` invocation failed: .*\n"#,
|
2023-01-28 00:24:54 -08:00
|
|
|
)
|
2021-07-26 01:26:06 -07:00
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.shell(false)
|
2023-01-03 22:31:56 -08:00
|
|
|
.args(["--shell", "/", "--choose"])
|
2021-07-26 01:26:06 -07:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
fn status_error() {
|
|
|
|
let tmp = temptree! {
|
|
|
|
justfile: "foo:\n echo foo\nbar:\n echo bar\n",
|
|
|
|
"exit-2": "#!/usr/bin/env bash\nexit 2\n",
|
|
|
|
};
|
|
|
|
|
2024-06-17 19:42:16 -07:00
|
|
|
let output = Command::new("chmod")
|
|
|
|
.arg("+x")
|
|
|
|
.arg(tmp.path().join("exit-2"))
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(output.status.success());
|
2021-07-26 01:26:06 -07:00
|
|
|
|
|
|
|
let path = env::join_paths(
|
|
|
|
iter::once(tmp.path().to_owned()).chain(env::split_paths(&env::var_os("PATH").unwrap())),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.arg("--choose")
|
|
|
|
.arg("--chooser")
|
|
|
|
.arg("exit-2")
|
|
|
|
.env("PATH", path)
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
2021-08-27 17:01:50 -07:00
|
|
|
assert!(
|
|
|
|
Regex::new("^error: Chooser `exit-2` failed: exit (code|status): 2\n$")
|
|
|
|
.unwrap()
|
|
|
|
.is_match(str::from_utf8(&output.stderr).unwrap())
|
2021-07-26 01:26:06 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(output.status.code().unwrap(), 2);
|
|
|
|
}
|
|
|
|
|
2020-09-17 19:43:04 -07:00
|
|
|
#[test]
|
|
|
|
fn default() {
|
2021-07-03 14:26:59 -07:00
|
|
|
let tmp = temptree! {
|
2020-09-17 19:43:04 -07:00
|
|
|
justfile: "foo:\n echo foo\n",
|
|
|
|
};
|
|
|
|
|
|
|
|
let cat = which("cat").unwrap();
|
2023-10-16 20:07:09 -07:00
|
|
|
let fzf = tmp.path().join(format!("fzf{EXE_SUFFIX}"));
|
2020-09-17 19:43:04 -07:00
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
std::os::unix::fs::symlink(cat, fzf).unwrap();
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
std::os::windows::fs::symlink_file(cat, fzf).unwrap();
|
|
|
|
|
|
|
|
let path = env::join_paths(
|
|
|
|
iter::once(tmp.path().to_owned()).chain(env::split_paths(&env::var_os("PATH").unwrap())),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.arg("--choose")
|
2023-01-28 00:24:54 -08:00
|
|
|
.arg("--chooser=fzf")
|
2020-09-17 19:43:04 -07:00
|
|
|
.current_dir(tmp.path())
|
|
|
|
.env("PATH", path)
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_stdout(&output, "foo\n");
|
|
|
|
}
|