Skip to content

Commit 389a9f6

Browse files
committed
vmstat: more tests
1 parent 11ce7fa commit 389a9f6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/by-util/test_vmstat.rs

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

6+
#[cfg(target_os = "linux")]
7+
use std::time::Duration;
68
use uutests::new_ucmd;
79
use uutests::util::TestScenario;
810
use uutests::util_name;
@@ -17,6 +19,12 @@ fn test_invalid_arg() {
1719
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
1820
}
1921

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

0 commit comments

Comments
 (0)