Display a descriptive error for !include directives (#1779)

This commit is contained in:
Casey Rodarmor 2023-12-25 01:14:17 +08:00 committed by GitHub
parent f47c175bc5
commit 86dbed7445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 0 deletions

View File

@ -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 \

View File

@ -58,6 +58,7 @@ pub(crate) enum CompileErrorKind<'src> {
found: usize,
expected: Range<usize>,
},
Include,
InconsistentLeadingWhitespace {
expected: &'src str,
found: &'src str,

View File

@ -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),

View File

@ -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();
}