Skip to content

Commit ce047e8

Browse files
sylvestrerivy
authored andcommitted
test(users): Introduce two tests
1 parent 94aa201 commit ce047e8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/test_users.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use common::util::*;
2+
use std::env;
3+
4+
#[test]
5+
fn test_users_noarg() {
6+
let (_, mut ucmd) = at_and_ucmd!();
7+
let result = ucmd.run();
8+
assert!(result.success);
9+
}
10+
#[test]
11+
fn test_users_check_name() {
12+
let result = TestScenario::new(util_name!()).ucmd_keepenv().run();
13+
assert!(result.success);
14+
15+
// Expectation: USER is often set
16+
let key = "USER";
17+
18+
match env::var(key) {
19+
Err(e) => println!("Key {} isn't set. Found {}", &key, e),
20+
Ok(username) =>
21+
// Check if "users" contains the name of the user
22+
{
23+
println!("username found {}", &username);
24+
println!("result.stdout {}", &result.stdout);
25+
if !&result.stdout.is_empty() {
26+
assert!(result.stdout.contains(&username))
27+
}
28+
}
29+
}
30+
}

tests/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ unix_only! {
3131
"stdbuf", test_stdbuf;
3232
"uname", test_uname;
3333
"unlink", test_unlink;
34+
"users", test_users;
3435
"who", test_who;
3536
// Be aware of the trailing semicolon after the last item
3637
"stat", test_stat

0 commit comments

Comments
 (0)