comtrya_lib/steps/initializers/
command_found.rs1use super::Initializer;
2
3#[derive(Clone, Debug)]
4pub struct CommandFound(pub &'static str);
5
6impl Initializer for CommandFound {
7 fn initialize(&self) -> anyhow::Result<bool> {
8 Ok(which::which(self.0).is_ok())
9 }
10}
11
12#[cfg(test)]
13mod tests {
14 use super::*;
15 use pretty_assertions::assert_eq;
16
17 #[test]
18 fn it_returns_false_when_not_found() {
19 let initializer = CommandFound("not-a-real-command");
20 let result = initializer.initialize();
21
22 assert_eq!(true, result.is_ok());
23 assert_eq!(false, result.unwrap());
24 }
25
26 #[cfg(target_family = "windows")]
27 #[test]
28 fn it_returns_true_when_found() {
29 let initializer = CommandFound("cmd.exe");
30 let result = initializer.initialize();
31
32 assert_eq!(true, result.is_ok());
33 assert_eq!(true, result.unwrap());
34 }
35
36 #[cfg(target_family = "windows")]
37 #[test]
38 fn return_true_windows_xcopy() {
39 let initializer = CommandFound("Xcopy");
40 let result = initializer.initialize();
41
42 assert_eq!(true, result.is_ok());
43 assert_eq!(true, result.unwrap());
44 }
45
46 #[cfg(target_family = "unix")]
47 #[test]
48 fn it_returns_true_when_found() {
49 let initializer = CommandFound("ls");
50 let result = initializer.initialize();
51
52 assert_eq!(true, result.is_ok());
53 assert_eq!(true, result.unwrap());
54 }
55}