Fix datatests to be properly working in newer nightly rust
continuous-integration/drone Build is passing Details

This commit is contained in:
Deukhoofd 2023-04-02 12:07:08 +02:00
parent ca54820483
commit af29abdb1e
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 81 additions and 23 deletions

View File

@ -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"

51
build.rs Normal file
View File

@ -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::<TestCase>(&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();
}
}

View File

@ -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

View File

@ -52,7 +52,7 @@ struct ScriptCapabilitiesKey {
impl WebAssemblyScriptResolver {
/// Instantiates a new WebAssemblyScriptResolver.
pub fn new() -> Box<WebAssemblyScriptResolver> {
let compiler = wasmer::LLVM::default();
let compiler = wasmer::Cranelift::default();
let mut features = Features::new();
features.multi_value = true;
features.reference_types = true;

24
tests/datatests/mod.rs Normal file
View File

@ -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::<TestCase>(&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"));
}

View File

@ -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<dyn DynamicLibrary> {
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::<TestCase>(&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]