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