Display a descriptive error for !include
directives (#1779)
This commit is contained in:
parent
f47c175bc5
commit
86dbed7445
@ -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 \
|
||||
|
@ -58,6 +58,7 @@ pub(crate) enum CompileErrorKind<'src> {
|
||||
found: usize,
|
||||
expected: Range<usize>,
|
||||
},
|
||||
Include,
|
||||
InconsistentLeadingWhitespace {
|
||||
expected: &'src str,
|
||||
found: &'src str,
|
||||
|
@ -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),
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user