Replace rstest with a couple of proc macros

rstest was overkill and pulled in 23 additional dependencies.
This commit is contained in:
Oliver Hamlet
2025-04-24 20:03:23 +01:00
parent a08d53ea52
commit 56b1fb09c9
9 changed files with 237 additions and 302 deletions
Generated
+12 -224
View File
@@ -418,49 +418,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "futures-core"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
[[package]]
name = "futures-macro"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-task"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"
[[package]]
name = "futures-timer"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24"
[[package]]
name = "futures-util"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
dependencies = [
"futures-core",
"futures-macro",
"futures-task",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]
name = "generic-array"
version = "0.14.7"
@@ -494,12 +451,6 @@ dependencies = [
"wasi 0.14.2+wasi-0.2.4",
]
[[package]]
name = "glob"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
[[package]]
name = "hashbrown"
version = "0.14.5"
@@ -602,10 +553,9 @@ dependencies = [
"libloadorder",
"log",
"loot-condition-interpreter",
"parameterized-test",
"petgraph",
"rayon",
"rstest",
"rstest_reuse",
"rustc-hash",
"saphyr",
"saphyr-parser",
@@ -829,6 +779,15 @@ dependencies = [
"hashbrown 0.14.5",
]
[[package]]
name = "parameterized-test"
version = "0.1.0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pelite"
version = "0.10.0"
@@ -905,47 +864,17 @@ dependencies = [
"serde",
]
[[package]]
name = "pin-project-lite"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "portable-atomic"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro-crate"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"
dependencies = [
"toml_edit",
]
[[package]]
name = "proc-macro2"
version = "1.0.94"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
@@ -1039,36 +968,6 @@ version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom 0.2.15",
]
[[package]]
name = "rayon"
version = "1.10.0"
@@ -1129,53 +1028,6 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "relative-path"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2"
[[package]]
name = "rstest"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fc39292f8613e913f7df8fa892b8944ceb47c247b78e1b1ae2f09e019be789d"
dependencies = [
"futures-timer",
"futures-util",
"rstest_macros",
"rustc_version",
]
[[package]]
name = "rstest_macros"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f168d99749d307be9de54d23fd226628d99768225ef08f6ffb52e0182a27746"
dependencies = [
"cfg-if",
"glob",
"proc-macro-crate",
"proc-macro2",
"quote",
"regex",
"relative-path",
"rustc_version",
"syn",
"unicode-ident",
]
[[package]]
name = "rstest_reuse"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a8fb4672e840a587a66fc577a5491375df51ddb88f2a2c2a792598c326fe14"
dependencies = [
"quote",
"rand",
"syn",
]
[[package]]
name = "rust-ini"
version = "0.21.1"
@@ -1194,15 +1046,6 @@ version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
[[package]]
name = "rustc_version"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
dependencies = [
"semver",
]
[[package]]
name = "rustix"
version = "1.0.5"
@@ -1294,15 +1137,6 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "slab"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
dependencies = [
"autocfg",
]
[[package]]
name = "strsim"
version = "0.11.1"
@@ -1397,23 +1231,6 @@ dependencies = [
"crunchy",
]
[[package]]
name = "toml_datetime"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
[[package]]
name = "toml_edit"
version = "0.22.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474"
dependencies = [
"indexmap",
"toml_datetime",
"winnow",
]
[[package]]
name = "trim-in-place"
version = "0.1.7"
@@ -1688,15 +1505,6 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63d3fcd9bba44b03821e7d699eeee959f3126dcc4aa8e4ae18ec617c2a5cea10"
dependencies = [
"memchr",
]
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
@@ -1705,23 +1513,3 @@ checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags",
]
[[package]]
name = "zerocopy"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
+2 -3
View File
@@ -23,12 +23,11 @@ loot-condition-interpreter.workspace = true
windows = { version = "0.61.1", features = ["Win32_Storage_FileSystem"] }
[dev-dependencies]
rstest = "0.25.0"
rstest_reuse = "0.7.0"
parameterized-test = { path = "./parameterized-test" }
tempfile = "3.17.1"
[workspace]
members = ["cxx", "ffi-errors", "nodejs", "pyo3"]
members = ["cxx", "ffi-errors", "nodejs", "parameterized-test", "pyo3"]
[workspace.dependencies]
esplugin = "6.1.2"
+12
View File
@@ -0,0 +1,12 @@
[package]
name = "parameterized-test"
version = "0.1.0"
edition = "2024"
[dependencies]
proc-macro2 = "1.0.95"
quote = "1.0.40"
syn = { version = "2.0.100", features = ["full"] }
[lib]
proc-macro = true
+140
View File
@@ -0,0 +1,140 @@
use proc_macro::{TokenStream, TokenTree};
use quote::{ToTokens, format_ident, quote};
use syn::{Expr, ExprLit, FnArg, Ident, ItemConst, ItemFn, Lit, Pat, PatIdent, PatType, parse};
#[proc_macro_attribute]
pub fn parameterized_test(input: TokenStream, annotated_item: TokenStream) -> TokenStream {
let macro_name: Ident = parse(input).unwrap();
let test: ItemFn = parse(annotated_item.clone()).unwrap();
let Some(FnArg::Typed(PatType {
pat: type_pattern, ..
})) = test.sig.inputs.first()
else {
panic!("Expected the first test function argument a type pattern");
};
let Pat::Ident(PatIdent {
ident: inner_func_arg_name,
..
}) = type_pattern.as_ref()
else {
panic!("Expected the first test function argument pattern to be an ident");
};
let inner_func_name = test.sig.ident.clone();
quote! {
mod #inner_func_name {
use super::*;
#test
#macro_name!{#inner_func_name, #inner_func_arg_name}
}
}
.into()
}
#[proc_macro_attribute]
pub fn test_parameter(_input: TokenStream, annotated_item: TokenStream) -> TokenStream {
let item: ItemConst = parse(annotated_item.clone()).unwrap();
let Expr::Array(array) = item.expr.as_ref() else {
panic!("Expected expression to be an array");
};
let values: Vec<_> = array
.elems
.iter()
.map(|n| match n {
Expr::Path(path) => path.path.segments.last().unwrap().ident.to_token_stream(),
Expr::Lit(ExprLit {
lit: Lit::Int(lit_int),
..
}) => lit_int.to_token_stream(),
_ => panic!("Expected array element to be a path or int literal"),
})
.collect();
let annotated_item = proc_macro2::TokenStream::from(annotated_item);
let const_item_name = item.ident;
let macro_name = format_ident!("{}_macro", &const_item_name);
let macro_output = quote! {
macro_rules! #macro_name {
( $inner_test_name:ident, $inner_test_arg_name:ident ) => {
parameterized_test::generate_tests!{
$inner_test_name,
$inner_test_arg_name,
#const_item_name,
[#(#values),*]
}
};
}
#[allow(unused_imports)]
pub(crate) use #macro_name as #const_item_name;
#annotated_item
};
macro_output.into()
}
#[proc_macro]
pub fn generate_tests(item: TokenStream) -> TokenStream {
let mut item_iter = item.into_iter();
let TokenTree::Ident(inner_test_name) = item_iter.next().unwrap() else {
panic!("Expected an ident for the inner_test_name");
};
let _ = item_iter.next();
let TokenTree::Ident(inner_test_param_name) = item_iter.next().unwrap() else {
panic!("Expected an ident for the inner_test_param_name");
};
let _ = item_iter.next();
let TokenTree::Ident(const_item_name) = item_iter.next().unwrap() else {
panic!("Expected an ident for the const_item_name");
};
let _ = item_iter.next();
let TokenTree::Group(const_item_values) = item_iter.next().unwrap() else {
panic!("Expected a group for the const_item_values");
};
let inner_test_name: Ident = parse(TokenTree::from(inner_test_name).into()).unwrap();
let const_item_name: Ident = parse(TokenTree::from(const_item_name).into()).unwrap();
let tokens: proc_macro2::TokenStream = const_item_values
.stream()
.into_iter()
.step_by(2)
.enumerate()
.flat_map(|(i, value)| {
let suffix = match value {
TokenTree::Ident(ident) => ident.to_string(),
TokenTree::Literal(literal) => literal.to_string(),
_ => panic!("Expected const item value to be an ident or literal"),
};
let test_name = format_ident!("{inner_test_param_name}_{i:02}_{suffix}");
quote! {
#[test]
#[allow(non_snake_case)]
fn #test_name() {
#inner_test_name(#const_item_name[#i]);
}
}
})
.collect();
tokens.into()
}
+9 -9
View File
@@ -201,14 +201,14 @@ mod tests {
mod find_associated_archives {
use std::path::absolute;
use rstest_reuse::apply;
use parameterized_test::parameterized_test;
use tempfile::TempDir;
use super::*;
use crate::tests::{
BLANK_DIFFERENT_ESM, BLANK_DIFFERENT_ESP, BLANK_ESM, BLANK_ESP,
BLANK_MASTER_DEPENDENT_ESM, all_game_types, copy_file, source_plugins_path,
ALL_GAME_TYPES, BLANK_DIFFERENT_ESM, BLANK_DIFFERENT_ESP, BLANK_ESM, BLANK_ESP,
BLANK_MASTER_DEPENDENT_ESM, copy_file, source_plugins_path,
};
const NON_ASCII_ESP: &str = "non\u{00C1}scii.esp";
@@ -281,7 +281,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_return_empty_vec_if_no_matching_archives_are_found(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -294,7 +294,7 @@ mod tests {
assert!(archives.is_empty());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_find_an_archive_that_exactly_matches_an_esm_file_basename_except_for_morrowind_and_oblivion(
game_type: GameType,
) {
@@ -316,7 +316,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_find_an_archive_that_exactly_matches_a_non_ascii_esp_file_basename_except_for_morrowind_and_starfield(
game_type: GameType,
) {
@@ -338,7 +338,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_find_an_archive_that_starts_with_an_esp_file_basename_except_for_morrowind_and(
game_type: GameType,
) {
@@ -357,7 +357,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_find_an_archive_that_starts_with_an_esm_file_basename_only_for_fallout(
game_type: GameType,
) {
@@ -382,7 +382,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_find_an_archive_that_starts_with_an_esp_file_basename_only_for_oblivion_and_fallout(
game_type: GameType,
) {
+6 -3
View File
@@ -137,7 +137,7 @@ mod tests {
io::SeekFrom,
};
use rstest::rstest;
use parameterized_test::{parameterized_test, test_parameter};
use tempfile::tempdir;
use super::*;
@@ -246,8 +246,11 @@ mod tests {
assert_eq!(expected_file_hash, *value.first().unwrap());
}
#[rstest]
fn should_support_ba2_versions(#[values(1, 2, 3, 7, 8)] version: u32) {
#[test_parameter]
const BA2_VERSIONS: [u32; 5] = [1, 2, 3, 7, 8];
#[parameterized_test(BA2_VERSIONS)]
fn should_support_ba2_versions(version: u32) {
use std::io::{Seek, Write};
let tmp_dir = tempdir().unwrap();
+18 -18
View File
@@ -805,13 +805,13 @@ impl GameCache {
mod tests {
use super::*;
use rstest_reuse::apply;
use parameterized_test::parameterized_test;
use crate::{
metadata::{File, PluginMetadata},
tests::{
BLANK_DIFFERENT_ESM, BLANK_DIFFERENT_ESP, BLANK_ESM, BLANK_ESP,
BLANK_MASTER_DEPENDENT_ESM, Fixture, all_game_types,
ALL_GAME_TYPES, BLANK_DIFFERENT_ESM, BLANK_DIFFERENT_ESP, BLANK_ESM, BLANK_ESP,
BLANK_MASTER_DEPENDENT_ESM, Fixture,
},
};
@@ -903,7 +903,7 @@ mod tests {
use super::*;
#[cfg(windows)]
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_succeed_if_given_valid_game_path(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -911,7 +911,7 @@ mod tests {
}
#[cfg(not(windows))]
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_succeed_for_morrowind_if_given_valid_game_path(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -975,7 +975,7 @@ mod tests {
mod with_local_path {
use super::*;
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_succeed_if_given_valid_paths(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -1090,7 +1090,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_set_default_additional_data_paths(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -1271,7 +1271,7 @@ mod tests {
use crate::tests::{NON_ASCII_ESM, NON_PLUGIN_FILE};
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_return_true_for_a_valid_non_ascii_plugin(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -1291,7 +1291,7 @@ mod tests {
assert!(game.is_valid_plugin(Path::new(NON_ASCII_ESM)));
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_return_true_for_an_omwscripts_plugin(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -1312,7 +1312,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_return_false_for_a_non_plugin_file(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -1326,7 +1326,7 @@ mod tests {
assert!(!game.is_valid_plugin(Path::new(NON_PLUGIN_FILE)));
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_return_false_for_an_empty_file(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -1343,7 +1343,7 @@ mod tests {
assert!(!game.is_valid_plugin(&empty_file_path));
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_try_ghosted_path_if_given_plugin_does_not_exist_unless_game_is_openmw(
game_type: GameType,
) {
@@ -1413,7 +1413,7 @@ mod tests {
use super::*;
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_load_the_headers_of_the_given_plugins(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -1514,7 +1514,7 @@ mod tests {
use super::*;
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_fully_load_the_given_plugins(game_type: GameType) {
let fixture = Fixture::new(game_type);
@@ -1584,7 +1584,7 @@ mod tests {
assert_ne!(plugin2, plugin3);
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_error_if_loading_a_plugin_with_a_master_that_is_not_loaded_if_game_is_morrowind_or_starfield(
game_type: GameType,
) {
@@ -1626,7 +1626,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_not_error_if_loading_a_plugin_with_a_master_that_is_also_being_loaded_if_game_is_morrowind_or_starfield(
game_type: GameType,
) {
@@ -1653,7 +1653,7 @@ mod tests {
assert!(game.plugin(BLANK_MASTER_DEPENDENT_ESM).is_some());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_not_error_if_loading_a_plugin_with_a_master_that_is_already_loaded_if_game_is_morrowind_or_starfield(
game_type: GameType,
) {
@@ -1684,7 +1684,7 @@ mod tests {
mod load_plugins_common {
use super::*;
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_find_archives_in_additional_data_paths(game_type: GameType) {
let fixture = Fixture::new(game_type);
+23 -25
View File
@@ -453,17 +453,19 @@ fn extract_version(description: &str) -> Result<Option<String>, Box<RegexImplErr
mod tests {
use super::*;
use crate::tests::ALL_GAME_TYPES;
use parameterized_test::parameterized_test;
mod plugin {
use std::io::Seek;
use std::io::Write;
use rstest_reuse::apply;
use tempfile::tempdir;
use crate::tests::{
BLANK_ESL, BLANK_ESM, BLANK_ESP, BLANK_FULL_ESM, BLANK_MASTER_DEPENDENT_ESM,
BLANK_MASTER_DEPENDENT_ESP, BLANK_MEDIUM_ESM, BLANK_OVERRIDE_ESP, NON_ASCII_ESM,
all_game_types, source_plugins_path,
source_plugins_path,
};
use super::*;
@@ -484,7 +486,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn new_should_trim_ghost_extension_unless_game_is_openmw(game_type: GameType) {
let tmp_dir = tempdir().unwrap();
let source_path = source_plugins_path(game_type).join(BLANK_ESP);
@@ -516,7 +518,7 @@ mod tests {
std::fs::copy(source_path, &path).unwrap();
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn new_with_header_only_scope_should_read_header_data_only(game_type: GameType) {
let plugin_name = blank_master_dependent_esm(game_type);
let path = source_plugins_path(game_type).join(plugin_name);
@@ -554,7 +556,7 @@ mod tests {
assert_eq!(0, plugin.override_record_count().unwrap());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn new_with_header_only_scope_should_read_version_from_header_description(
game_type: GameType,
) {
@@ -571,7 +573,7 @@ mod tests {
assert_eq!("5.0", plugin.version().unwrap());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn new_with_header_only_scope_should_not_read_assets(game_type: GameType) {
let path = source_plugins_path(game_type).join(blank_esm(game_type));
@@ -587,7 +589,7 @@ mod tests {
assert_eq!(0, plugin.asset_count());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn new_with_whole_plugin_scope_should_read_records(game_type: GameType) {
let plugin_name = blank_master_dependent_esm(game_type);
let path = source_plugins_path(game_type).join(plugin_name);
@@ -663,7 +665,7 @@ mod tests {
assert!(plugin.do_records_overlap(&plugin).unwrap());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn new_with_whole_plugin_scope_should_read_assets(game_type: GameType) {
let data_path = source_plugins_path(game_type);
let path = data_path.join(BLANK_ESP);
@@ -691,7 +693,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn new_with_whole_plugin_scope_should_succeed_for_openmw_plugins(game_type: GameType) {
let tmp_dir = tempdir().unwrap();
@@ -751,7 +753,7 @@ mod tests {
);
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn is_master_should_be_false_for_a_non_master_plugin(game_type: GameType) {
let path = source_plugins_path(game_type).join(BLANK_ESP);
let plugin = Plugin::new(
@@ -765,7 +767,7 @@ mod tests {
assert!(!plugin.is_master());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn is_light_plugin_should_be_true_for_a_plugin_with_esl_extension_for_fo4_and_later(
game_type: GameType,
) {
@@ -814,7 +816,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn is_medium_plugin_should_be_true_for_a_medium_flagged_plugin_for_starfield(
game_type: GameType,
) {
@@ -851,7 +853,7 @@ mod tests {
assert_eq!(game_type == GameType::Starfield, plugin.is_medium_plugin());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn is_update_plugin_should_be_true_for_an_update_plugin_for_starfield(game_type: GameType) {
let tmp_dir = tempdir().unwrap();
@@ -887,7 +889,7 @@ mod tests {
assert_eq!(game_type == GameType::Starfield, update.is_update_plugin());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn is_blueprint_plugin_should_be_true_for_a_blueprint_plugin_for_starfield(
game_type: GameType,
) {
@@ -917,7 +919,7 @@ mod tests {
assert_eq!(game_type == GameType::Starfield, update.is_update_plugin());
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn is_valid_as_light_plugin_should_be_true_only_for_a_skyrim_fallout4_or_starfield_plugin_with_new_formids_in_the_valid_range(
game_type: GameType,
) {
@@ -960,7 +962,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn is_valid_as_medium_plugin_should_be_true_only_for_a_starfield_plugin_with_new_formids_in_the_valid_range(
game_type: GameType,
) {
@@ -996,7 +998,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn is_valid_as_update_plugin_should_be_true_only_for_a_starfield_plugin_with_no_new_records(
game_type: GameType,
) {
@@ -1035,20 +1037,16 @@ mod tests {
}
mod has_plugin_file_extension {
use rstest_reuse::apply;
use crate::tests::all_game_types;
use super::*;
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_be_true_if_file_ends_in_dot_esp_or_dot_esm(game_type: GameType) {
assert!(has_plugin_file_extension(game_type, Path::new("file.esp")));
assert!(has_plugin_file_extension(game_type, Path::new("file.esm")));
assert!(!has_plugin_file_extension(game_type, Path::new("file.bsa")));
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_be_true_if_file_ends_in_dot_esl_and_game_is_fo4_or_later(game_type: GameType) {
let result = has_plugin_file_extension(game_type, Path::new("file.esl"));
if matches!(
@@ -1065,7 +1063,7 @@ mod tests {
}
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_trim_ghost_extension_unless_game_is_openmw(game_type: GameType) {
if game_type == GameType::OpenMW {
assert!(!has_plugin_file_extension(
@@ -1092,7 +1090,7 @@ mod tests {
));
}
#[apply(all_game_types)]
#[parameterized_test(ALL_GAME_TYPES)]
fn should_recognise_openmw_plugin_extensions(game_type: GameType) {
if game_type == GameType::OpenMW {
assert!(has_plugin_file_extension(
+15 -20
View File
@@ -5,7 +5,7 @@ use std::{
};
use crate::GameType;
use rstest_reuse::template;
use parameterized_test::test_parameter;
use tempfile::TempDir;
pub const BLANK_ESM: &str = "Blank.esm";
@@ -314,25 +314,20 @@ impl Fixture {
}
}
#[template]
#[rstest::rstest]
pub fn all_game_types(
#[values(
GameType::Oblivion,
GameType::Skyrim,
GameType::Fallout3,
GameType::FalloutNV,
GameType::Fallout4,
GameType::SkyrimSE,
GameType::Fallout4VR,
GameType::SkyrimVR,
GameType::Morrowind,
GameType::Starfield,
GameType::OpenMW
)]
game_type: GameType,
) {
}
#[test_parameter]
pub const ALL_GAME_TYPES: [GameType; 11] = [
GameType::Oblivion,
GameType::Skyrim,
GameType::Fallout3,
GameType::FalloutNV,
GameType::Fallout4,
GameType::SkyrimSE,
GameType::Fallout4VR,
GameType::SkyrimVR,
GameType::Morrowind,
GameType::Starfield,
GameType::OpenMW,
];
mod unicase {
#[test]