2024-06-16 02:15:36 -04:00
|
|
|
//! These tests are mostly here just to ensure that invalid results will be
|
|
|
|
//! caught when passing arguments.
|
2024-01-01 22:20:40 +00:00
|
|
|
|
2019-09-16 22:39:57 -04:00
|
|
|
use assert_cmd::prelude::*;
|
2019-09-14 22:29:40 -04:00
|
|
|
use predicates::prelude::*;
|
2024-01-15 04:19:18 -05:00
|
|
|
|
|
|
|
use crate::util::{btm_command, no_cfg_btm_command};
|
2019-12-30 22:39:49 -05:00
|
|
|
|
2019-09-14 22:29:40 -04:00
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_small_rate() {
|
2024-01-15 04:19:18 -05:00
|
|
|
btm_command(&["-C", "./tests/valid_configs/empty_config.toml"])
|
2020-02-29 17:07:47 -05:00
|
|
|
.arg("-r")
|
|
|
|
.arg("249")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
2024-07-19 02:51:50 -04:00
|
|
|
.stderr(predicate::str::contains("'--rate' must be greater"));
|
2019-09-14 22:29:40 -04:00
|
|
|
}
|
|
|
|
|
2020-03-08 22:19:57 -04:00
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_large_default_time() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-03-08 22:19:57 -04:00
|
|
|
.arg("-t")
|
|
|
|
.arg("18446744073709551616")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
2024-05-27 01:16:37 -04:00
|
|
|
.stderr(predicate::str::contains(
|
2024-07-19 02:51:50 -04:00
|
|
|
"'--default_time_value' was set with an invalid value",
|
2024-05-27 01:16:37 -04:00
|
|
|
));
|
2020-03-08 22:19:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_small_default_time() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-03-08 22:19:57 -04:00
|
|
|
.arg("-t")
|
|
|
|
.arg("900")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
|
|
|
.stderr(predicate::str::contains(
|
2024-07-19 02:51:50 -04:00
|
|
|
"'--default_time_value' must be greater",
|
2020-03-08 22:19:57 -04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_large_delta_time() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-03-08 22:19:57 -04:00
|
|
|
.arg("-d")
|
|
|
|
.arg("18446744073709551616")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
2024-07-19 02:51:50 -04:00
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
"'--time_delta' was set with an invalid value",
|
|
|
|
));
|
2020-03-08 22:19:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_small_delta_time() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-03-08 22:19:57 -04:00
|
|
|
.arg("-d")
|
|
|
|
.arg("900")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
2024-07-19 02:51:50 -04:00
|
|
|
.stderr(predicate::str::contains("'--time_delta' must be greater"));
|
2020-03-08 22:19:57 -04:00
|
|
|
}
|
|
|
|
|
2019-09-15 00:06:57 -04:00
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_large_rate() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-02-29 17:07:47 -05:00
|
|
|
.arg("-r")
|
|
|
|
.arg("18446744073709551616")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
2024-07-19 02:51:50 -04:00
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
"'--rate' was set with an invalid value",
|
|
|
|
));
|
2019-09-15 00:06:57 -04:00
|
|
|
}
|
|
|
|
|
2019-09-14 22:29:40 -04:00
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_negative_rate() {
|
2020-02-29 17:07:47 -05:00
|
|
|
// This test should auto fail due to how clap works
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-02-29 17:07:47 -05:00
|
|
|
.arg("-r")
|
|
|
|
.arg("-1000")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
2023-04-21 00:07:34 -04:00
|
|
|
.stderr(predicate::str::contains("unexpected argument"));
|
2019-09-14 22:29:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_invalid_rate() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-02-29 17:07:47 -05:00
|
|
|
.arg("-r")
|
|
|
|
.arg("100-1000")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
2024-07-19 02:51:50 -04:00
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
"'--rate' was set with an invalid value",
|
|
|
|
));
|
2019-09-14 22:29:40 -04:00
|
|
|
}
|
2020-03-03 01:02:54 -05:00
|
|
|
|
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_conflicting_temps() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-03-03 01:02:54 -05:00
|
|
|
.arg("-c")
|
|
|
|
.arg("-f")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
2022-03-07 22:53:02 -05:00
|
|
|
.stderr(predicate::str::contains("cannot be used with"));
|
2020-03-03 01:02:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_invalid_default_widget_1() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-04-01 20:31:43 -04:00
|
|
|
.arg("--default_widget_type")
|
|
|
|
.arg("fake_widget")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
2024-01-21 05:47:13 -05:00
|
|
|
.stderr(predicate::str::contains("invalid value"));
|
2020-04-01 20:31:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_invalid_default_widget_2() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-04-01 20:31:43 -04:00
|
|
|
.arg("--default_widget_type")
|
|
|
|
.arg("cpu")
|
|
|
|
.arg("--default_widget_count")
|
|
|
|
.arg("18446744073709551616")
|
2020-03-03 01:02:54 -05:00
|
|
|
.assert()
|
|
|
|
.failure()
|
2024-05-27 01:16:37 -04:00
|
|
|
.stderr(predicate::str::contains("number too large"));
|
2020-03-03 01:02:54 -05:00
|
|
|
}
|
2020-09-01 03:08:38 -04:00
|
|
|
|
|
|
|
#[test]
|
2021-02-15 14:12:43 -05:00
|
|
|
fn test_missing_default_widget_type() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2020-09-01 03:08:38 -04:00
|
|
|
.arg("--default_widget_count")
|
|
|
|
.arg("3")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
|
|
|
.stderr(predicate::str::contains(
|
2023-04-21 00:07:34 -04:00
|
|
|
"the following required arguments were not provided",
|
2020-09-01 03:08:38 -04:00
|
|
|
));
|
|
|
|
}
|
2022-05-01 17:15:54 -04:00
|
|
|
|
|
|
|
#[test]
|
2023-04-21 00:07:34 -04:00
|
|
|
#[cfg_attr(feature = "battery", ignore)]
|
2022-05-01 17:15:54 -04:00
|
|
|
fn test_battery_flag() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2023-06-13 05:25:20 +00:00
|
|
|
.arg("--battery")
|
|
|
|
.assert()
|
|
|
|
.failure()
|
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
"unexpected argument '--battery' found",
|
|
|
|
));
|
2023-04-21 00:07:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg_attr(feature = "gpu", ignore)]
|
|
|
|
fn test_gpu_flag() {
|
2024-01-15 04:19:18 -05:00
|
|
|
no_cfg_btm_command()
|
2024-08-15 00:22:47 +02:00
|
|
|
.arg("--disable_gpu")
|
2023-06-13 05:25:20 +00:00
|
|
|
.assert()
|
|
|
|
.failure()
|
|
|
|
.stderr(predicate::str::contains(
|
2024-08-15 00:22:47 +02:00
|
|
|
"unexpected argument '--disable_gpu' found",
|
2023-06-13 05:25:20 +00:00
|
|
|
));
|
2022-05-01 17:15:54 -04:00
|
|
|
}
|
2024-06-05 01:12:00 -04:00
|
|
|
|
|
|
|
/// Sanity test due to <https://github.com/ClementTsang/bottom/pull/1478>.
|
|
|
|
#[test]
|
|
|
|
fn test_version() {
|
|
|
|
btm_command(&["--version"]).assert().success();
|
|
|
|
btm_command(&["-V"]).assert().success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sanity test due to <https://github.com/ClementTsang/bottom/pull/1478>.
|
|
|
|
#[test]
|
|
|
|
fn test_help() {
|
|
|
|
btm_command(&["--help"]).assert().success();
|
|
|
|
btm_command(&["-h"]).assert().success();
|
|
|
|
}
|