Skip to content

Commit 91f48aa

Browse files
committed
vmstat: more tests
1 parent 11ce7fa commit 91f48aa

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/by-util/test_vmstat.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6+
use std::time::Duration;
67
use uutests::new_ucmd;
78
use uutests::util::TestScenario;
89
use uutests::util_name;
@@ -17,6 +18,12 @@ fn test_invalid_arg() {
1718
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
1819
}
1920

21+
#[test]
22+
fn test_invalid_number() {
23+
new_ucmd!().arg("-1").fails().code_is(1);
24+
new_ucmd!().arg("0").fails().code_is(1);
25+
}
26+
2027
#[test]
2128
fn test_unit() {
2229
new_ucmd!().args(&["-S", "M"]).succeeds();
@@ -27,3 +34,37 @@ fn test_unit() {
2734
fn test_invalid_unit() {
2835
new_ucmd!().args(&["-S", "x"]).fails().code_is(1);
2936
}
37+
38+
#[test]
39+
#[cfg(target_os = "linux")]
40+
fn test_header() {
41+
let result = new_ucmd!().succeeds();
42+
assert!(result.stdout_str().starts_with("procs"));
43+
}
44+
45+
#[test]
46+
#[cfg(target_os = "linux")]
47+
fn test_wide_mode() {
48+
let result = new_ucmd!().arg("-w").succeeds();
49+
assert!(result.stdout_str().starts_with("--procs--"));
50+
}
51+
52+
#[test]
53+
#[cfg(target_os = "linux")]
54+
fn test_no_first() {
55+
let time = std::time::Instant::now();
56+
new_ucmd!().arg("-y").succeeds();
57+
assert!(time.elapsed() >= Duration::from_secs(1));
58+
}
59+
60+
#[test]
61+
#[cfg(target_os = "linux")]
62+
fn test_active() {
63+
let result = new_ucmd!().arg("-a").succeeds();
64+
assert!(result
65+
.stdout_str()
66+
.lines()
67+
.nth(1)
68+
.unwrap()
69+
.contains("active"));
70+
}

0 commit comments

Comments
 (0)