Skip to content

Commit

Permalink
Refactor plugin paths in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcharles committed Nov 5, 2024
1 parent 2076f15 commit 90aa9b4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
17 changes: 2 additions & 15 deletions crates/cli/tests/dylib_test.rs
Original file line number Diff line number Diff line change
@@ -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);";
Expand Down Expand Up @@ -60,15 +57,5 @@ fn test_dylib_with_exported_func() -> Result<()> {
}

fn plugin_module() -> Result<Vec<u8>> {
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)
}
27 changes: 22 additions & 5 deletions crates/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -815,10 +836,6 @@ impl Runner {
.into()),
}
}

fn plugin_path() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_plugin.wasm")
}
}

#[derive(Debug)]
Expand Down
20 changes: 4 additions & 16 deletions crates/test-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,30 +290,18 @@ fn expand_cli_tests(test_config: &CliTestConfig, func: syn::ItemFn) -> Result<To
// releases.
if command_name == "Compile" {
quote! {
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let plugin = javy_runner::Plugin::V2;
let namespace = plugin.namespace();
builder.plugin(plugin);
builder.preload(
namespace.into(),
root.join("src").join("javy_quickjs_provider_v2.wasm")
plugin.namespace().into(),
plugin.path(),
);
builder.plugin(plugin);
}
} else {
quote! {
let mut root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
root.pop();
root.pop();
root = root.join(
std::path::Path::new("target")
.join("wasm32-wasip1")
.join("release")
.join("plugin_wizened.wasm"),
);
let plugin = javy_runner::Plugin::Default;
let namespace = plugin.namespace();
builder.preload(plugin.namespace().into(), plugin.path());
builder.plugin(plugin);
builder.preload(namespace.into(), root);
}
}
} else {
Expand Down

0 comments on commit 90aa9b4

Please sign in to comment.