fn write_mod_files()

in yaml_test_runner/src/generator.rs [477:520]


fn write_mod_files(generated_dir: &PathBuf, toplevel: bool) -> Result<(), failure::Error> {
    if !generated_dir.exists() {
        fs::create_dir(generated_dir)?;
    }

    let paths = fs::read_dir(generated_dir)?;
    let mut mods = vec![];
    for path in paths {
        if let Ok(entry) = path {
            let path = entry.path();
            let name = path.file_stem().unwrap().to_string_lossy();

            if name != "mod" {
                mods.push(format!(
                    "pub mod {};",
                    path.file_stem().unwrap().to_string_lossy()
                ));
            }

            if path.is_dir() && !(toplevel && name == "common") {
                write_mod_files(&entry.path(), false)?;
            }
        }
    }

    // Make sure we have a stable output
    mods.sort();

    if toplevel {
        // The "common" module must appear first so that its macros are parsed before the
        // compiler visits other modules, otherwise we'll have "macro not found" errors.
        mods.retain(|name| name != "pub mod common;");
        mods.insert(0, "#[macro_use]".into());
        mods.insert(1, "pub mod common;".into());
        mods.insert(2, "".into());
    }

    let mut path = generated_dir.clone();
    path.push("mod.rs");
    let mut file = File::create(&path)?;
    let generated_mods: String = mods.join("\n");
    file.write_all(generated_mods.as_bytes())?;
    Ok(())
}