#![allow(clippy::expect_used)]
use polyplug::loader::ManifestData;
use polyplug::loader::parse_manifest;
use polyplug::runtime::Runtime;
use polyplug_utils::bundle_id;
use std::sync::Arc;
mod common;
use common::TestNativeLoader;
const TEST_PLUGIN_DIR: &str = env!("TEST_PLUGIN_DIR");
#[test]
#[cfg(not(miri))]
fn library_handle_outlives_load_call() {
let plugin_dir: &std::path::Path = std::path::Path::new(TEST_PLUGIN_DIR);
let mut manifest: ManifestData =
parse_manifest(plugin_dir).expect("parse_manifest for test_plugin_dir");
manifest.id = bundle_id(&manifest.name);
let runtime: Arc<Runtime> = Runtime::builder()
.loader(TestNativeLoader::new())
.build()
.expect("runtime build should succeed");
let so_path: std::path::PathBuf = plugin_dir.join(&manifest.file);
runtime
.load_bundle(&so_path)
.expect("load_bundle must succeed for test_plugin");
drop(runtime);
}
#[test]
#[cfg(not(miri))]
fn load_bundle_from_source_path_loads_native_bundle() {
let plugin_dir: &std::path::Path = std::path::Path::new(TEST_PLUGIN_DIR);
let mut manifest: ManifestData =
parse_manifest(plugin_dir).expect("parse_manifest for test_plugin_dir");
manifest.id = bundle_id(&manifest.name);
let runtime: Arc<Runtime> = Runtime::builder()
.loader(TestNativeLoader::new())
.build()
.expect("runtime build should succeed");
let source: polyplug::loader::BundleSource =
polyplug::loader::BundleSource::Path(manifest.path.clone());
runtime
.load_bundle_from_source(manifest, source)
.expect("load_bundle_from_source must succeed for test_plugin");
drop(runtime);
}
#[test]
#[cfg(miri)]
fn push_library_ownership_enforced_at_compile_time() {
assert!(
true,
"ownership invariant is statically verified by the compiler"
);
}