Skip to content

Commit

Permalink
Allow shell expanded strings in mod and import paths (#2059)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored May 19, 2024
1 parent a343f5c commit 198b37c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ impl<'run, 'src> Parser<'run, 'src> {
}
Some(Keyword::Import)
if self.next_are(&[Identifier, StringToken])
|| self.next_are(&[Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, QuestionMark]) =>
{
self.presume_keyword(Keyword::Import)?;
Expand All @@ -353,6 +354,7 @@ impl<'run, 'src> Parser<'run, 'src> {
}
Some(Keyword::Mod)
if self.next_are(&[Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, Identifier, Identifier, StringToken])
|| self.next_are(&[Identifier, Identifier, Eof])
|| self.next_are(&[Identifier, Identifier, Eol])
|| self.next_are(&[Identifier, QuestionMark]) =>
Expand All @@ -363,7 +365,8 @@ impl<'run, 'src> Parser<'run, 'src> {

let name = self.parse_name()?;

let relative = if self.next_is(StringToken) {
let relative = if self.next_is(StringToken) || self.next_are(&[Identifier, StringToken])
{
Some(self.parse_string_literal()?)
} else {
None
Expand Down
32 changes: 32 additions & 0 deletions tests/shell_expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,35 @@ fn shell_expanded_strings_can_be_used_in_settings() {
.stdout("dotenv-value\n")
.run();
}

#[test]
fn shell_expanded_strings_can_be_used_in_import_paths() {
Test::new()
.justfile(
"
import x'$JUST_TEST_VARIABLE'
foo: bar
",
)
.write("import.just", "@bar:\n echo BAR")
.env("JUST_TEST_VARIABLE", "import.just")
.stdout("BAR\n")
.run();
}

#[test]
fn shell_expanded_strings_can_be_used_in_mod_paths() {
Test::new()
.justfile(
"
mod foo x'$JUST_TEST_VARIABLE'
",
)
.write("mod.just", "@bar:\n echo BAR")
.env("JUST_TEST_VARIABLE", "mod.just")
.args(["--unstable", "foo", "bar"])
.stdout("BAR\n")
.test_round_trip(false)
.run();
}

0 comments on commit 198b37c

Please sign in to comment.