forked from uutils/coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_who.rs
238 lines (211 loc) · 7.24 KB
/
test_who.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore (flags) runlevel mesg
use crate::common::util::{expected_result, TestScenario};
#[test]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
}
#[cfg(unix)]
#[test]
#[ignore = "issue #3219"]
fn test_count() {
let ts = TestScenario::new(util_name!());
for opt in ["-q", "--count", "--c"] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
}
#[cfg(unix)]
#[test]
fn test_boot() {
let ts = TestScenario::new(util_name!());
for opt in ["-b", "--boot", "--b"] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
}
#[cfg(unix)]
#[test]
#[ignore = "issue #3219"]
fn test_heading() {
let ts = TestScenario::new(util_name!());
for opt in ["-H", "--heading", "--head"] {
// allow whitespace variation
// * minor whitespace differences occur between platform built-in outputs;
// specifically number of TABs between "TIME" and "COMMENT" may be variant
let actual = ts.ucmd().arg(opt).succeeds().stdout_move_str();
let expect = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
println!("actual: {actual:?}");
println!("expect: {expect:?}");
let v_actual: Vec<&str> = actual.split_whitespace().collect();
let v_expect: Vec<&str> = expect.split_whitespace().collect();
assert_eq!(v_actual, v_expect);
}
}
#[cfg(unix)]
#[test]
#[ignore = "issue #3219"]
fn test_short() {
let ts = TestScenario::new(util_name!());
for opt in ["-s", "--short", "--s"] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
}
#[cfg(unix)]
#[test]
fn test_login() {
let ts = TestScenario::new(util_name!());
for opt in ["-l", "--login", "--log"] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
}
#[cfg(unix)]
#[test]
fn test_m() {
let ts = TestScenario::new(util_name!());
let expected_stdout = unwrap_or_return!(expected_result(&ts, &["-m"])).stdout_move_str();
ts.ucmd().arg("-m").succeeds().stdout_is(expected_stdout);
}
#[cfg(unix)]
#[test]
fn test_process() {
let ts = TestScenario::new(util_name!());
for opt in ["-p", "--process", "--p"] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
}
#[cfg(unix)]
#[test]
fn test_runlevel() {
let ts = TestScenario::new(util_name!());
for opt in ["-r", "--runlevel", "--r"] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
#[cfg(not(target_os = "linux"))]
ts.ucmd().arg(opt).succeeds().stdout_is("");
}
}
#[cfg(unix)]
#[test]
fn test_time() {
let ts = TestScenario::new(util_name!());
for opt in ["-t", "--time", "--t"] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
}
#[cfg(unix)]
#[test]
#[ignore = "issue #3219"]
fn test_mesg() {
// -T, -w, --mesg
// add user's message status as +, - or ?
// --message
// same as -T
// --writable
// same as -T
let ts = TestScenario::new(util_name!());
for opt in [
"-T",
"-w",
"--mesg",
"--m",
"--message",
"--writable",
"--w",
] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
}
#[cfg(unix)]
#[test]
fn test_arg1_arg2() {
let args = ["am", "i"];
let ts = TestScenario::new(util_name!());
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
}
#[test]
fn test_too_many_args() {
const EXPECTED: &str =
"error: unexpected value 'u' for '[FILE]...' found; no more were expected";
let args = ["am", "i", "u"];
new_ucmd!().args(&args).fails().stderr_contains(EXPECTED);
}
#[cfg(unix)]
#[test]
#[ignore = "issue #3219"]
fn test_users() {
let ts = TestScenario::new(util_name!());
for opt in ["-u", "--users", "--us"] {
let actual = ts.ucmd().arg(opt).succeeds().stdout_move_str();
let expect = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
println!("actual: {actual:?}");
println!("expect: {expect:?}");
let mut v_actual: Vec<&str> = actual.split_whitespace().collect();
let mut v_expect: Vec<&str> = expect.split_whitespace().collect();
// TODO: `--users` sometimes differs from GNU's output on macOS (race condition?)
// actual: "runner console Jun 23 06:37 00:34 196\n"
// expect: "runner console Jun 23 06:37 old 196\n"
if cfg!(target_os = "macos") {
v_actual.remove(5);
v_expect.remove(5);
}
assert_eq!(v_actual, v_expect);
}
}
#[cfg(unix)]
#[test]
#[ignore = "issue #3219"]
fn test_lookup() {
let opt = "--lookup";
let ts = TestScenario::new(util_name!());
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
#[cfg(unix)]
#[test]
fn test_dead() {
let ts = TestScenario::new(util_name!());
for opt in ["-d", "--dead", "--de"] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
}
#[cfg(unix)]
#[test]
#[ignore = "issue #3219"]
fn test_all_separately() {
if cfg!(target_os = "macos") {
// TODO: fix `-u`, see: test_users
return;
}
// -a, --all same as -b -d --login -p -r -t -T -u
let args = ["-b", "-d", "--login", "-p", "-r", "-t", "-T", "-u"];
let ts = TestScenario::new(util_name!());
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
let expected_stdout = unwrap_or_return!(expected_result(&ts, &["--all"])).stdout_move_str();
ts.ucmd().arg("--all").succeeds().stdout_is(expected_stdout);
}
#[cfg(unix)]
#[test]
#[ignore = "issue #3219"]
fn test_all() {
if cfg!(target_os = "macos") {
// TODO: fix `-u`, see: test_users
return;
}
let ts = TestScenario::new(util_name!());
for opt in ["-a", "--all", "--a"] {
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
}
}