trybuild 1.0.36

Test harness for ui tests of compiler diagnostics
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::env;
use std::fs;
use std::io;
use std::path::Path;

fn main() -> io::Result<()> {
    let out_dir = env::var_os("OUT_DIR").unwrap();
    let target = env::var("TARGET").ok();
    let path = Path::new(&out_dir).join("target.rs");
    let value = match target {
        Some(target) => format!("Some({:?})", target),
        None => "None".to_owned(),
    };
    let content = format!("const TARGET: Option<&'static str> = {};", value);
    fs::write(path, content)
}