Allow shell expanded strings in mod and import paths (#2059)

This commit is contained in:
Casey Rodarmor 2024-05-19 16:47:25 -07:00 committed by GitHub
parent a343f5c80c
commit 198b37c020
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View File

@ -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)?;
@ -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]) =>
@ -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

View File

@ -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();
}