From 86dbed744598aeeac080970cca42c1cb74a1b9a0 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 25 Dec 2023 01:14:17 +0800 Subject: [PATCH] Display a descriptive error for `!include` directives (#1779) --- src/compile_error.rs | 4 ++++ src/compile_error_kind.rs | 1 + src/lexer.rs | 1 + tests/imports.rs | 17 +++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/src/compile_error.rs b/src/compile_error.rs index 7a0d6f9..3d3718b 100644 --- a/src/compile_error.rs +++ b/src/compile_error.rs @@ -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 \ diff --git a/src/compile_error_kind.rs b/src/compile_error_kind.rs index acd8b2f..0be5555 100644 --- a/src/compile_error_kind.rs +++ b/src/compile_error_kind.rs @@ -58,6 +58,7 @@ pub(crate) enum CompileErrorKind<'src> { found: usize, expected: Range, }, + Include, InconsistentLeadingWhitespace { expected: &'src str, found: &'src str, diff --git a/src/lexer.rs b/src/lexer.rs index 37c8f7d..6d380ae 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -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), diff --git a/tests/imports.rs b/tests/imports.rs index 38dfe98..2c2c913 100644 --- a/tests/imports.rs +++ b/tests/imports.rs @@ -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(); +}