|
| 1 | +//@ run-pass |
| 2 | +//! Test that users are able to use rustc_public to consume formatting macros. |
| 3 | +//@ ignore-stage1 |
| 4 | +//@ ignore-cross-compile |
| 5 | +//@ ignore-remote |
| 6 | +//@ edition: 2021 |
| 7 | + |
| 8 | +#![feature(rustc_private)] |
| 9 | + |
| 10 | +extern crate rustc_middle; |
| 11 | + |
| 12 | +extern crate rustc_driver; |
| 13 | +extern crate rustc_interface; |
| 14 | +extern crate rustc_public; |
| 15 | +use std::io::Write; |
| 16 | +use std::ops::ControlFlow; |
| 17 | +use rustc_public::run; |
| 18 | + |
| 19 | +const CRATE_NAME: &str = "fmt_macro"; |
| 20 | + |
| 21 | +/// Test if we can pass the compilation. |
| 22 | +fn test_fmt_macro() -> ControlFlow<()> { |
| 23 | + let entry_fn = rustc_public::entry_fn().unwrap().body().unwrap(); |
| 24 | + for bb in &entry_fn.blocks { |
| 25 | + for stmt in &bb.statements { |
| 26 | + let _ = stmt; |
| 27 | + } |
| 28 | + } |
| 29 | + ControlFlow::Continue(()) |
| 30 | +} |
| 31 | + |
| 32 | +/// This test will generate and analyze a dummy crate using the stable mir. |
| 33 | +/// For that, it will first write the dummy crate into a file. |
| 34 | +/// Then it will create a `RustcPublic` using custom arguments and then |
| 35 | +/// it will run the compiler. |
| 36 | +fn main() { |
| 37 | + let path = "fmt_macro_input.rs"; |
| 38 | + generate_input(&path).unwrap(); |
| 39 | + let args = &[ |
| 40 | + "rustc".to_string(), |
| 41 | + "-Cpanic=abort".to_string(), |
| 42 | + "--crate-name".to_string(), |
| 43 | + CRATE_NAME.to_string(), |
| 44 | + path.to_string(), |
| 45 | + ]; |
| 46 | + run!(args, test_fmt_macro).unwrap(); |
| 47 | +} |
| 48 | + |
| 49 | +fn generate_input(path: &str) -> std::io::Result<()> { |
| 50 | + let mut file = std::fs::File::create(path)?; |
| 51 | + write!( |
| 52 | + file, |
| 53 | + r#" |
| 54 | + fn main() {{ |
| 55 | + println!("hello world!"); |
| 56 | + }} |
| 57 | + "# |
| 58 | + )?; |
| 59 | + Ok(()) |
| 60 | +} |
0 commit comments