Add serve snapshot test for empty project

This commit is contained in:
Lucien Greathouse
2019-09-03 17:56:23 -07:00
parent d5c816f24d
commit ea765eb929
10 changed files with 176 additions and 213 deletions

View File

@@ -1,4 +1,10 @@
use std::path::{Path, PathBuf};
use std::{
fs, io,
path::{Path, PathBuf},
process::Child,
};
use walkdir::WalkDir;
pub fn get_rojo_path() -> PathBuf {
let working_dir = get_working_dir_path();
@@ -29,3 +35,37 @@ pub fn get_serve_tests_path() -> PathBuf {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
manifest_dir.join("serve-tests")
}
/// Recursively walk a directory and copy each item to the equivalent location
/// in another directory. Equivalent to `cp -r src/* dst`
pub fn copy_recursive(from: &Path, to: &Path) -> io::Result<()> {
for entry in WalkDir::new(from) {
let entry = entry?;
let path = entry.path();
let new_path = to.join(path.strip_prefix(from).unwrap());
let file_type = entry.file_type();
if file_type.is_dir() {
match fs::create_dir(new_path) {
Ok(_) => {}
Err(err) => match err.kind() {
io::ErrorKind::AlreadyExists => {}
_ => panic!(err),
},
}
} else {
fs::copy(path, new_path)?;
}
}
Ok(())
}
pub struct KillOnDrop(pub Child);
impl Drop for KillOnDrop {
fn drop(&mut self) {
let _ = self.0.kill();
}
}