just/tests/fall_back_to_parent.rs
Casey Rodarmor 76bda4cfd9
Allow fallback with search directory (#1348)
This loosens a restriction, and allows falling back to a justfile in a parent justfile
when a search directory is provide, e.g. with `just ..` or `just foo/bar/`. Looking
 at it now, I can't really think of why I enforced that restriction in the first place.
Hopefully it's not important 🤷‍♀️.
2022-09-21 05:46:53 +00:00

199 lines
3.2 KiB
Rust

use super::*;
#[test]
fn runs_recipe_in_parent_if_not_found_in_current() {
Test::new()
.tree(tree! {
bar: {
justfile: "
baz:
echo subdir
"
}
})
.justfile(
"
foo:
echo root
",
)
.args(&["--unstable", "foo"])
.current_dir("bar")
.stderr(format!(
"
Trying ..{}justfile
echo root
",
MAIN_SEPARATOR
))
.stdout("root\n")
.run();
}
#[test]
fn print_error_from_parent_if_recipe_not_found_in_current() {
Test::new()
.tree(tree! {
bar: {
justfile: "
baz:
echo subdir
"
}
})
.justfile("foo:\n echo {{bar}}")
.args(&["--unstable", "foo"])
.current_dir("bar")
.stderr(format!(
"
Trying ..{}justfile
error: Variable `bar` not defined
|
2 | echo {{{{bar}}}}
| ^^^
",
MAIN_SEPARATOR
))
.status(EXIT_FAILURE)
.run();
}
#[test]
fn requires_unstable() {
Test::new()
.tree(tree! {
bar: {
justfile: "
baz:
echo subdir
"
}
})
.justfile(
"
foo:
echo root
",
)
.args(&["foo"])
.current_dir("bar")
.status(EXIT_FAILURE)
.stderr("error: Justfile does not contain recipe `foo`.\n")
.run();
}
#[test]
fn works_with_provided_search_directory() {
Test::new()
.tree(tree! {
bar: {
justfile: "
baz:
echo subdir
"
}
})
.justfile(
"
foo:
echo root
",
)
.args(&["--unstable", "./foo"])
.stdout("root\n")
.stderr(format!(
"
Trying ..{}justfile
echo root
",
MAIN_SEPARATOR
))
.current_dir("bar")
.run();
}
#[test]
fn doesnt_work_with_justfile() {
Test::new()
.tree(tree! {
bar: {
justfile: "
baz:
echo subdir
"
}
})
.justfile(
"
foo:
echo root
",
)
.args(&["--unstable", "--justfile", "justfile", "foo"])
.current_dir("bar")
.status(EXIT_FAILURE)
.stderr("error: Justfile does not contain recipe `foo`.\n")
.run();
}
#[test]
fn doesnt_work_with_justfile_and_working_directory() {
Test::new()
.tree(tree! {
bar: {
justfile: "
baz:
echo subdir
"
}
})
.justfile(
"
foo:
echo root
",
)
.args(&[
"--unstable",
"--justfile",
"justfile",
"--working-directory",
".",
"foo",
])
.current_dir("bar")
.status(EXIT_FAILURE)
.stderr("error: Justfile does not contain recipe `foo`.\n")
.run();
}
#[test]
fn prints_correct_error_message_when_recipe_not_found() {
Test::new()
.tree(tree! {
bar: {
justfile: "
bar:
echo subdir
"
}
})
.justfile(
"
bar:
echo root
",
)
.args(&["--unstable", "foo"])
.current_dir("bar")
.status(EXIT_FAILURE)
.stderr(format!(
"
Trying ..{}justfile
error: Justfile does not contain recipe `foo`.
",
MAIN_SEPARATOR,
))
.run();
}