Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spezifisch committed Aug 3, 2024
1 parent 387036e commit e1de5f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn parse_non_negative_f64(src: &str) -> Result<f64, String> {
fn parse_positive_u64(src: &str) -> Result<u64, String> {
let val: u64 = src
.parse()
.map_err(|_| format!("`{}` is not a valid number", src))?;
.map_err(|_| format!("`{}` is not a valid number > 0", src))?;
if val == 0 {
Err(format!("`{}` must be greater than 0", src))
} else {
Expand Down
24 changes: 17 additions & 7 deletions tests/command_line_options_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
mod command_line_options_tests {
use clap::Parser;
use ifstat_rs::opts::Opts;
use tokio::sync::broadcast::error;

#[test]
fn test_valid_command_line_options() {
Expand Down Expand Up @@ -72,13 +71,13 @@ mod command_line_options_tests {
fn test_first_measurement_negative_should_fail() {
let result = Opts::try_parse_from(&[
"ifstat-rs",
"--first-measurement=-1",
"1", // Delay
"--first-measurement=-1",
]);
assert!(result.is_err());
let error_message = format!("{}", result.err().unwrap());
assert!(
error_message.contains("`-1` must be greater than or equal to 0"),
error_message.contains("must be greater than or equal to 0"),
"errmsg={}",
error_message
);
Expand All @@ -89,24 +88,35 @@ mod command_line_options_tests {
let result = Opts::try_parse_from(&[
"ifstat-rs",
"1", // Delay
"--count",
"0", // Count
]);
assert!(result.is_err());
let error_message = format!("{}", result.err().unwrap());
assert!(error_message.contains("`0` must be greater than 0"));
assert!(error_message.contains("must be greater than 0"));
}

#[test]
fn test_count_negative_unescaped_should_fail() {
let result = Opts::try_parse_from(&[
"ifstat-rs",
"1", // Delay
"-1", // Count
]);
assert!(result.is_err());
let error_message = format!("{}", result.err().unwrap());
assert!(error_message.contains("unexpected argument '-1'"));
}

#[test]
fn test_count_negative_should_fail() {
let result = Opts::try_parse_from(&[
"ifstat-rs",
"1", // Delay
"--count",
"--",
"-1", // Count
]);
assert!(result.is_err());
let error_message = format!("{}", result.err().unwrap());
assert!(error_message.contains("`-1` must be greater than 0"));
assert!(error_message.contains("not a valid number > 0"));
}
}

0 comments on commit e1de5f7

Please sign in to comment.