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