forked from rojo-rbx/rojo
Change rojo-test to be macro-based
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1541,6 +1541,7 @@ name = "rojo-test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"insta 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
||||
@@ -7,4 +7,5 @@ publish = false
|
||||
|
||||
[dependencies]
|
||||
insta = "0.10.0"
|
||||
paste = "0.1.5"
|
||||
tempfile = "3.1.0"
|
||||
53
rojo-test/src/build_test.rs
Normal file
53
rojo-test/src/build_test.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use std::{
|
||||
fs,
|
||||
path::Path,
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use insta::assert_snapshot_matches;
|
||||
use tempfile::tempdir;
|
||||
|
||||
macro_rules! gen_build_tests {
|
||||
( $($test_name: ident,)* ) => {
|
||||
$(
|
||||
paste::item! {
|
||||
#[test]
|
||||
fn [<build_ $test_name>]() {
|
||||
run_build_test(stringify!($test_name));
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
gen_build_tests! {
|
||||
gitkeep,
|
||||
txt_in_folder,
|
||||
}
|
||||
|
||||
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 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 status = Command::new("cargo")
|
||||
.args(&[
|
||||
"run", "--quiet", "--",
|
||||
"build", input_path.to_str().unwrap(), "-o", output_path.to_str().unwrap(),
|
||||
])
|
||||
.current_dir(working_dir)
|
||||
.status()
|
||||
.expect("Couldn't start Rojo");
|
||||
|
||||
assert!(status.success(), "Rojo did not exit successfully");
|
||||
|
||||
let contents = fs::read_to_string(&output_path)
|
||||
.expect("Couldn't read output file");
|
||||
|
||||
assert_snapshot_matches!(test_name, contents);
|
||||
}
|
||||
@@ -1,43 +1,2 @@
|
||||
use std::{
|
||||
fs,
|
||||
path::Path,
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use insta::assert_snapshot_matches;
|
||||
use tempfile::tempdir;
|
||||
|
||||
static BUILD_TESTS: &[&str] = &[
|
||||
"gitkeep",
|
||||
"txt_in_folder",
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn build_tests() {
|
||||
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 output_dir = tempdir().expect("couldn't create temporary directory");
|
||||
|
||||
for &test_name in BUILD_TESTS {
|
||||
let input_path = build_test_path.join(test_name);
|
||||
let output_path = output_dir.path().join(format!("{}.rbxmx", test_name));
|
||||
|
||||
let status = Command::new("cargo")
|
||||
.args(&[
|
||||
"run", "--",
|
||||
"build", input_path.to_str().unwrap(), "-o", output_path.to_str().unwrap(),
|
||||
])
|
||||
.current_dir(working_dir)
|
||||
.status()
|
||||
.expect("Couldn't start Rojo");
|
||||
|
||||
assert!(status.success(), "Rojo did not exit successfully");
|
||||
|
||||
let contents = fs::read_to_string(&output_path)
|
||||
.expect("Couldn't read output file");
|
||||
|
||||
assert_snapshot_matches!(format!("build_{}", test_name), contents);
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod build_test;
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
created: "2019-08-08T00:40:36.892733600Z"
|
||||
created: "2019-08-08T00:48:33.382271800Z"
|
||||
creator: insta@0.10.0
|
||||
source: rojo-test/src/lib.rs
|
||||
source: rojo-test/src/build_test.rs
|
||||
expression: contents
|
||||
---
|
||||
<roblox version="4">
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
created: "2019-08-08T00:40:50.026718300Z"
|
||||
created: "2019-08-08T00:48:33.502257600Z"
|
||||
creator: insta@0.10.0
|
||||
source: rojo-test/src/lib.rs
|
||||
source: rojo-test/src/build_test.rs
|
||||
expression: contents
|
||||
---
|
||||
<roblox version="4">
|
||||
Reference in New Issue
Block a user