kawauso_process/invocation/program.rs
1//! The program that an external command starts
2
3use typed_fields::path;
4
5path!(
6 /// The program that an external command starts
7 ///
8 /// The value is the path of an executable file, such as
9 /// `/usr/bin/git` or `./scripts/build.sh`, or the bare name of one, such
10 /// as `git`. The operating system resolves a bare name when the command
11 /// runs, with the rules of the platform that it runs on.
12 ///
13 /// The value is stored as the caller gave it. A name that no program on
14 /// the machine answers to is therefore a valid program, and the failure
15 /// appears when the command runs.
16 Program
17);
18
19/// Creates a program from a path that the application built at runtime
20impl From<std::path::PathBuf> for Program {
21 fn from(path: std::path::PathBuf) -> Self {
22 Self::new(path)
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 // An assertion in a test panics by design. A `# Panics` section on every
29 // test would repeat that and give the reader no information.
30 #![allow(clippy::missing_panics_doc)]
31
32 use super::*;
33
34 // An application that resolves the program itself, through a version
35 // manager for example, holds a `PathBuf`, and the program takes it
36 // without a borrow.
37 #[test]
38 fn from_path_buf_keeps_the_path() {
39 let program = Program::from(std::path::PathBuf::from("/usr/bin/git"));
40
41 assert_eq!(program.get(), std::path::Path::new("/usr/bin/git"));
42 }
43}