From 90aa9b4227e2e7d4b57e92de0c86b3f589dda26f Mon Sep 17 00:00:00 2001 From: Jeff Charles Date: Tue, 5 Nov 2024 18:11:54 -0500 Subject: [PATCH] Refactor plugin paths in test suite --- crates/cli/tests/dylib_test.rs | 17 ++--------------- crates/runner/src/lib.rs | 27 ++++++++++++++++++++++----- crates/test-macros/src/lib.rs | 20 ++++---------------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/crates/cli/tests/dylib_test.rs b/crates/cli/tests/dylib_test.rs index 60232253..05e90448 100644 --- a/crates/cli/tests/dylib_test.rs +++ b/crates/cli/tests/dylib_test.rs @@ -1,10 +1,7 @@ use anyhow::Result; -use javy_runner::{Runner, RunnerError, UseExportedFn}; -use std::path::{Path, PathBuf}; +use javy_runner::{Plugin, Runner, RunnerError, UseExportedFn}; use std::str; -static ROOT: &str = env!("CARGO_MANIFEST_DIR"); - #[test] fn test_dylib() -> Result<()> { let js_src = "console.log(42);"; @@ -60,15 +57,5 @@ fn test_dylib_with_exported_func() -> Result<()> { } fn plugin_module() -> Result> { - let mut lib_path = PathBuf::from(ROOT); - lib_path.pop(); - lib_path.pop(); - lib_path = lib_path.join( - Path::new("target") - .join("wasm32-wasip1") - .join("release") - .join("plugin_wizened.wasm"), - ); - - std::fs::read(lib_path).map_err(Into::into) + std::fs::read(Plugin::Default.path()).map_err(Into::into) } diff --git a/crates/runner/src/lib.rs b/crates/runner/src/lib.rs index 8c7251ec..d0e9001b 100644 --- a/crates/runner/src/lib.rs +++ b/crates/runner/src/lib.rs @@ -35,6 +35,27 @@ impl Plugin { Self::User { .. } => "test_plugin", } } + + pub fn path(&self) -> PathBuf { + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + match self { + Self::V2 => root + .join("..") + .join("..") + .join("crates") + .join("cli") + .join("src") + .join("javy_quickjs_provider_v2.wasm"), + Self::User => root.join("test_plugin.wasm"), + Self::Default => root + .join("..") + .join("..") + .join("target") + .join("wasm32-wasip1") + .join("release") + .join("plugin_wizened.wasm"), + } + } } #[derive(Clone)] @@ -589,7 +610,7 @@ impl Runner { if let Plugin::User = plugin { args.push("-C".to_string()); - args.push(format!("plugin={}", Self::plugin_path().to_str().unwrap())); + args.push(format!("plugin={}", plugin.path().to_str().unwrap())); } args @@ -815,10 +836,6 @@ impl Runner { .into()), } } - - fn plugin_path() -> PathBuf { - PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_plugin.wasm") - } } #[derive(Debug)] diff --git a/crates/test-macros/src/lib.rs b/crates/test-macros/src/lib.rs index bc3f8557..9fa8ff40 100644 --- a/crates/test-macros/src/lib.rs +++ b/crates/test-macros/src/lib.rs @@ -290,30 +290,18 @@ fn expand_cli_tests(test_config: &CliTestConfig, func: syn::ItemFn) -> Result