interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / syn / tests / test_unparenthesize.rs

71 lines · 2014 bytes Raw Blame History
1#![cfg(not(miri))]
2#![recursion_limit = "1024"]
3#![feature(rustc_private)]
4#![allow(
5 clippy::assert_is_empty,
6 clippy::elidable_lifetime_names,
7 clippy::manual_assert,
8 clippy::match_like_matches_macro,
9 clippy::needless_lifetimes,
10 clippy::uninlined_format_args
11)]
12
13use crate::common::visit::{AsIfPrinted, FlattenParens};
14use quote::ToTokens as _;
15use std::fs;
16use std::panic;
17use std::path::Path;
18use std::sync::atomic::{AtomicUsize, Ordering};
19use syn::visit_mut::VisitMut as _;
20
21#[macro_use]
22mod macros;
23
24mod common;
25mod repo;
26
27#[test]
28fn test_unparenthesize() {
29 repo::rayon_init();
30 repo::clone_rust();
31
32 let failed = AtomicUsize::new(0);
33
34 repo::for_each_rust_file(|path| test(path, &failed));
35
36 let failed = failed.into_inner();
37 if failed > 0 {
38 panic!("{} failures", failed);
39 }
40}
41
42fn test(path: &Path, failed: &AtomicUsize) {
43 let content = fs::read_to_string(path).unwrap();
44
45 match panic::catch_unwind(|| -> syn::Result<()> {
46 let mut before = syn::parse_file(&content)?;
47 FlattenParens::discard_attrs().visit_file_mut(&mut before);
48 let printed = before.to_token_stream();
49 let mut after = syn::parse2::<syn::File>(printed.clone())?;
50 FlattenParens::discard_attrs().visit_file_mut(&mut after);
51 // Normalize features that we expect Syn not to print.
52 AsIfPrinted.visit_file_mut(&mut before);
53 if before != after {
54 errorf!("=== {}\n", path.display());
55 if failed.fetch_add(1, Ordering::Relaxed) == 0 {
56 errorf!("BEFORE:\n{:#?}\nAFTER:\n{:#?}\n", before, after);
57 }
58 }
59 Ok(())
60 }) {
61 Err(_) => {
62 errorf!("=== {}: syn panic\n", path.display());
63 failed.fetch_add(1, Ordering::Relaxed);
64 }
65 Ok(Err(msg)) => {
66 errorf!("=== {}: syn failed to parse\n{:?}\n", path.display(), msg);
67 failed.fetch_add(1, Ordering::Relaxed);
68 }
69 Ok(Ok(())) => {}
70 }
71}