2022-06-19 07:56:31 +03:00
|
|
|
use super::*;
|
2022-03-31 08:13:59 +03:00
|
|
|
|
2023-01-04 09:31:56 +03:00
|
|
|
#[test]
|
|
|
|
fn fallback_from_subdir_bugfix() {
|
|
|
|
Test::new()
|
|
|
|
.write(
|
|
|
|
"sub/justfile",
|
|
|
|
unindent(
|
|
|
|
"
|
|
|
|
set fallback
|
|
|
|
|
|
|
|
@default:
|
|
|
|
echo foo
|
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.args(["sub/default"])
|
|
|
|
.stdout("foo\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fallback_from_subdir_message() {
|
|
|
|
Test::new()
|
|
|
|
.justfile("bar:\n echo bar")
|
|
|
|
.write(
|
|
|
|
"sub/justfile",
|
|
|
|
unindent(
|
|
|
|
"
|
|
|
|
set fallback
|
|
|
|
|
|
|
|
@foo:
|
|
|
|
echo foo
|
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.args(["sub/bar"])
|
2023-01-14 00:36:52 +03:00
|
|
|
.stderr(path("echo bar\n"))
|
|
|
|
.stdout("bar\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fallback_from_subdir_verbose_message() {
|
|
|
|
Test::new()
|
|
|
|
.justfile("bar:\n echo bar")
|
|
|
|
.write(
|
|
|
|
"sub/justfile",
|
|
|
|
unindent(
|
|
|
|
"
|
|
|
|
set fallback
|
|
|
|
|
|
|
|
@foo:
|
|
|
|
echo foo
|
|
|
|
",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.args(["--verbose", "sub/bar"])
|
|
|
|
.stderr(path(
|
|
|
|
"
|
|
|
|
Trying ../justfile
|
|
|
|
===> Running recipe `bar`...
|
|
|
|
echo bar
|
|
|
|
",
|
|
|
|
))
|
2023-01-04 09:31:56 +03:00
|
|
|
.stdout("bar\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2022-03-31 08:13:59 +03:00
|
|
|
#[test]
|
|
|
|
fn runs_recipe_in_parent_if_not_found_in_current() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
bar: {
|
|
|
|
justfile: "
|
2022-11-26 00:02:01 +03:00
|
|
|
set fallback := true
|
|
|
|
|
2022-10-20 05:00:09 +03:00
|
|
|
baz:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo root
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["foo"])
|
2022-10-20 05:00:09 +03:00
|
|
|
.current_dir("bar")
|
2023-01-14 00:36:52 +03:00
|
|
|
.stderr(
|
2022-10-20 05:00:09 +03:00
|
|
|
"
|
|
|
|
echo root
|
|
|
|
",
|
2023-01-14 00:36:52 +03:00
|
|
|
)
|
2022-10-20 05:00:09 +03:00
|
|
|
.stdout("root\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn setting_accepts_value() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
bar: {
|
|
|
|
justfile: "
|
|
|
|
set fallback := true
|
|
|
|
|
2022-03-31 08:13:59 +03:00
|
|
|
baz:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo root
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["foo"])
|
2022-03-31 08:13:59 +03:00
|
|
|
.current_dir("bar")
|
2023-01-14 00:36:52 +03:00
|
|
|
.stderr(
|
2022-03-31 08:13:59 +03:00
|
|
|
"
|
|
|
|
echo root
|
|
|
|
",
|
2023-01-14 00:36:52 +03:00
|
|
|
)
|
2022-03-31 08:13:59 +03:00
|
|
|
.stdout("root\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn print_error_from_parent_if_recipe_not_found_in_current() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
bar: {
|
|
|
|
justfile: "
|
2022-11-26 00:02:01 +03:00
|
|
|
set fallback := true
|
|
|
|
|
2022-03-31 08:13:59 +03:00
|
|
|
baz:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.justfile("foo:\n echo {{bar}}")
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["foo"])
|
2022-03-31 08:13:59 +03:00
|
|
|
.current_dir("bar")
|
2023-01-14 00:36:52 +03:00
|
|
|
.stderr(
|
2022-03-31 08:13:59 +03:00
|
|
|
"
|
|
|
|
error: Variable `bar` not defined
|
2023-12-30 00:25:30 +03:00
|
|
|
——▶ justfile:2:9
|
|
|
|
│
|
|
|
|
2 │ echo {{bar}}
|
|
|
|
│ ^^^
|
2022-03-31 08:13:59 +03:00
|
|
|
",
|
2023-01-14 00:36:52 +03:00
|
|
|
)
|
2022-03-31 08:13:59 +03:00
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-10-20 05:00:09 +03:00
|
|
|
fn requires_setting() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
bar: {
|
|
|
|
justfile: "
|
|
|
|
baz:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo root
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["foo"])
|
2022-10-20 05:00:09 +03:00
|
|
|
.current_dir("bar")
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.stderr("error: Justfile does not contain recipe `foo`.\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2022-03-31 08:13:59 +03:00
|
|
|
#[test]
|
2022-09-21 08:46:53 +03:00
|
|
|
fn works_with_provided_search_directory() {
|
2022-03-31 08:13:59 +03:00
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
bar: {
|
|
|
|
justfile: "
|
2022-11-26 00:02:01 +03:00
|
|
|
set fallback := true
|
|
|
|
|
2022-03-31 08:13:59 +03:00
|
|
|
baz:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo root
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["./foo"])
|
2022-09-21 08:46:53 +03:00
|
|
|
.stdout("root\n")
|
2023-01-14 00:36:52 +03:00
|
|
|
.stderr(
|
2022-09-21 08:46:53 +03:00
|
|
|
"
|
|
|
|
echo root
|
|
|
|
",
|
2023-01-14 00:36:52 +03:00
|
|
|
)
|
2022-03-31 08:13:59 +03:00
|
|
|
.current_dir("bar")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doesnt_work_with_justfile() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
bar: {
|
|
|
|
justfile: "
|
|
|
|
baz:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
echo root
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["--justfile", "justfile", "foo"])
|
2022-03-31 08:13:59 +03:00
|
|
|
.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
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["--justfile", "justfile", "--working-directory", ".", "foo"])
|
2022-03-31 08:13:59 +03:00
|
|
|
.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: "
|
2022-11-26 00:02:01 +03:00
|
|
|
set fallback := true
|
|
|
|
|
2022-03-31 08:13:59 +03:00
|
|
|
bar:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
bar:
|
|
|
|
echo root
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["foo"])
|
2022-03-31 08:13:59 +03:00
|
|
|
.current_dir("bar")
|
|
|
|
.status(EXIT_FAILURE)
|
2023-01-14 00:36:52 +03:00
|
|
|
.stderr(
|
2022-03-31 08:13:59 +03:00
|
|
|
"
|
|
|
|
error: Justfile does not contain recipe `foo`.
|
|
|
|
",
|
2023-01-14 00:36:52 +03:00
|
|
|
)
|
2022-03-31 08:13:59 +03:00
|
|
|
.run();
|
|
|
|
}
|
2022-10-20 05:00:09 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_levels_of_fallback_work() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
a: {
|
|
|
|
b: {
|
|
|
|
justfile: "
|
2022-11-26 00:02:01 +03:00
|
|
|
set fallback := true
|
|
|
|
|
2022-10-20 05:00:09 +03:00
|
|
|
foo:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
},
|
|
|
|
justfile: "
|
2022-11-26 00:02:01 +03:00
|
|
|
set fallback := true
|
|
|
|
|
2022-10-20 05:00:09 +03:00
|
|
|
bar:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
baz:
|
|
|
|
echo root
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["baz"])
|
2022-10-20 05:00:09 +03:00
|
|
|
.current_dir("a/b")
|
|
|
|
.stdout("root\n")
|
2023-01-14 00:36:52 +03:00
|
|
|
.stderr(
|
2022-10-20 05:00:09 +03:00
|
|
|
"
|
|
|
|
echo root
|
|
|
|
",
|
2023-01-14 00:36:52 +03:00
|
|
|
)
|
2022-10-20 05:00:09 +03:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn stop_fallback_when_fallback_is_false() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
a: {
|
|
|
|
b: {
|
|
|
|
justfile: "
|
2022-11-26 00:02:01 +03:00
|
|
|
set fallback := true
|
|
|
|
|
2022-10-20 05:00:09 +03:00
|
|
|
foo:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
},
|
|
|
|
justfile: "
|
|
|
|
bar:
|
|
|
|
echo subdir
|
|
|
|
"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
baz:
|
|
|
|
echo root
|
|
|
|
",
|
|
|
|
)
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["baz"])
|
2022-10-20 05:00:09 +03:00
|
|
|
.current_dir("a/b")
|
2023-01-14 00:36:52 +03:00
|
|
|
.stderr(
|
2022-10-20 05:00:09 +03:00
|
|
|
"
|
|
|
|
error: Justfile does not contain recipe `baz`.
|
|
|
|
Did you mean `bar`?
|
|
|
|
",
|
2023-01-14 00:36:52 +03:00
|
|
|
)
|
2022-10-20 05:00:09 +03:00
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.run();
|
|
|
|
}
|
2024-08-29 01:10:40 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn works_with_modules() {
|
|
|
|
Test::new()
|
|
|
|
.write("bar/justfile", "set fallback := true")
|
|
|
|
.write("foo.just", "baz:\n @echo BAZ")
|
|
|
|
.justfile("mod foo")
|
|
|
|
.args(["foo::baz"])
|
|
|
|
.current_dir("bar")
|
|
|
|
.stdout("BAZ\n")
|
|
|
|
.run();
|
|
|
|
}
|