Skip to content

Commit

Permalink
Test that every expr can be scanned
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 2, 2024
1 parent 0132c44 commit 8039cb3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/test_precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use std::fs;
use std::path::Path;
use std::process;
use std::sync::atomic::{AtomicUsize, Ordering};
use syn::parse::Parser as _;

#[macro_use]
mod macros;
Expand All @@ -57,7 +58,6 @@ mod common;
mod repo;

#[path = "../src/scan_expr.rs"]
#[allow(dead_code)]
mod scan_expr;

#[test]
Expand Down Expand Up @@ -119,7 +119,8 @@ fn test_expressions(path: &Path, edition: Edition, exprs: Vec<syn::Expr>) -> (us

rustc_span::create_session_if_not_set_then(edition, |_| {
for expr in exprs {
let source_code = expr.to_token_stream().to_string();
let expr_tokens = expr.to_token_stream();
let source_code = expr_tokens.to_string();
let librustc_ast = if let Some(e) = librustc_parse_and_rewrite(&source_code) {
e
} else {
Expand Down Expand Up @@ -177,6 +178,16 @@ fn test_expressions(path: &Path, edition: Edition, exprs: Vec<syn::Expr>) -> (us
continue;
}

if scan_expr::scan_expr.parse2(expr_tokens).is_err() {
failed += 1;
errorf!(
"\nFAIL {} - failed to scan expr\n{}\n",
path.display(),
source_code,
);
continue;
}

passed += 1;
}
});
Expand Down

0 comments on commit 8039cb3

Please sign in to comment.