2023-01-12 19:25:28 -08:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn include_fails_without_unstable() {
|
|
|
|
Test::new()
|
|
|
|
.justfile("!include ./include.justfile")
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.stderr("error: The !include directive is currently unstable. Invoke `just` with the `--unstable` flag to enable unstable features.\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn include_succeeds_with_unstable() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
"include.justfile": "
|
|
|
|
b:
|
|
|
|
@echo B
|
|
|
|
",
|
|
|
|
})
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
!include ./include.justfile
|
|
|
|
|
|
|
|
a: b
|
|
|
|
@echo A
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.arg("--unstable")
|
|
|
|
.test_round_trip(false)
|
|
|
|
.arg("a")
|
|
|
|
.stdout("B\nA\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn trailing_spaces_after_include_are_ignored() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
2023-11-22 10:27:49 -08:00
|
|
|
"include.justfile": "",
|
2023-01-12 19:25:28 -08:00
|
|
|
})
|
2023-11-22 10:27:49 -08:00
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
!include ./include.justfile\x20
|
|
|
|
a:
|
|
|
|
@echo A
|
|
|
|
",
|
|
|
|
)
|
2023-01-12 19:25:28 -08:00
|
|
|
.arg("--unstable")
|
|
|
|
.test_round_trip(false)
|
|
|
|
.stdout("A\n")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn include_directive_with_no_path() {
|
|
|
|
Test::new()
|
|
|
|
.justfile("!include")
|
|
|
|
.arg("--unstable")
|
|
|
|
.status(EXIT_FAILURE)
|
2023-11-21 11:28:59 -08:00
|
|
|
.stderr(
|
|
|
|
"
|
|
|
|
error: !include directive has no argument
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:1:9
|
2023-11-21 11:28:59 -08:00
|
|
|
|
|
|
|
|
1 | !include
|
|
|
|
| ^
|
|
|
|
",
|
|
|
|
)
|
2023-01-12 19:25:28 -08:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-11-21 11:28:59 -08:00
|
|
|
fn include_after_recipe() {
|
2023-01-12 19:25:28 -08:00
|
|
|
Test::new()
|
2023-11-21 11:28:59 -08:00
|
|
|
.tree(tree! {
|
|
|
|
"include.justfile": "
|
|
|
|
a:
|
|
|
|
@echo A
|
|
|
|
",
|
|
|
|
})
|
2023-01-12 19:25:28 -08:00
|
|
|
.justfile(
|
|
|
|
"
|
2023-11-21 11:28:59 -08:00
|
|
|
b: a
|
2023-01-12 19:25:28 -08:00
|
|
|
!include ./include.justfile
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.arg("--unstable")
|
2023-11-21 11:28:59 -08:00
|
|
|
.test_round_trip(false)
|
|
|
|
.stdout("A\n")
|
2023-01-12 19:25:28 -08:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn circular_include() {
|
|
|
|
Test::new()
|
|
|
|
.justfile("!include a")
|
|
|
|
.tree(tree! {
|
|
|
|
a: "!include b",
|
|
|
|
b: "!include a",
|
|
|
|
})
|
|
|
|
.arg("--unstable")
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.stderr_regex(path_for_regex(
|
|
|
|
"error: Include `.*/a` in `.*/b` is a circular include\n",
|
|
|
|
))
|
|
|
|
.run();
|
|
|
|
}
|
2023-11-22 10:27:49 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn include_recipes_are_not_default() {
|
|
|
|
Test::new()
|
|
|
|
.tree(tree! {
|
|
|
|
"include.justfile": "bar:",
|
|
|
|
})
|
|
|
|
.justfile("!include ./include.justfile")
|
|
|
|
.arg("--unstable")
|
|
|
|
.test_round_trip(false)
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.stderr("error: Justfile contains no default recipe.\n")
|
|
|
|
.run();
|
|
|
|
}
|
2023-11-24 23:15:41 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn listed_recipes_in_includes_are_in_load_order() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
!include ./include.justfile
|
|
|
|
foo:
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.write("include.justfile", "bar:")
|
|
|
|
.args(["--list", "--unstable", "--unsorted"])
|
|
|
|
.test_round_trip(false)
|
|
|
|
.stdout(
|
|
|
|
"
|
|
|
|
Available recipes:
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|