Debian Codegraph @

tests/integration/arg_tests.rs

raw symbols SCIP
1 //! These tests are mostly here just to ensure that invalid results will be
2 //! caught when passing arguments.
3
4 use assert_cmd::prelude::*;
5 use predicates::prelude::*;
6
7 use crate::util::{btm_command, no_cfg_btm_command};
8
9 #[test]
10 fn test_small_rate() {
11 btm_command(&["-C", "./tests/valid_configs/empty_config.toml"])
12 .arg("-r")
13 .arg("249")
14 .assert()
15 .failure()
16 .stderr(predicate::str::contains("'--rate' must be greater"));
17 }
18
19 #[test]
20 fn test_large_default_time() {
21 no_cfg_btm_command()
22 .arg("-t")
23 .arg("18446744073709551616")
24 .assert()
25 .failure()
26 .stderr(predicate::str::contains(
27 "'--default_time_value' was set with an invalid value",
28 ));
29 }
30
31 #[test]
32 fn test_small_default_time() {
33 no_cfg_btm_command()
34 .arg("-t")
35 .arg("900")
36 .assert()
37 .failure()
38 .stderr(predicate::str::contains(
39 "'--default_time_value' must be greater",
40 ));
41 }
42
43 #[test]
44 fn test_large_delta_time() {
45 no_cfg_btm_command()
46 .arg("-d")
47 .arg("18446744073709551616")
48 .assert()
49 .failure()
50 .stderr(predicate::str::contains(
51 "'--time_delta' was set with an invalid value",
52 ));
53 }
54
55 #[test]
56 fn test_small_delta_time() {
57 no_cfg_btm_command()
58 .arg("-d")
59 .arg("900")
60 .assert()
61 .failure()
62 .stderr(predicate::str::contains("'--time_delta' must be greater"));
63 }
64
65 #[test]
66 fn test_large_rate() {
67 no_cfg_btm_command()
68 .arg("-r")
69 .arg("18446744073709551616")
70 .assert()
71 .failure()
72 .stderr(predicate::str::contains(
73 "'--rate' was set with an invalid value",
74 ));
75 }
76
77 #[test]
78 fn test_negative_rate() {
79 // This test should auto fail due to how clap works
80 no_cfg_btm_command()
81 .arg("-r")
82 .arg("-1000")
83 .assert()
84 .failure()
85 .stderr(predicate::str::contains("unexpected argument"));
86 }
87
88 #[test]
89 fn test_invalid_rate() {
90 no_cfg_btm_command()
91 .arg("-r")
92 .arg("100-1000")
93 .assert()
94 .failure()
95 .stderr(predicate::str::contains(
96 "'--rate' was set with an invalid value",
97 ));
98 }
99
100 #[test]
101 fn test_conflicting_temps() {
102 no_cfg_btm_command()
103 .arg("-c")
104 .arg("-f")
105 .assert()
106 .failure()
107 .stderr(predicate::str::contains("cannot be used with"));
108 }
109
110 #[test]
111 fn test_invalid_default_widget_1() {
112 no_cfg_btm_command()
113 .arg("--default_widget_type")
114 .arg("fake_widget")
115 .assert()
116 .failure()
117 .stderr(predicate::str::contains("invalid value"));
118 }
119
120 #[test]
121 fn test_invalid_default_widget_2() {
122 no_cfg_btm_command()
123 .arg("--default_widget_type")
124 .arg("cpu")
125 .arg("--default_widget_count")
126 .arg("18446744073709551616")
127 .assert()
128 .failure()
129 .stderr(predicate::str::contains("number too large"));
130 }
131
132 #[test]
133 fn test_missing_default_widget_type() {
134 no_cfg_btm_command()
135 .arg("--default_widget_count")
136 .arg("3")
137 .assert()
138 .failure()
139 .stderr(predicate::str::contains(
140 "the following required arguments were not provided",
141 ));
142 }
143
144 #[test]
145 fn test_invalid_default_cpu_entry() {
146 no_cfg_btm_command()
147 .arg("--default_cpu_entry")
148 .arg("invalid")
149 .assert()
150 .failure()
151 .stderr(predicate::str::contains("possible values"));
152 }
153
154 #[test]
155 #[cfg_attr(feature = "battery", ignore)]
156 fn test_battery_flag() {
157 no_cfg_btm_command()
158 .arg("--battery")
159 .assert()
160 .failure()
161 .stderr(predicate::str::contains(
162 "unexpected argument '--battery' found",
163 ));
164 }
165
166 #[test]
167 #[cfg_attr(feature = "gpu", ignore)]
168 fn test_gpu_flag() {
169 no_cfg_btm_command()
170 .arg("--disable_gpu")
171 .assert()
172 .failure()
173 .stderr(predicate::str::contains(
174 "unexpected argument '--disable_gpu' found",
175 ));
176 }
177
178 /// Sanity test due to <https://github.com/ClementTsang/bottom/pull/1478>.
179 #[test]
180 fn test_version() {
181 btm_command(&["--version"]).assert().success();
182 btm_command(&["-V"]).assert().success();
183 }
184
185 /// Sanity test due to <https://github.com/ClementTsang/bottom/pull/1478>.
186 #[test]
187 fn test_help() {
188 btm_command(&["--help"]).assert().success();
189 btm_command(&["-h"]).assert().success();
190 }