From af29abdb1e5bb8c54bd7178c4099346e81db62bb Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 2 Apr 2023 12:07:08 +0200 Subject: [PATCH] Fix datatests to be properly working in newer nightly rust --- Cargo.toml | 3 +- build.rs | 51 +++++++++++++++++++ src/lib.rs | 3 +- .../wasm/script_resolver.rs | 2 +- tests/datatests/mod.rs | 24 +++++++++ tests/integration.rs | 21 +------- 6 files changed, 81 insertions(+), 23 deletions(-) create mode 100644 build.rs create mode 100644 tests/datatests/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 27fc5c7..d4e3d48 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ hashbrown = "0.13.1" indexmap = "1.8.2" parking_lot = "0.12.1" serde = { version = "1.0.137", optional = true, features = ["derive"] } -wasmer = { version = "3.1.0", optional = true, default-features = false, features = ["sys", "wat", "llvm"] } +wasmer = { version = "3.1.1", optional = true, default-features = false, features = ["sys", "wat", "cranelift"] } uuid = "1.2.2" paste = { version = "1.0.8" } arcstr = { version = "1.1.4", features = ["std"] } @@ -62,7 +62,6 @@ enum-display-derive = "0.1.1" [dev-dependencies] csv = "1.1.6" project-root = "0.2.2" -datatest = { git = "https://github.com/Deukhoofd/datatest.git" } serde_yaml = "0.9.14" serde_json = "1.0.81" serde_plain = "1.0.0" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..2e36dac --- /dev/null +++ b/build.rs @@ -0,0 +1,51 @@ +use std::io::Write; + +fn main() { + let files = std::fs::read_dir("tests/test_cases").unwrap(); + let mut output_file = std::fs::File::create("tests/datatests/mod.rs").unwrap(); + output_file + .write_all( + b"// This file is generated by build.rs + +use std::path::Path; +use std::fs::File; +use std::io::Read; +use super::common::TestCase; +use super::get_library; + +fn integration_tests(input: &Path) { + let mut str: String = \"\".to_string(); + let mut file = File::open(input).unwrap(); + file.read_to_string(&mut str).unwrap(); + let test_case = serde_yaml::from_str::(&str).unwrap(); + println!(\"\tRunning integration test {}\", test_case.name); + test_case.run_test(get_library()); +} + +", + ) + .unwrap(); + for file in files { + let file = file.unwrap(); + let path = file.path(); + let path_str = path.to_str().unwrap(); + if path_str.ends_with(".yaml") { + println!("cargo:rerun-if-changed={}", path_str); + } + let file_name = path.file_stem().unwrap().to_str().unwrap(); + + write!( + output_file, + " +#[test] +fn {}() {{ + integration_tests(Path::new(\"{}\")); +}} + + ", + file_name, + path.to_str().unwrap(), + ) + .unwrap(); + } +} diff --git a/src/lib.rs b/src/lib.rs index 0b8c1a2..cffcea2 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,10 +2,10 @@ #![allow(clippy::not_unsafe_ptr_arg_deref)] #![allow(clippy::borrowed_box)] #![allow(incomplete_features)] +#![allow(ambiguous_glob_reexports)] #![deny(missing_docs)] #![deny(clippy::missing_docs_in_private_items)] #![feature(test)] -#![feature(once_cell)] #![feature(const_option)] #![feature(is_some_and)] #![feature(new_uninit)] @@ -14,6 +14,7 @@ #![feature(fn_traits)] #![feature(unboxed_closures)] #![feature(trait_upcasting)] +#![feature(lazy_cell)] //! PkmnLib //! PkmnLib is a full featured implementation of Pokemon. while currently focused on implementing diff --git a/src/script_implementations/wasm/script_resolver.rs b/src/script_implementations/wasm/script_resolver.rs index 1edb730..39ec4ae 100755 --- a/src/script_implementations/wasm/script_resolver.rs +++ b/src/script_implementations/wasm/script_resolver.rs @@ -52,7 +52,7 @@ struct ScriptCapabilitiesKey { impl WebAssemblyScriptResolver { /// Instantiates a new WebAssemblyScriptResolver. pub fn new() -> Box { - let compiler = wasmer::LLVM::default(); + let compiler = wasmer::Cranelift::default(); let mut features = Features::new(); features.multi_value = true; features.reference_types = true; diff --git a/tests/datatests/mod.rs b/tests/datatests/mod.rs new file mode 100644 index 0000000..6787e9f --- /dev/null +++ b/tests/datatests/mod.rs @@ -0,0 +1,24 @@ +// This file is generated by build.rs + +use std::path::Path; +use std::fs::File; +use std::io::Read; +use super::common::TestCase; +use super::get_library; + +fn integration_tests(input: &Path) { + let mut str: String = "".to_string(); + let mut file = File::open(input).unwrap(); + file.read_to_string(&mut str).unwrap(); + let test_case = serde_yaml::from_str::(&str).unwrap(); + println!(" Running integration test {}", test_case.name); + test_case.run_test(get_library()); +} + + +#[test] +fn basic_single_turn() { + integration_tests(Path::new("tests/test_cases/basic_single_turn.yaml")); +} + + \ No newline at end of file diff --git a/tests/integration.rs b/tests/integration.rs index f2d0eee..e86d46e 100755 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1,11 +1,6 @@ #![feature(custom_test_frameworks)] -#![feature(once_cell)] -#![test_runner(datatest::runner)] #![allow(clippy::borrowed_box)] -use std::fs::File; -use std::io::Read; -use std::path::Path; use std::sync::Arc; use pkmn_lib::dynamic_data::{ @@ -13,9 +8,10 @@ use pkmn_lib::dynamic_data::{ ScriptCategory, ScriptContainer, ScriptOwnerData, TurnChoice, VolatileScriptsOwner, }; -use crate::common::{library_loader, TestCase}; +use crate::common::library_loader; pub mod common; +pub mod datatests; fn get_library() -> Arc { library_loader::load_library().library @@ -49,19 +45,6 @@ fn validate_library_load() { ); } -#[datatest::files("tests/test_cases", { -input in r"^(.*)\.yaml" -})] -#[cfg_attr(miri, ignore)] -fn integration_tests(input: &Path) { - let mut str: String = "".to_string(); - let mut file = File::open(input).unwrap(); - file.read_to_string(&mut str).unwrap(); - let test_case = serde_yaml::from_str::(&str).unwrap(); - println!("\tRunning integration test {}", test_case.name); - test_case.run_test(get_library()); -} - /// Assurance has the interesting properties that it creates a special data script internally, and /// deletes that data script through the get_owner functionality. #[test]