Factor out test utilities in preparation for serve tests

This commit is contained in:
Lucien Greathouse
2019-09-03 10:25:48 -07:00
parent 2fb2342fd4
commit 6747d97d60
6 changed files with 186 additions and 80 deletions

View File

@@ -9,6 +9,7 @@ publish = false
insta = "0.10.0"
paste = "0.1.5"
tempfile = "3.1.0"
reqwest = "0.9.20"
# We execute Rojo via std::process::Command, so depend on it so it's built!
rojo = { path = ".." }

View File

@@ -1,8 +1,10 @@
use std::{fs, path::Path, process::Command};
use std::{fs, process::Command};
use insta::assert_snapshot_matches;
use tempfile::tempdir;
use crate::util::{get_build_tests_path, get_rojo_path, get_working_dir_path};
macro_rules! gen_build_tests {
( $($test_name: ident,)* ) => {
$(
@@ -49,19 +51,15 @@ fn build_rbxmx_ref() {
}
fn run_build_test(test_name: &str) {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let build_test_path = manifest_dir.join("build-tests");
let working_dir = manifest_dir.parent().unwrap();
let build_test_path = get_build_tests_path();
let working_dir = get_working_dir_path();
let output_dir = tempdir().expect("couldn't create temporary directory");
let input_path = build_test_path.join(test_name);
let output_path = output_dir.path().join(format!("{}.rbxmx", test_name));
let mut exe_path = working_dir.join("target/debug/rojo");
if cfg!(windows) {
exe_path.set_extension("exe");
}
let exe_path = get_rojo_path();
let status = Command::new(exe_path)
.args(&[

View File

@@ -1,2 +1,7 @@
mod util;
#[cfg(test)]
mod build_test;
#[cfg(test)]
mod serve_test;

View File

@@ -0,0 +1 @@
use std::path::Path;

28
rojo-test/src/util.rs Normal file
View File

@@ -0,0 +1,28 @@
use std::path::{Path, PathBuf};
pub fn get_rojo_path() -> PathBuf {
let working_dir = get_working_dir_path();
let mut exe_path = working_dir.join("target/debug/rojo");
if cfg!(windows) {
exe_path.set_extension("exe");
}
exe_path
}
pub fn get_working_dir_path() -> PathBuf {
let mut manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
assert!(manifest_dir.pop(), "Manifest directory did not have a parent");
manifest_dir
}
pub fn get_build_tests_path() -> PathBuf {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
manifest_dir.join("build-tests")
}
pub fn get_serve_tests_path() -> PathBuf {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
manifest_dir.join("serve-tests")
}