1#[doc(hidden)]
43#[macro_use]
44mod macros;
45
46mod cargo;
47mod spawn;
48
49pub use crate::cargo::{get_cargo_bin, get_cargo_example};
50pub use crate::spawn::{Spawn, SpawnExt};
51
52#[allow(deprecated)]
53pub use crate::spawn::StdinCommand;
54
55pub use std::process::Command;
56
57#[doc(hidden)]
58pub mod _macro_support {
59 pub use super::spawn::Spawn;
60 pub use insta;
61}
62
63#[cfg(test)]
64fn echo_test_helper(msg: &str) -> Command {
65 #[cfg(windows)]
66 {
67 use std::os::windows::process::CommandExt;
68 let mut rv = Command::new("cmd.exe");
69 rv.arg("/c").arg("echo").raw_arg(msg);
70 rv
71 }
72 #[cfg(unix)]
73 {
74 let mut rv = Command::new("echo");
75 rv.arg(msg);
76 rv
77 }
78}
79
80#[cfg(test)]
81fn cat_test_helper() -> Command {
82 #[cfg(windows)]
83 {
84 use std::os::windows::process::CommandExt;
85 let mut rv = Command::new("cmd.exe");
86 rv.arg("/c").arg("find").arg("/v").raw_arg("\"\"");
87 rv
88 }
89 #[cfg(unix)]
90 {
91 Command::new("cat")
92 }
93}
94
95#[cfg(unix)]
96#[test]
97fn test_basic() {
98 assert_cmd_snapshot!(["/bin/echo", "Hello World"]);
99}
100
101#[test]
102fn test_command() {
103 assert_cmd_snapshot!(echo_test_helper("Just some stuff"));
104}
105
106#[test]
107fn test_env() {
108 assert_cmd_snapshot!(echo_test_helper("Just some stuff")
109 .env("K", "V")
110 .env("A", "B")
111 .env("Y", "Z"));
112}
113
114#[cfg(unix)]
115#[test]
116#[allow(deprecated)]
117fn test_stdin() {
118 assert_cmd_snapshot!(StdinCommand::new("cat", "Hello World!"));
119}
120
121#[test]
122fn test_pass_stdin() {
123 assert_cmd_snapshot!(cat_test_helper().pass_stdin("Hello World!\n"));
124}
125
126#[cfg(unix)]
127#[test]
128fn test_pass_stdin_on_array() {
129 assert_cmd_snapshot!(["cat"].pass_stdin("Hello World!"));
130}
131
132#[cfg(unix)]
133#[test]
134fn test_failure() {
135 assert_cmd_snapshot!(["false"]);
136}
137
138#[cfg(unix)]
139#[test]
140fn test_trailing_comma_one_arg() {
141 assert_cmd_snapshot!(["echo", "42"],);
142}
143
144#[test]
145fn test_trailing_comma_named_snapshot() {
146 assert_cmd_snapshot!("named_snapshot_with_trailing_comma", echo_test_helper("27"),);
147}
148
149#[cfg(unix)]
150#[test]
151fn test_trailing_comma_inline_snapshot() {
152 assert_cmd_snapshot!(
153 Command::new("true"),
154 @r###"
155 success: true
156 exit_code: 0
157 ----- stdout -----
158
159 ----- stderr -----
160 "###,
161 );
162}