From da97f8d7ddf7b06885f6ee101b4cced4f8f85733 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 5 Apr 2021 21:17:53 -0700 Subject: [PATCH] Allow evaluating justfiles with no recipes (#794) --- src/justfile.rs | 34 +++++++++++++++++----------------- tests/evaluate.rs | 29 +++++++++++++++++++++++++++++ tests/lib.rs | 1 + tests/misc.rs | 19 ------------------- 4 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 tests/evaluate.rs diff --git a/src/justfile.rs b/src/justfile.rs index 7255c67..36c4472 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -61,23 +61,6 @@ impl<'src> Justfile<'src> { overrides: &'run BTreeMap, arguments: &'run [String], ) -> RunResult<'run, ()> { - let argvec: Vec<&str> = if !arguments.is_empty() { - arguments.iter().map(String::as_str).collect() - } else if let Some(recipe) = self.first() { - let min_arguments = recipe.min_arguments(); - if min_arguments > 0 { - return Err(RuntimeError::DefaultRecipeRequiresArguments { - recipe: recipe.name.lexeme(), - min_arguments, - }); - } - vec![recipe.name()] - } else { - return Err(RuntimeError::NoRecipes); - }; - - let arguments = argvec.as_slice(); - let unknown_overrides = overrides .keys() .filter(|name| !self.assignments.contains_key(name.as_str())) @@ -142,6 +125,23 @@ impl<'src> Justfile<'src> { return Ok(()); } + let argvec: Vec<&str> = if !arguments.is_empty() { + arguments.iter().map(String::as_str).collect() + } else if let Some(recipe) = self.first() { + let min_arguments = recipe.min_arguments(); + if min_arguments > 0 { + return Err(RuntimeError::DefaultRecipeRequiresArguments { + recipe: recipe.name.lexeme(), + min_arguments, + }); + } + vec![recipe.name()] + } else { + return Err(RuntimeError::NoRecipes); + }; + + let arguments = argvec.as_slice(); + let mut missing = vec![]; let mut grouped = vec![]; let mut rest = arguments; diff --git a/tests/evaluate.rs b/tests/evaluate.rs new file mode 100644 index 0000000..4f11d77 --- /dev/null +++ b/tests/evaluate.rs @@ -0,0 +1,29 @@ +test! { + name: evaluate, + justfile: r#" +foo := "a\t" +hello := "c" +bar := "b\t" +ab := foo + bar + hello + +wut: + touch /this/is/not/a/file +"#, + args: ("--evaluate"), + stdout: r#"ab := "a b c" +bar := "b " +foo := "a " +hello := "c" +"#, +} + +test! { + name: evaluate_empty, + justfile: " + a := 'foo' + ", + args: ("--evaluate"), + stdout: r#" + a := "foo" + "#, +} diff --git a/tests/lib.rs b/tests/lib.rs index ef90678..2ec5a2f 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -10,6 +10,7 @@ mod delimiters; mod dotenv; mod edit; mod error_messages; +mod evaluate; mod examples; mod export; mod init; diff --git a/tests/misc.rs b/tests/misc.rs index 69e4b1c..55c52ba 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -569,25 +569,6 @@ echo `echo command interpolation` ", } -test! { - name: evaluate, - justfile: r#" -foo := "a\t" -hello := "c" -bar := "b\t" -ab := foo + bar + hello - -wut: - touch /this/is/not/a/file -"#, - args: ("--evaluate"), - stdout: r#"ab := "a b c" -bar := "b " -foo := "a " -hello := "c" -"#, -} - test! { name: line_error_spacing, justfile: r#"