diff options
Diffstat (limited to 'src/shims')
| -rw-r--r-- | src/shims/mod.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/shims/mod.rs b/src/shims/mod.rs index fd515bc..4b29466 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -85,7 +85,21 @@ impl Default for Manifest { } } +/// The shim reads its own manifest while dispatching a tool; tests read it to assert what a build did. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn manifest() -> Manifest { + manifest_impl() +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn manifest() -> Manifest { + manifest_impl() +} + +fn manifest_impl() -> Manifest { match std::env::var("AUR_SHIM_MANIFEST") { Ok(p) => match std::fs::read_to_string(&p) { Ok(s) => serde_json::from_str(&s).unwrap_or_default(), @@ -491,7 +505,21 @@ pub const DB_SUFFIXES: [&str; 5] = [ ".db.tar.xz", ]; +/// The shim validates its own `--db` argument; tests check the verdicts. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn valid_db_arg(p: &Path) -> bool { + valid_db_arg_impl(p) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn valid_db_arg(p: &Path) -> bool { + valid_db_arg_impl(p) +} + +fn valid_db_arg_impl(p: &Path) -> bool { let name = p .file_name() .map(|s| s.to_string_lossy().into_owned()) |
