mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 06:05:24 +00:00
Replace rojo-test with regular tests folder again (#323)
* Replace rojo-test with regular tests folder again * Bump MSRV to 1.43.1
This commit is contained in:
committed by
GitHub
parent
ca5b8ab309
commit
5ccd02939b
94
tests/tests/build.rs
Normal file
94
tests/tests/build.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
use std::{fs, path::Path, process::Command};
|
||||
|
||||
use insta::assert_snapshot;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use crate::rojo_test::io_util::{get_working_dir_path, BUILD_TESTS_PATH, ROJO_PATH};
|
||||
|
||||
macro_rules! gen_build_tests {
|
||||
( $($test_name: ident,)* ) => {
|
||||
$(
|
||||
paste::item! {
|
||||
#[test]
|
||||
fn [<build_ $test_name>]() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
run_build_test(stringify!($test_name));
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
gen_build_tests! {
|
||||
client_in_folder,
|
||||
client_init,
|
||||
csv_bug_145,
|
||||
csv_bug_147,
|
||||
csv_in_folder,
|
||||
deep_nesting,
|
||||
gitkeep,
|
||||
infer_service_name,
|
||||
infer_starter_player,
|
||||
init_meta_class_name,
|
||||
init_meta_properties,
|
||||
init_with_children,
|
||||
json_as_lua,
|
||||
json_model_in_folder,
|
||||
json_model_legacy_name,
|
||||
module_in_folder,
|
||||
module_init,
|
||||
rbxm_in_folder,
|
||||
rbxmx_in_folder,
|
||||
rbxmx_ref,
|
||||
script_meta_disabled,
|
||||
server_in_folder,
|
||||
server_init,
|
||||
txt,
|
||||
txt_in_folder,
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable_glob_ignore_paths")]
|
||||
gen_build_tests! {
|
||||
ignore_glob_inner,
|
||||
ignore_glob_nested,
|
||||
ignore_glob_spec,
|
||||
}
|
||||
|
||||
fn run_build_test(test_name: &str) {
|
||||
let working_dir = get_working_dir_path();
|
||||
|
||||
let input_path = Path::new(BUILD_TESTS_PATH).join(test_name);
|
||||
|
||||
let output_dir = tempdir().expect("couldn't create temporary directory");
|
||||
let output_path = output_dir.path().join(format!("{}.rbxmx", test_name));
|
||||
|
||||
let status = Command::new(ROJO_PATH)
|
||||
.args(&[
|
||||
"build",
|
||||
input_path.to_str().unwrap(),
|
||||
"-o",
|
||||
output_path.to_str().unwrap(),
|
||||
])
|
||||
.env("RUST_LOG", "error")
|
||||
.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");
|
||||
|
||||
let mut settings = insta::Settings::new();
|
||||
|
||||
let snapshot_path = Path::new(BUILD_TESTS_PATH)
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("build-test-snapshots");
|
||||
|
||||
settings.set_snapshot_path(snapshot_path);
|
||||
|
||||
settings.bind(|| {
|
||||
assert_snapshot!(test_name, contents);
|
||||
});
|
||||
}
|
||||
2
tests/tests/mod.rs
Normal file
2
tests/tests/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod build;
|
||||
mod serve;
|
||||
188
tests/tests/serve.rs
Normal file
188
tests/tests/serve.rs
Normal file
@@ -0,0 +1,188 @@
|
||||
use std::fs;
|
||||
|
||||
use insta::assert_yaml_snapshot;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use crate::rojo_test::{internable::InternAndRedact, serve_util::run_serve_test};
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
run_serve_test("empty", |session, mut redactions| {
|
||||
let info = session.get_api_rojo().unwrap();
|
||||
let root_id = info.root_instance_id;
|
||||
|
||||
assert_yaml_snapshot!("empty_info", redactions.redacted_yaml(info));
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"empty_all",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scripts() {
|
||||
run_serve_test("scripts", |session, mut redactions| {
|
||||
let info = session.get_api_rojo().unwrap();
|
||||
let root_id = info.root_instance_id;
|
||||
|
||||
assert_yaml_snapshot!("scripts_info", redactions.redacted_yaml(info));
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"scripts_all",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
|
||||
fs::write(session.path().join("src/foo.lua"), "Updated foo!").unwrap();
|
||||
|
||||
let subscribe_response = session.get_api_subscribe(0).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"scripts_subscribe",
|
||||
subscribe_response.intern_and_redact(&mut redactions, ())
|
||||
);
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"scripts_all-2",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_folder() {
|
||||
run_serve_test("add_folder", |session, mut redactions| {
|
||||
let info = session.get_api_rojo().unwrap();
|
||||
let root_id = info.root_instance_id;
|
||||
|
||||
assert_yaml_snapshot!("add_folder_info", redactions.redacted_yaml(info));
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"add_folder_all",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
|
||||
fs::create_dir(session.path().join("src/my-new-folder")).unwrap();
|
||||
|
||||
let subscribe_response = session.get_api_subscribe(0).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"add_folder_subscribe",
|
||||
subscribe_response.intern_and_redact(&mut redactions, ())
|
||||
);
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"add_folder_all-2",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_file() {
|
||||
run_serve_test("remove_file", |session, mut redactions| {
|
||||
let info = session.get_api_rojo().unwrap();
|
||||
let root_id = info.root_instance_id;
|
||||
|
||||
assert_yaml_snapshot!("remove_file_info", redactions.redacted_yaml(info));
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"remove_file_all",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
|
||||
fs::remove_file(session.path().join("src/hello.txt")).unwrap();
|
||||
|
||||
let subscribe_response = session.get_api_subscribe(0).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"remove_file_subscribe",
|
||||
subscribe_response.intern_and_redact(&mut redactions, ())
|
||||
);
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"remove_file_all-2",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_init() {
|
||||
run_serve_test("edit_init", |session, mut redactions| {
|
||||
let info = session.get_api_rojo().unwrap();
|
||||
let root_id = info.root_instance_id;
|
||||
|
||||
assert_yaml_snapshot!("edit_init_info", redactions.redacted_yaml(info));
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"edit_init_all",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
|
||||
fs::write(session.path().join("src/init.lua"), b"-- Edited contents").unwrap();
|
||||
|
||||
let subscribe_response = session.get_api_subscribe(0).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"edit_init_subscribe",
|
||||
subscribe_response.intern_and_redact(&mut redactions, ())
|
||||
);
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"edit_init_all-2",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn move_folder_of_stuff() {
|
||||
run_serve_test("move_folder_of_stuff", |session, mut redactions| {
|
||||
let info = session.get_api_rojo().unwrap();
|
||||
let root_id = info.root_instance_id;
|
||||
|
||||
assert_yaml_snapshot!("move_folder_of_stuff_info", redactions.redacted_yaml(info));
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"move_folder_of_stuff_all",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
|
||||
// Create a directory full of stuff we can move in
|
||||
let src_dir = tempdir().unwrap();
|
||||
let stuff_path = src_dir.path().join("new-stuff");
|
||||
|
||||
fs::create_dir(&stuff_path).unwrap();
|
||||
|
||||
// Make a bunch of random files in our stuff folder
|
||||
for i in 0..10 {
|
||||
let file_name = stuff_path.join(format!("{}.txt", i));
|
||||
let file_contents = format!("File #{}", i);
|
||||
|
||||
fs::write(file_name, file_contents).unwrap();
|
||||
}
|
||||
|
||||
// We're hoping that this rename gets picked up as one event. This test
|
||||
// will fail otherwise.
|
||||
fs::rename(stuff_path, session.path().join("src/new-stuff")).unwrap();
|
||||
|
||||
let subscribe_response = session.get_api_subscribe(0).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"move_folder_of_stuff_subscribe",
|
||||
subscribe_response.intern_and_redact(&mut redactions, ())
|
||||
);
|
||||
|
||||
let read_response = session.get_api_read(root_id).unwrap();
|
||||
assert_yaml_snapshot!(
|
||||
"move_folder_of_stuff_all-2",
|
||||
read_response.intern_and_redact(&mut redactions, root_id)
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user