view build.rs @ 96:20c1c9d7803d default tip

Fix dump failure in strings containing backquotes and double quotes.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 28 Jun 2016 01:40:55 +0100
parents 6569eea3db23
children
line wrap: on
line source

use std::env;
use std::path::Path;
use std::io::prelude::*;
use std::fs::{File, read_dir};

fn gen_parse_file_tests(out_dir: String) {
    let path = Path::new(&out_dir).join("generated_parse_tests.rs");
    let mut f = File::create(&path).unwrap();

    for file in read_dir("tests/test_parse_files").unwrap() {
        let path = file.unwrap().path();
        if path.extension().unwrap() != "py" {
            continue;
        }
        let test_name = path.file_stem().unwrap().to_str().unwrap();
        let _ = f.write_all(format!("#[test]
fn {}() {{
    test_parse_file(\"{}\");
}}\n", test_name, path.to_str().unwrap()).as_bytes()).unwrap();
    }
}

fn main() {
    let out_dir = env::var("OUT_DIR").unwrap();
    gen_parse_file_tests(out_dir);
}