use std::path::{Path, PathBuf};
use znippy_common::plugin::ArchiveTypePlugin;
use znippy_common::plugins::cargo_native::CargoPlugin;
use znippy_common::plugins::conda_native::CondaPlugin;
use znippy_common::plugins::deb_native::DebPlugin;
use znippy_common::plugins::gem_native::GemPlugin;
use znippy_common::plugins::npm_native::NpmPlugin;
use znippy_common::plugins::rpm_native::RpmPlugin;
fn plugins_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/plugins")
}
fn loose_rs(dir: &Path) -> Vec<String> {
let entries = std::fs::read_dir(dir)
.unwrap_or_else(|e| panic!("plugin source dir {} is unreadable: {e}", dir.display()));
let mut names: Vec<String> = entries
.map(|e| e.expect("read_dir entry").path())
.filter(|p| p.is_file() && p.extension().is_some_and(|x| x == "rs"))
.map(|p| p.file_name().expect("file has a name").to_string_lossy().into_owned())
.collect();
names.sort();
names
}
#[test]
fn no_plugin_source_sits_loose() {
let dir = plugins_dir();
for sub in ["native", "wasm"] {
let p = dir.join(sub);
assert!(
p.is_dir(),
"the plugin split is gone: {} is not a directory",
p.display()
);
}
assert!(
!loose_rs(&dir.join("native")).is_empty(),
"src/plugins/native/ holds no .rs at all — the guard would pass over an empty tree"
);
assert!(
!loose_rs(&dir.join("wasm")).is_empty(),
"src/plugins/wasm/ holds no .rs at all — the guard would pass over an empty tree"
);
let loose = loose_rs(&dir);
assert_eq!(
loose,
vec!["mod.rs".to_string()],
"plugin source must live in src/plugins/native/ or src/plugins/wasm/, never loose \
beside mod.rs — these are loose: {loose:?}"
);
}
#[test]
fn published_handler_paths_still_resolve() {
let ids: Vec<(&str, i8)> = vec![
("cargo", CargoPlugin::new().type_id()),
("npm", NpmPlugin.type_id()),
("rpm", RpmPlugin.type_id()),
("deb", DebPlugin.type_id()),
("gem", GemPlugin.type_id()),
("conda", CondaPlugin.type_id()),
];
assert_eq!(
ids,
vec![("cargo", 1), ("npm", 6), ("rpm", 8), ("deb", 9), ("gem", 11), ("conda", 14)],
"a published handler path resolved to the wrong handler after the source move"
);
use znippy_common::plugins::skeletons;
assert_eq!(
(skeletons::GoPlugin.type_id(), skeletons::NugetPlugin.type_id()),
(4, 5),
"a skeleton stub resolved to the wrong handler after the source move"
);
assert!(
!skeletons::skeleton_handlers().is_empty(),
"znippy_common::plugins::skeletons::skeleton_handlers() returned no stubs"
);
}