Skip to content

Commit f24d34f

Browse files
committed
add tests for all debug output variants and triggers
1 parent 0b5f098 commit f24d34f

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

tests/by-util/test_env.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use crate::common::util::expected_result;
99
use crate::common::util::TestScenario;
1010
use ::env::native_int_str::{Convert, NCvt};
11+
use regex::Regex;
1112
use std::env;
1213
use std::path::Path;
1314
use tempfile::tempdir;
@@ -55,6 +56,83 @@ fn test_if_windows_batch_files_can_be_executed() {
5556
assert!(result.stdout_str().contains("Hello Windows World!"));
5657
}
5758

59+
#[test]
60+
fn test_debug_1() {
61+
let ts = TestScenario::new(util_name!());
62+
let result = ts
63+
.ucmd()
64+
.arg("-v")
65+
.arg(&ts.bin_path)
66+
.args(&["sleep", "0.1"])
67+
.succeeds();
68+
result.stderr_matches(
69+
&Regex::new(concat!(
70+
r"executing: [^\n]+/coreutils(.exe)?\n arg\[0\]= '[^\n]+/coreutils(.exe)?'\n",
71+
r" arg\[1\]= 'sleep'\n arg\[2\]= '0.1'"
72+
))
73+
.unwrap(),
74+
);
75+
}
76+
77+
#[test]
78+
fn test_debug_2() {
79+
let ts = TestScenario::new(util_name!());
80+
let result = ts
81+
.ucmd()
82+
.arg("-vv")
83+
.arg(ts.bin_path)
84+
.args(&["sleep", "0.1"])
85+
.succeeds();
86+
result.stderr_matches(
87+
&Regex::new(concat!(
88+
r"input args:\narg\[0\]: 'env'\narg\[1\]: '-vv'\n",
89+
r"arg\[2\]: '[^\n]+\/coreutils(.exe)?'\narg\[3\]: 'sleep'\narg\[4\]: '0.1'\n",
90+
r"executing: [^\n]+\/coreutils(.exe)?\n arg\[0\]= '[^\n]+\/coreutils(.exe)?'\n",
91+
r" arg\[1\]= 'sleep'\n arg\[2\]= '0.1'"
92+
))
93+
.unwrap(),
94+
);
95+
}
96+
97+
#[test]
98+
fn test_debug1_part_of_string_arg() {
99+
let ts = TestScenario::new(util_name!());
100+
101+
let result = ts
102+
.ucmd()
103+
.arg("-vS FOO=BAR")
104+
.arg(ts.bin_path)
105+
.args(&["sleep", "0.1"])
106+
.succeeds();
107+
result.stderr_matches(
108+
&Regex::new(concat!(
109+
r"executing: [^\n]+/coreutils(.exe)?\n arg\[0\]= '[^\n]+/coreutils(.exe)?'\n",
110+
r" arg\[1\]= 'sleep'\n arg\[2\]= '0.1'"
111+
))
112+
.unwrap(),
113+
);
114+
}
115+
116+
#[test]
117+
fn test_debug2_part_of_string_arg() {
118+
let ts = TestScenario::new(util_name!());
119+
let result = ts
120+
.ucmd()
121+
.arg("-vvS FOO=BAR")
122+
.arg(ts.bin_path)
123+
.args(&["sleep", "0.1"])
124+
.succeeds();
125+
result.stderr_matches(
126+
&Regex::new(concat!(
127+
r"input args:\narg\[0\]: 'env'\narg\[1\]: '-vvS FOO=BAR'\n",
128+
r"arg\[2\]: '[^\n]+\/coreutils(.exe)?'\narg\[3\]: 'sleep'\narg\[4\]: '0.1'\n",
129+
r"executing: [^\n]+\/coreutils(.exe)?\n arg\[0\]= '[^\n]+\/coreutils(.exe)?'\n",
130+
r" arg\[1\]= 'sleep'\n arg\[2\]= '0.1'"
131+
))
132+
.unwrap(),
133+
);
134+
}
135+
58136
#[test]
59137
fn test_file_option() {
60138
let out = new_ucmd!()

0 commit comments

Comments
 (0)