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-2.0.119 / tests / test_unparenthesize.rs

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