From c907e718aca13ff4a2f3f568ad16f2c05f6b61ea Mon Sep 17 00:00:00 2001 From: Heinz Wiesinger Date: Mon, 29 Jan 2024 16:21:47 +0100 Subject: [PATCH] Add tests for variables in module source paths --- tests/modules.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/modules.rs b/tests/modules.rs index 75aaf7fce9..accb01b2bc 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -668,7 +668,7 @@ fn submodule_shebang_recipes_run_in_submodule_directory() { #[cfg(not(windows))] #[test] -fn module_paths_beginning_with_tilde_are_expanded_to_homdir() { +fn module_paths_beginning_with_tilde_are_expanded_to_homedir() { Test::new() .write("foobar/mod.just", "foo:\n @echo FOOBAR") .justfile( @@ -685,6 +685,47 @@ fn module_paths_beginning_with_tilde_are_expanded_to_homdir() { .run(); } +#[test] +fn module_paths_with_variables_are_expanded() { + Test::new() + .write("foobar/mod.just", "foo:\n @echo FOOBAR") + .justfile( + " + mod foo '$FOO/mod.just' + ", + ) + .test_round_trip(false) + .arg("--unstable") + .arg("foo") + .arg("foo") + .stdout("FOOBAR\n") + .env("FOO", "foobar") + .run(); +} + +#[test] +fn unresolved_variable_in_module_error() { + Test::new() + .justfile( + " + mod foo '$FOO/mod.just' + ", + ) + .test_round_trip(false) + .arg("--unstable") + .status(EXIT_FAILURE) + .stderr( + " + error: Source path for foo contains unresolved variable FOO. + ——▶ justfile:1:5 + │ + 1 │ mod foo '$FOO/mod.just' + │ ^^^ + ", + ) + .run(); +} + #[test] fn module_recipe_list_alignment_ignores_private_recipes() { Test::new()