Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve testing error locations #7455

Closed
asterite opened this issue Feb 20, 2025 · 0 comments · Fixed by #7526
Closed

Improve testing error locations #7455

asterite opened this issue Feb 20, 2025 · 0 comments · Fixed by #7526

Comments

@asterite
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant