running_process_platform_internal/platform/executable.rs
1//! Executable naming, search, image discovery, and materialization primitives.
2//!
3//! Callers name the *program* they want. Whether that program is a file called
4//! `runpm` or `runpm.exe`, and where a sibling install lives relative to the
5//! running image, is a host mechanic and is decided here.
6
7pub use crate::{
8 executable_file_name as file_name,
9 executable_sibling_of_current_image as sibling_of_current_image, EXECUTABLE_EXTENSION,
10};
11
12#[cfg(test)]
13mod tests {
14 use super::*;
15
16 /// The host decides the spelling; the caller never does.
17 ///
18 /// Asserted against `EXECUTABLE_EXTENSION` rather than a hard-coded
19 /// `.exe`, so the test states the contract instead of restating one host's
20 /// answer -- the shape the caller sites used to have.
21 #[test]
22 fn file_name_applies_the_host_executable_extension() {
23 let named = file_name("running-process-daemon");
24 match EXECUTABLE_EXTENSION {
25 Some(extension) => {
26 assert_eq!(named, format!("running-process-daemon.{extension}"));
27 assert!(std::path::Path::new(&named).extension().is_some());
28 }
29 None => assert_eq!(named, "running-process-daemon"),
30 }
31 }
32
33 /// The running image is always a sibling of itself, under whatever
34 /// spelling this host uses -- which is the only claim that holds on every
35 /// host without assuming what else is installed.
36 #[test]
37 fn the_running_image_is_found_beside_itself() {
38 let current = std::env::current_exe().expect("current image");
39 let bare = current
40 .file_stem()
41 .expect("image stem")
42 .to_string_lossy()
43 .into_owned();
44
45 assert_eq!(sibling_of_current_image(&bare).as_deref(), Some(&*current));
46 }
47
48 /// A program that is not installed beside us is reported as absent rather
49 /// than as a path that does not exist.
50 #[test]
51 fn an_absent_sibling_is_none_not_a_missing_path() {
52 assert!(sibling_of_current_image("rp-no-such-sibling-program").is_none());
53 }
54}