diff --git a/src/justfile.rs b/src/justfile.rs index ce0ce9f..718f2fd 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -284,6 +284,15 @@ impl<'src> Justfile<'src> { search: &Search, ran: &mut BTreeSet>, ) -> RunResult<'src, ()> { + let mut invocation = vec![recipe.name().to_owned()]; + for argument in arguments { + invocation.push((*argument).to_string()); + } + + if ran.contains(&invocation) { + return Ok(()); + } + let (outer, positional) = Evaluator::evaluate_parameters( context.config, dotenv, @@ -300,20 +309,19 @@ impl<'src> Justfile<'src> { Evaluator::recipe_evaluator(context.config, dotenv, &scope, context.settings, search); for Dependency { recipe, arguments } in recipe.dependencies.iter().take(recipe.priors) { - let mut invocation = vec![recipe.name().to_owned()]; + let arguments = arguments + .iter() + .map(|argument| evaluator.evaluate_expression(argument)) + .collect::>>()?; - for argument in arguments { - invocation.push(evaluator.evaluate_expression(argument)?); - } - - if !ran.contains(&invocation) { - let arguments = invocation - .iter() - .skip(1) - .map(String::as_ref) - .collect::>(); - self.run_recipe(context, recipe, &arguments, dotenv, search, ran)?; - } + self.run_recipe( + context, + recipe, + &arguments.iter().map(String::as_ref).collect::>(), + dotenv, + search, + ran, + )?; } recipe.run(context, dotenv, scope.child(), search, &positional)?; @@ -339,11 +347,6 @@ impl<'src> Justfile<'src> { } } - let mut invocation = vec![recipe.name().to_owned()]; - for argument in arguments { - invocation.push((*argument).to_string()); - } - ran.insert(invocation); Ok(()) } diff --git a/tests/lib.rs b/tests/lib.rs index 798b045..04ca439 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -33,6 +33,7 @@ mod quiet; mod quote; mod readme; mod regexes; +mod run; mod search; mod shebang; mod shell; diff --git a/tests/run.rs b/tests/run.rs new file mode 100644 index 0000000..2d7d7d3 --- /dev/null +++ b/tests/run.rs @@ -0,0 +1,19 @@ +use crate::common::*; + +#[test] +fn dont_run_duplicate_recipes() { + Test::new() + .justfile( + " + foo: + # foo + ", + ) + .args(&["foo", "foo"]) + .stderr( + " + # foo + ", + ) + .run(); +}