From 5512581c0f7b9f61ea8b6b3e9db67b1ffe591c2b Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 23 Oct 2018 18:30:05 +0100 Subject: [PATCH] Move test resources into subdirectory --- .gitignore | 4 +-- .travis.yml | 7 +++++ appveyor.yml | 19 ++++++++---- benches/eval.rs | 12 +++---- ffi/tests/ffi.cpp | 8 ++--- src/function/eval.rs | 74 +++++++++++++++++++++++++++----------------- src/version.rs | 10 +++--- 7 files changed, 81 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 1eb7c99..3bfb83c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,8 @@ /target/ **/*.rs.bk Cargo.lock -/testing-plugins -/loot_api* +/tests/testing-plugins +/tests/loot_api* /ffi/include/ /ffi/build/ .vscode diff --git a/.travis.yml b/.travis.yml index 1e293cc..e852cc6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,15 +12,22 @@ install: - rustfmt --version before_script: + - mkdir tests + - cd tests + - wget https://github.com/WrinklyNinja/testing-plugins/archive/1.4.1.tar.gz - tar -xf 1.4.1.tar.gz - mv testing-plugins-1.4.1 testing-plugins - wget https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win32.7z - 7z x loot_api-0.13.8-0-g47797cc_dev-win32.7z + - mv loot_api-0.13.8-0-g47797cc_dev-win32 loot_api_win32 - wget https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win64.7z - 7z x loot_api-0.13.8-0-g47797cc_dev-win64.7z + - mv loot_api-0.13.8-0-g47797cc_dev-win64 loot_api_win64 + + - cd .. script: - cargo fmt --all -- --check diff --git a/appveyor.yml b/appveyor.yml index c9b949c..d2a909d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,15 +16,22 @@ install: - rustup component add rustfmt-preview - rustfmt --version - - ps: (New-Object Net.WebClient).DownloadFile('https://github.com/WrinklyNinja/testing-plugins/archive/1.4.0.zip', "$env:APPVEYOR_BUILD_FOLDER\1.4.0.zip") - - ps: 7z x "$env:APPVEYOR_BUILD_FOLDER\1.4.0.zip" + - ps: mkdir tests + - cd tests + + - ps: (New-Object Net.WebClient).DownloadFile('https://github.com/WrinklyNinja/testing-plugins/archive/1.4.0.zip', "$PWD/1.4.0.zip") + - 7z x 1.4.0.zip - mv testing-plugins-1.4.0 testing-plugins - - ps: (New-Object Net.WebClient).DownloadFile('https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win32.7z', "$env:APPVEYOR_BUILD_FOLDER\loot_api-0.13.8-0-g47797cc_dev-win32.7z") - - ps: 7z x "$env:APPVEYOR_BUILD_FOLDER\loot_api-0.13.8-0-g47797cc_dev-win32.7z" + - ps: (New-Object Net.WebClient).DownloadFile('https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win32.7z', "$PWD/loot_api_win32.7z") + - 7z x loot_api_win32.7z + - mv loot_api-0.13.8-0-g47797cc_dev-win32 loot_api_win32 - - ps: (New-Object Net.WebClient).DownloadFile('https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win64.7z', "$env:APPVEYOR_BUILD_FOLDER\loot_api-0.13.8-0-g47797cc_dev-win64.7z") - - ps: 7z x "$env:APPVEYOR_BUILD_FOLDER\loot_api-0.13.8-0-g47797cc_dev-win64.7z" + - ps: (New-Object Net.WebClient).DownloadFile('https://github.com/loot/loot-api/releases/download/0.13.8/loot_api-0.13.8-0-g47797cc_dev-win64.7z', "$PWD/loot_api_win64.7z") + - 7z x loot_api_win64.7z + - mv loot_api-0.13.8-0-g47797cc_dev-win64 loot_api_win64 + + - cd .. build: false diff --git a/benches/eval.rs b/benches/eval.rs index 2ae8769..c6f3bed 100644 --- a/benches/eval.rs +++ b/benches/eval.rs @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("Expression.eval() active(path)", |b| { let state = State::new( GameType::Tes4, - "testing-plugins/Oblivion/Data".into(), + "tests/testing-plugins/Oblivion/Data".into(), ".".into(), ).with_active_plugins(&generate_active_plugins()); @@ -57,7 +57,7 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("Expression.eval() active(regex)", |b| { let state = State::new( GameType::Tes4, - "testing-plugins/Oblivion/Data".into(), + "tests/testing-plugins/Oblivion/Data".into(), ".".into(), ).with_active_plugins(&generate_active_plugins()); @@ -80,7 +80,7 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("Expression.eval() many_active()", |b| { let state = State::new( GameType::Tes4, - "testing-plugins/Oblivion/Data".into(), + "tests/testing-plugins/Oblivion/Data".into(), ".".into(), ).with_active_plugins(&generate_active_plugins()); @@ -94,7 +94,7 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("Expression.eval() checksum()", |b| { let state = State::new( GameType::Tes4, - "testing-plugins/Oblivion/Data".into(), + "tests/testing-plugins/Oblivion/Data".into(), ".".into(), ); let expression = Expression::from_str("checksum(\"Blank.esm\", 374E2A6F)").unwrap(); @@ -107,7 +107,7 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("Expression.eval() version(plugin)", |b| { let state = State::new( GameType::Tes4, - "testing-plugins/Oblivion/Data".into(), + "tests/testing-plugins/Oblivion/Data".into(), ".".into(), ).with_plugin_versions(&generate_plugin_versions()); @@ -121,7 +121,7 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("Expression.eval() version(executable)", |b| { let state = State::new(GameType::Tes4, ".".into(), ".".into()); let expression = Expression::from_str( - "version(\"loot_api-0.13.8-0-g47797cc_dev-win32/loot_api.dll\", \"0.13.8.0\", ==)", + "version(\"tests/loot_api_win32/loot_api.dll\", \"0.13.8.0\", ==)", ).unwrap(); b.iter(|| { diff --git a/ffi/tests/ffi.cpp b/ffi/tests/ffi.cpp index 3280b87..310eade 100644 --- a/ffi/tests/ffi.cpp +++ b/ffi/tests/ffi.cpp @@ -65,7 +65,7 @@ void test_lci_condition_eval() { printf("testing lci_condition_eval()...\n"); lci_state * state = nullptr; - int return_code = lci_state_create(&state, LCI_GAME_TES4, "../../testing-plugins/Oblivion/Data", "."); + int return_code = lci_state_create(&state, LCI_GAME_TES4, "../../tests/testing-plugins/Oblivion/Data", "."); assert(return_code == LCI_OK); assert(state != nullptr); @@ -85,7 +85,7 @@ void test_lci_state_set_active_plugins() { printf("testing lci_state_set_active_plugins()...\n"); lci_state * state = nullptr; - int return_code = lci_state_create(&state, LCI_GAME_TES4, "../../testing-plugins/Oblivion/Data", "."); + int return_code = lci_state_create(&state, LCI_GAME_TES4, "../../tests/testing-plugins/Oblivion/Data", "."); assert(return_code == LCI_OK); assert(state != nullptr); @@ -117,7 +117,7 @@ void test_lci_state_set_plugin_versions() { printf("testing lci_state_set_plugin_versions()...\n"); lci_state * state = nullptr; - int return_code = lci_state_create(&state, LCI_GAME_TES4, "../../testing-plugins/Oblivion/Data", "."); + int return_code = lci_state_create(&state, LCI_GAME_TES4, "../../tests/testing-plugins/Oblivion/Data", "."); assert(return_code == LCI_OK); assert(state != nullptr); @@ -152,7 +152,7 @@ void test_lci_state_set_crc_cache() { printf("testing lci_state_set_crc_cache()...\n"); lci_state * state = nullptr; - int return_code = lci_state_create(&state, LCI_GAME_TES4, "../../testing-plugins/Oblivion/Data", "."); + int return_code = lci_state_create(&state, LCI_GAME_TES4, "../../tests/testing-plugins/Oblivion/Data", "."); assert(return_code == LCI_OK); assert(state != nullptr); diff --git a/src/function/eval.rs b/src/function/eval.rs index d059534..fd26eeb 100644 --- a/src/function/eval.rs +++ b/src/function/eval.rs @@ -330,7 +330,7 @@ mod tests { let state = state(data_path); copy( - Path::new("testing-plugins/Oblivion/Data/Blank.esp"), + Path::new("tests/testing-plugins/Oblivion/Data/Blank.esp"), &state.data_path.join("Blank.esp.ghost"), ).unwrap(); @@ -400,7 +400,7 @@ mod tests { #[test] fn function_file_regex_eval_should_be_true_if_a_directory_entry_matches() { let function = Function::FileRegex( - PathBuf::from("testing-plugins/Oblivion/Data"), + PathBuf::from("tests/testing-plugins/Oblivion/Data"), regex("Blank\\.esp"), ); let state = state("."); @@ -467,7 +467,7 @@ mod tests { #[test] fn function_many_eval_should_be_false_if_one_directory_entry_matches() { let function = Function::Many( - PathBuf::from("testing-plugins/Oblivion/Data"), + PathBuf::from("tests/testing-plugins/Oblivion/Data"), regex("Blank\\.esp"), ); let state = state("."); @@ -478,7 +478,7 @@ mod tests { #[test] fn function_many_eval_should_be_true_if_more_than_one_directory_entry_matches() { let function = Function::Many( - PathBuf::from("testing-plugins/Oblivion/Data"), + PathBuf::from("tests/testing-plugins/Oblivion/Data"), regex("Blank.*"), ); let state = state("."); @@ -522,7 +522,7 @@ mod tests { fn function_checksum_eval_should_be_false_if_the_file_checksum_does_not_equal_the_given_checksum( ) { let function = Function::Checksum( - PathBuf::from("testing-plugins/Oblivion/Data/Blank.esm"), + PathBuf::from("tests/testing-plugins/Oblivion/Data/Blank.esm"), 0xDEADBEEF, ); let state = state("."); @@ -533,7 +533,7 @@ mod tests { #[test] fn function_checksum_eval_should_be_true_if_the_file_checksum_equals_the_given_checksum() { let function = Function::Checksum( - PathBuf::from("testing-plugins/Oblivion/Data/Blank.esm"), + PathBuf::from("tests/testing-plugins/Oblivion/Data/Blank.esm"), 0x374E2A6F, ); let state = state("."); @@ -548,7 +548,7 @@ mod tests { let state = state(data_path); copy( - Path::new("testing-plugins/Oblivion/Data/Blank.esm"), + Path::new("tests/testing-plugins/Oblivion/Data/Blank.esm"), &state.data_path.join("Blank.esm.ghost"), ).unwrap(); @@ -564,7 +564,7 @@ mod tests { let state = state(data_path); copy( - Path::new("testing-plugins/Oblivion/Data/Blank.bsa"), + Path::new("tests/testing-plugins/Oblivion/Data/Blank.bsa"), &state.data_path.join("Blank.bsa.ghost"), ).unwrap(); @@ -577,7 +577,7 @@ mod tests { #[allow(non_snake_case)] fn function_checksum_eval_should_be_true_if_given_LOOT_crc_matches() { let function = Function::Checksum(PathBuf::from("LOOT"), 0x374E2A6F); - let state = state_with_loot_path(".", "testing-plugins/Oblivion/Data/Blank.esm"); + let state = state_with_loot_path(".", "tests/testing-plugins/Oblivion/Data/Blank.esm"); assert!(function.eval(&state).unwrap()); } @@ -586,7 +586,7 @@ mod tests { #[allow(non_snake_case)] fn function_checksum_eval_should_be_false_if_given_LOOT_crc_does_not_match() { let function = Function::Checksum(PathBuf::from("LOOT"), 0xDEADBEEF); - let state = state_with_loot_path(".", "testing-plugins/Oblivion/Data/Blank.esm"); + let state = state_with_loot_path(".", "tests/testing-plugins/Oblivion/Data/Blank.esm"); assert!(!function.eval(&state).unwrap()); } @@ -598,7 +598,7 @@ mod tests { let state = state(data_path); copy( - Path::new("testing-plugins/Oblivion/Data/Blank.esm"), + Path::new("tests/testing-plugins/Oblivion/Data/Blank.esm"), &state.data_path.join("Blank.esm"), ).unwrap(); @@ -608,7 +608,7 @@ mod tests { // Change the CRC of the file to test that the cached value is used. copy( - Path::new("testing-plugins/Oblivion/Data/Blank.bsa"), + Path::new("tests/testing-plugins/Oblivion/Data/Blank.bsa"), &state.data_path.join("Blank.esm"), ).unwrap(); @@ -702,7 +702,7 @@ mod tests { let plugin = PathBuf::from("Blank.esm"); let version = String::from("1.0"); - let state = state("./testing-plugins/Oblivion/Data"); + let state = state("tests/testing-plugins/Oblivion/Data"); let function = Function::Version(plugin.clone(), version.clone(), NotEqual); assert!(function.eval(&state).unwrap()); @@ -721,7 +721,8 @@ mod tests { #[test] fn function_version_eval_should_be_false_if_versions_are_not_equal_and_comparator_is_eq() { let function = Function::Version("Blank.esm".into(), "5".into(), ComparisonOperator::Equal); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "1")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "1")]); assert!(!function.eval(&state).unwrap()); } @@ -729,7 +730,8 @@ mod tests { #[test] fn function_version_eval_should_be_true_if_versions_are_equal_and_comparator_is_eq() { let function = Function::Version("Blank.esm".into(), "5".into(), ComparisonOperator::Equal); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); assert!(function.eval(&state).unwrap()); } @@ -738,7 +740,8 @@ mod tests { fn function_version_eval_should_be_false_if_versions_are_equal_and_comparator_is_ne() { let function = Function::Version("Blank.esm".into(), "5".into(), ComparisonOperator::NotEqual); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); assert!(!function.eval(&state).unwrap()); } @@ -747,7 +750,8 @@ mod tests { fn function_version_eval_should_be_true_if_versions_are_not_equal_and_comparator_is_ne() { let function = Function::Version("Blank.esm".into(), "5".into(), ComparisonOperator::NotEqual); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "1")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "1")]); assert!(function.eval(&state).unwrap()); } @@ -756,7 +760,8 @@ mod tests { fn function_version_eval_should_be_false_if_actual_version_is_eq_and_comparator_is_lt() { let function = Function::Version("Blank.esm".into(), "5".into(), ComparisonOperator::LessThan); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); assert!(!function.eval(&state).unwrap()); } @@ -765,7 +770,8 @@ mod tests { fn function_version_eval_should_be_false_if_actual_version_is_gt_and_comparator_is_lt() { let function = Function::Version("Blank.esm".into(), "5".into(), ComparisonOperator::LessThan); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "6")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "6")]); assert!(!function.eval(&state).unwrap()); } @@ -774,7 +780,8 @@ mod tests { fn function_version_eval_should_be_true_if_actual_version_is_lt_and_comparator_is_lt() { let function = Function::Version("Blank.esm".into(), "5".into(), ComparisonOperator::NotEqual); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "1")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "1")]); assert!(function.eval(&state).unwrap()); } @@ -786,7 +793,8 @@ mod tests { "5".into(), ComparisonOperator::GreaterThan, ); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); assert!(!function.eval(&state).unwrap()); } @@ -798,7 +806,8 @@ mod tests { "5".into(), ComparisonOperator::GreaterThan, ); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "4")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "4")]); assert!(!function.eval(&state).unwrap()); } @@ -810,7 +819,8 @@ mod tests { "5".into(), ComparisonOperator::GreaterThan, ); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "6")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "6")]); assert!(function.eval(&state).unwrap()); } @@ -822,7 +832,8 @@ mod tests { "5".into(), ComparisonOperator::LessThanOrEqual, ); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "6")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "6")]); assert!(!function.eval(&state).unwrap()); } @@ -834,7 +845,8 @@ mod tests { "5".into(), ComparisonOperator::LessThanOrEqual, ); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); assert!(function.eval(&state).unwrap()); } @@ -846,7 +858,8 @@ mod tests { "5".into(), ComparisonOperator::LessThanOrEqual, ); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "4")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "4")]); assert!(function.eval(&state).unwrap()); } @@ -858,7 +871,8 @@ mod tests { "5".into(), ComparisonOperator::GreaterThanOrEqual, ); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "4")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "4")]); assert!(!function.eval(&state).unwrap()); } @@ -870,7 +884,8 @@ mod tests { "5".into(), ComparisonOperator::GreaterThanOrEqual, ); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "5")]); assert!(function.eval(&state).unwrap()); } @@ -882,7 +897,8 @@ mod tests { "5".into(), ComparisonOperator::GreaterThanOrEqual, ); - let state = state_with_versions("./testing-plugins/Oblivion/Data", &[("Blank.esm", "6")]); + let state = + state_with_versions("tests/testing-plugins/Oblivion/Data", &[("Blank.esm", "6")]); assert!(function.eval(&state).unwrap()); } diff --git a/src/version.rs b/src/version.rs index 599f9c2..89dbe14 100644 --- a/src/version.rs +++ b/src/version.rs @@ -148,9 +148,8 @@ mod tests { #[test] fn version_read_file_version_should_read_the_file_version_field_of_a_32_bit_executable() { - let version = Version::read_file_version(Path::new( - "loot_api-0.13.8-0-g47797cc_dev-win32/loot_api.dll", - )).unwrap(); + let version = + Version::read_file_version(Path::new("tests/loot_api_win32/loot_api.dll")).unwrap(); assert_eq!( version.release_ids, @@ -166,9 +165,8 @@ mod tests { #[test] fn version_read_file_version_should_read_the_file_version_field_of_a_64_bit_executable() { - let version = Version::read_file_version(Path::new( - "loot_api-0.13.8-0-g47797cc_dev-win64/loot_api.dll", - )).unwrap(); + let version = + Version::read_file_version(Path::new("tests/loot_api_win64/loot_api.dll")).unwrap(); assert_eq!( version.release_ids,