Skip to content

Improve testing error locations #7455

@asterite

Description

@asterite

Right now in the compiler's frontend tests we just check that expected errors happen. However, we don't check where they happen.

One way to do this would be in a way similar to how it's done in parser tests:

#[test]
fn errors_on_return_statement() {
// This shouldn't be parsed as a call
let src = "
return 1
^^^^^^^^
";
let (src, span) = get_source_with_error_span(src);
let mut parser = Parser::for_str(&src);
let statement = parser.parse_statement_or_error();
assert!(matches!(statement.kind, StatementKind::Error));
let reason = get_single_error_reason(&parser.errors, span);
assert!(matches!(reason, ParserErrorReason::EarlyReturn));
}

That is, allow squiggles bellow a line, pre-process that input and extract the span where the error would happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions