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
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
crate::test::Test::new()
|
|
|
|
.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(
|
|
|
|
r"error: Chooser `/ -cu fzf --preview 'just --show \{\}'` invocation failed: .*\n",
|
|
|
|
)
|
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",
|
|
|
|
};
|
|
|
|
|
2021-08-27 17:21:59 -07:00
|
|
|
("chmod", "+x", tmp.path().join("exit-2")).run();
|
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();
|
|
|
|
let fzf = tmp.path().join(format!("fzf{}", env::consts::EXE_SUFFIX));
|
|
|
|
|
|
|
|
#[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");
|
|
|
|
}
|