From 9f2568c461173a1ffe05152670c60bb258087260 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 2 Nov 2016 22:01:38 -0700 Subject: [PATCH] Fix tab-indented lines in shebang recipes Fixed a precedence bug in the recipe parser where tab-indented lines in a shebang recipe would trigger an ExtraLeadingWhitespace error. --- src/lib.rs | 5 +++-- src/unit.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 97617de..58f710b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -988,7 +988,7 @@ impl<'a> Display for RunError<'a> { match *self { RunError::UnknownRecipes{ref recipes} => { if recipes.len() == 1 { - try!(write!(f, "Justfile does not contain recipe: {}", recipes[0])); + try!(write!(f, "Justfile does not contain recipe `{}`", recipes[0])); } else { try!(write!(f, "Justfile does not contain recipes: {}", recipes.join(" "))); }; @@ -1528,7 +1528,8 @@ impl<'a> Parser<'a> { if token.lexeme.starts_with("#!") { shebang = true; } - } else if !shebang && token.lexeme.starts_with(' ') || token.lexeme.starts_with('\t') { + } else if !shebang && (token.lexeme.starts_with(' ') || + token.lexeme.starts_with('\t')) { return Err(token.error(ErrorKind::ExtraLeadingWhitespace)); } } diff --git a/src/unit.rs b/src/unit.rs index ac02648..9313e82 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -302,6 +302,25 @@ y: z:"); } +#[test] +fn parse_shebang() { + parse_summary(" +practicum = 'hello' +install: +\t#!/bin/sh +\tif [[ -f {{practicum}} ]]; then +\t\treturn +\tfi +", "practicum = \"hello\" + +install: + #!/bin/sh + if [[ -f {{practicum}} ]]; then + \treturn + fi" + ); +} + #[test] fn parse_assignments() { parse_summary(