Skip to content

Commit

Permalink
Display a descriptive error for !include directives (#1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Dec 24, 2023
1 parent f47c175 commit 86dbed7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ impl Display for CompileError<'_> {
Count("argument", *found),
expected.display(),
),
Include => write!(
f,
"The `!include` directive has been stabilized as `import`"
),
InconsistentLeadingWhitespace { expected, found } => write!(
f,
"Recipe line has inconsistent leading whitespace. Recipe started with `{}` but found \
Expand Down
1 change: 1 addition & 0 deletions src/compile_error_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub(crate) enum CompileErrorKind<'src> {
found: usize,
expected: Range<usize>,
},
Include,
InconsistentLeadingWhitespace {
expected: &'src str,
found: &'src str,
Expand Down
1 change: 1 addition & 0 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ impl<'src> Lexer<'src> {
fn lex_normal(&mut self, start: char) -> CompileResult<'src, ()> {
match start {
' ' | '\t' => self.lex_whitespace(),
'!' if self.rest().starts_with("!include") => Err(self.error(Include)),
'!' => self.lex_digraph('!', '=', BangEquals),
'#' => self.lex_comment(),
'$' => self.lex_single(Dollar),
Expand Down
17 changes: 17 additions & 0 deletions tests/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,20 @@ fn listed_recipes_in_imports_are_in_load_order() {
)
.run();
}

#[test]
fn include_error() {
Test::new()
.justfile("!include foo")
.status(EXIT_FAILURE)
.stderr(
"
error: The `!include` directive has been stabilized as `import`
--> justfile:1:1
|
1 | !include foo
| ^
",
)
.run();
}

0 comments on commit 86dbed7

Please sign in to comment.