From 6384034e47180e2dde12bbddce978e76799a92dd Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Fri, 27 Jan 2023 19:15:49 +0100 Subject: [PATCH] tests: Move test_swf_with_hooks to util/runner --- tests/tests/regression_tests.rs | 41 +-------------------------------- tests/tests/util/runner.rs | 39 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/tests/tests/regression_tests.rs b/tests/tests/regression_tests.rs index 2525ae5f3..80bdec32b 100644 --- a/tests/tests/regression_tests.rs +++ b/tests/tests/regression_tests.rs @@ -11,7 +11,7 @@ use ruffle_core::external::Value as ExternalValue; use ruffle_core::external::{ExternalInterfaceMethod, ExternalInterfaceProvider}; use ruffle_core::Player; -use crate::util::runner::test_swf_approx; +use crate::util::runner::{test_swf_approx, test_swf_with_hooks}; use anyhow::Context; use anyhow::Result; use libtest_mimic::{Arguments, Trial}; @@ -244,45 +244,6 @@ fn shared_object_avm2() -> Result<()> { Ok(()) } -/// Loads an SWF and runs it through the Ruffle core for a number of frames. -/// Tests that the trace output matches the given expected output. -#[allow(clippy::too_many_arguments)] -fn test_swf_with_hooks( - swf_path: &Path, - num_frames: u32, - simulated_input_path: &Path, - expected_output_path: &Path, - before_start: impl FnOnce(Arc>) -> Result<()>, - before_end: impl FnOnce(Arc>) -> Result<()>, - check_img: bool, - frame_time_sleep: bool, -) -> Result<()> { - let injector = - InputInjector::from_file(simulated_input_path).unwrap_or_else(|_| InputInjector::empty()); - let mut expected_output = std::fs::read_to_string(expected_output_path)?.replace("\r\n", "\n"); - - // Strip a trailing newline if it has one. - if expected_output.ends_with('\n') { - expected_output = expected_output[0..expected_output.len() - "\n".len()].to_string(); - } - - let trace_log = run_swf( - swf_path, - num_frames, - before_start, - injector, - before_end, - check_img, - frame_time_sleep, - )?; - assert_eq!( - trace_log, expected_output, - "ruffle output != flash player output" - ); - - Ok(()) -} - struct TestLogBackend { trace_output: Rc>>, } diff --git a/tests/tests/util/runner.rs b/tests/tests/util/runner.rs index 3e6df42b6..24b4d4361 100644 --- a/tests/tests/util/runner.rs +++ b/tests/tests/util/runner.rs @@ -293,3 +293,42 @@ pub fn test_swf_approx( } Ok(()) } + +/// Loads an SWF and runs it through the Ruffle core for a number of frames. +/// Tests that the trace output matches the given expected output. +#[allow(clippy::too_many_arguments)] +pub fn test_swf_with_hooks( + swf_path: &Path, + num_frames: u32, + simulated_input_path: &Path, + expected_output_path: &Path, + before_start: impl FnOnce(Arc>) -> Result<()>, + before_end: impl FnOnce(Arc>) -> Result<()>, + check_img: bool, + frame_time_sleep: bool, +) -> Result<()> { + let injector = + InputInjector::from_file(simulated_input_path).unwrap_or_else(|_| InputInjector::empty()); + let mut expected_output = std::fs::read_to_string(expected_output_path)?.replace("\r\n", "\n"); + + // Strip a trailing newline if it has one. + if expected_output.ends_with('\n') { + expected_output = expected_output[0..expected_output.len() - "\n".len()].to_string(); + } + + let trace_log = run_swf( + swf_path, + num_frames, + before_start, + injector, + before_end, + check_img, + frame_time_sleep, + )?; + assert_eq!( + trace_log, expected_output, + "ruffle output != flash player output" + ); + + Ok(()) +}