Skip to content

Commit ce691ff

Browse files
authored
Export variables to submodules (#2816)
1 parent 015bcda commit ce691ff

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/justfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'src> Justfile<'src> {
9191
config,
9292
dotenv,
9393
&BTreeMap::new(),
94-
root,
94+
scope,
9595
scopes,
9696
search,
9797
)?;

tests/modules.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,3 +1018,54 @@ fn overrides_work_when_submodule_is_present() {
10181018
.stdout("b\n")
10191019
.run();
10201020
}
1021+
1022+
#[test]
1023+
fn exported_variables_are_available_in_submodules() {
1024+
Test::new()
1025+
.write("foo.just", "bar:\n @echo $x")
1026+
.justfile(
1027+
"
1028+
mod foo
1029+
1030+
export x := 'a'
1031+
",
1032+
)
1033+
.test_round_trip(false)
1034+
.arg("foo::bar")
1035+
.stdout("a\n")
1036+
.run();
1037+
}
1038+
1039+
#[test]
1040+
fn exported_variables_can_be_unexported_in_submodules() {
1041+
Test::new()
1042+
.write("foo.just", "unexport x\nbar:\n @echo ${x:-default}")
1043+
.justfile(
1044+
"
1045+
mod foo
1046+
1047+
export x := 'a'
1048+
",
1049+
)
1050+
.test_round_trip(false)
1051+
.arg("foo::bar")
1052+
.stdout("default\n")
1053+
.run();
1054+
}
1055+
1056+
#[test]
1057+
fn exported_variables_can_be_overridden_in_submodules() {
1058+
Test::new()
1059+
.write("foo.just", "export x := 'b'\nbar:\n @echo $x")
1060+
.justfile(
1061+
"
1062+
mod foo
1063+
1064+
export x := 'a'
1065+
",
1066+
)
1067+
.test_round_trip(false)
1068+
.arg("foo::bar")
1069+
.stdout("b\n")
1070+
.run();
1071+
}

0 commit comments

Comments
 (0)