use std::env;
use std::fs;
use std::io;
use std::path::Path;
use std::process::exit;
use wdl_doc::document_workspace;
fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
fs::create_dir_all(&dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
if ty.is_dir() {
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
} else {
fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
}
}
Ok(())
}
#[tokio::main]
async fn main() {
#[cfg(not(windows))]
let test_dir = Path::new("tests/codebase");
#[cfg(not(windows))]
let docs_dir = Path::new("tests/output_docs");
#[cfg(windows)]
let test_dir = Path::new("tests\\codebase");
#[cfg(windows)]
let docs_dir = Path::new("tests\\output_docs");
if test_dir.join("docs").exists() {
fs::remove_dir_all(test_dir.join("docs")).unwrap();
}
match document_workspace(test_dir.to_path_buf(), None::<&str>, true).await {
Ok(_) => {
println!("Successfully generated docs");
}
Err(e) => {
eprintln!("Failed to generate docs: {}", e);
exit(1);
}
}
if env::var("BLESS").is_ok() {
if docs_dir.exists() {
fs::remove_dir_all(docs_dir).unwrap();
}
fs::create_dir_all(docs_dir).unwrap();
copy_dir_all(test_dir.join("docs"), docs_dir).unwrap();
println!("Blessed docs");
exit(0);
}
let mut success = true;
for entry in fs::read_dir(docs_dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
let expected_path = test_dir
.join("docs")
.join(path.strip_prefix(docs_dir).unwrap());
if !expected_path.exists() {
eprintln!("Expected path does not exist: {}", expected_path.display());
success = false;
}
}
if success {
println!("Docs are as expected");
exit(0);
} else {
exit(1);
}
}