Skip to content

Commit 5778608

Browse files
authored
Merge branch 'master' into bug/linewise-error-line-number-wrong-after-multi-line-interpolation
2 parents 3fd2fe6 + 8159bb6 commit 5778608

9 files changed

Lines changed: 130 additions & 14 deletions

File tree

‎src/compiler.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Compiler {
159159
let mut candidates = Vec::new();
160160

161161
if let Some(path) = path {
162-
let full = parent.join(path);
162+
let full = parent.join(path).clean();
163163

164164
if filesystem::is_file(&full)? {
165165
return Ok(Some(full));
@@ -240,7 +240,12 @@ impl Compiler {
240240
Err(Error::AmbiguousModuleFile {
241241
found: found
242242
.into_iter()
243-
.map(|found| found.strip_prefix(parent).unwrap().into())
243+
.map(|found| {
244+
found
245+
.strip_prefix(parent)
246+
.map(PathBuf::from)
247+
.unwrap_or(found)
248+
})
244249
.collect(),
245250
module,
246251
})

‎src/justfile.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'src> Justfile<'src> {
125125
} else {
126126
&search.working_directory
127127
};
128-
load_dotenv(config, &self.settings, working_directory)?
128+
load_dotenv(config, self, working_directory)?
129129
} else {
130130
BTreeMap::new()
131131
};

‎src/load_dotenv.rs‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@ use super::*;
22

33
pub(crate) fn load_dotenv(
44
config: &Config,
5-
settings: &Settings,
5+
justfile: &Justfile,
66
working_directory: &Path,
77
) -> RunResult<'static, BTreeMap<String, String>> {
8-
let commands = if config.dotenv_command.is_empty() {
8+
let settings = &justfile.settings;
9+
10+
let commands = if config.dotenv_command.is_empty() || justfile.is_submodule() {
911
settings.dotenv_command.elements()
1012
} else {
1113
&config.dotenv_command
1214
};
1315

1416
if !commands.is_empty() {
1517
let mut dotenv = BTreeMap::new();
16-
for command in commands {
17-
dotenv.extend(load_from_command(
18-
command,
19-
config,
20-
settings,
21-
working_directory,
22-
)?);
18+
19+
if !config.dry_run {
20+
for command in commands {
21+
dotenv.extend(load_from_command(
22+
command,
23+
config,
24+
settings,
25+
working_directory,
26+
)?);
27+
}
2328
}
29+
2430
return Ok(dotenv);
2531
}
2632

‎src/parameter.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ impl<'src> Parameter<'src> {
2525
}
2626

2727
pub(crate) fn is_required(&self) -> bool {
28-
self.default.is_none() && self.kind != ParameterKind::Star && !self.flag
28+
self.default.is_none()
29+
&& !self.flag
30+
&& (self.kind != ParameterKind::Star || self.min.is_some_and(|min| min > 0))
2931
}
3032

3133
pub(crate) fn check_value_count(

‎src/subcommand.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,7 @@ impl Subcommand {
10101010
pub(crate) fn takes_arguments(&self) -> bool {
10111011
match self {
10121012
Self::Changelog
1013+
| Self::Completions { .. }
10131014
| Self::Dump { .. }
10141015
| Self::Edit
10151016
| Self::Format
@@ -1021,7 +1022,6 @@ impl Subcommand {
10211022
Self::Choose { .. }
10221023
| Self::Clean { .. }
10231024
| Self::Command { .. }
1024-
| Self::Completions { .. }
10251025
| Self::Evaluate { .. }
10261026
| Self::List { .. }
10271027
| Self::Request { .. }

‎tests/arg_attribute.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,25 @@ fn star_variadic_without_arguments_below_min_is_an_error() {
912912
.failure();
913913
}
914914

915+
#[test]
916+
fn star_variadic_with_min_cannot_be_default_recipe() {
917+
Test::new()
918+
.justfile(
919+
"
920+
set lists
921+
922+
[arg('bar', min='1')]
923+
foo *bar:
924+
@echo {{ bar }}
925+
",
926+
)
927+
.unstable()
928+
.stderr(
929+
"error: recipe `foo` cannot be used as default recipe since it requires at least 1 argument\n",
930+
)
931+
.failure();
932+
}
933+
915934
#[test]
916935
fn default_satisfying_min_is_accepted() {
917936
Test::new()

‎tests/completions.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,16 @@ fn usage_recipes() {
427427
.success();
428428
}
429429

430+
#[test]
431+
fn rejects_unexpected_arguments() {
432+
Test::new()
433+
.justfile("")
434+
.args(["--completions", "bash", "extra"])
435+
.stdout_regex(".*")
436+
.stderr("error: `--completions` used with unexpected argument: `extra`\n")
437+
.failure();
438+
}
439+
430440
#[test]
431441
fn recipes_with_invalid_config() {
432442
Test::new()

‎tests/dotenv.rs‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,22 @@ fn command_composes_with_dotenv_override_setting() {
927927
.success();
928928
}
929929

930+
#[test]
931+
fn command_is_not_executed_in_dry_run() {
932+
Test::new()
933+
.justfile(
934+
"
935+
set dotenv-command := 'exit 1'
936+
937+
foo:
938+
echo bar
939+
",
940+
)
941+
.arg("--dry-run")
942+
.stderr("echo bar\n")
943+
.success();
944+
}
945+
930946
#[test]
931947
fn dotenv_command_exit_code_is_propagated() {
932948
Test::new()
@@ -940,3 +956,29 @@ fn dotenv_command_exit_code_is_propagated() {
940956
.stderr("error: dotenv command `exit 42` failed: process exited with status code 42\n")
941957
.status(42);
942958
}
959+
960+
#[test]
961+
fn command_only_runs_in_root_module() {
962+
Test::new()
963+
.write(
964+
"foo.just",
965+
"set dotenv-command := 'echo KEY=submodule'\nbaz:\n @echo $KEY\n",
966+
)
967+
.write("bar.env", "KEY=value\n")
968+
.justfile(
969+
"
970+
mod foo
971+
972+
bar:
973+
@echo $KEY
974+
",
975+
)
976+
.args(["--dotenv-command", "echo KEY=root", "bar", "foo::baz"])
977+
.stdout(
978+
"
979+
root
980+
submodule
981+
",
982+
)
983+
.success();
984+
}

‎tests/modules.rs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ fn circular_module_imports_are_detected() {
335335
.failure();
336336
}
337337

338+
#[test]
339+
fn circular_module_through_path_with_parent_is_detected() {
340+
Test::new()
341+
.write("sub/foo.just", "mod bar '../justfile'")
342+
.justfile("mod foo 'sub/foo.just'")
343+
.arg("--list")
344+
.stderr_regex(path_for_regex(
345+
"error: import `.*/justfile` in `.*/sub/foo.just` is circular\n",
346+
))
347+
.failure();
348+
}
349+
338350
#[test]
339351
fn modules_use_module_settings() {
340352
Test::new()
@@ -638,6 +650,26 @@ fn modules_require_unambiguous_file() {
638650
.failure();
639651
}
640652

653+
#[test]
654+
fn modules_outside_justfile_directory_require_unambiguous_file() {
655+
let test = Test::new()
656+
.create_dir("root")
657+
.write("external/justfile", "")
658+
.write("external/.justfile", "");
659+
660+
let external = test.tempdir.path().join("external");
661+
662+
test
663+
.write(
664+
"root/justfile",
665+
&format!("mod foo '{}'\n", external.display()),
666+
)
667+
.current_dir("root")
668+
.arg("--summary")
669+
.stderr_regex("error: found multiple source files for module `foo`:.*")
670+
.failure();
671+
}
672+
641673
#[test]
642674
fn missing_module_file_error() {
643675
Test::new()

0 commit comments

Comments
 (0)