mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-21 12:45:05 +02:00
bug: fix broken check from last commit, add tests
This commit is contained in:
parent
d24a797ce9
commit
663ae6c5c2
@ -1,2 +1,7 @@
|
|||||||
echo "Running pre-push hook: cargo +nightly clippy -- -D clippy::all"
|
echo "Running pre-push hook:"
|
||||||
|
|
||||||
|
echo "Executing: cargo +nightly clippy -- -D clippy::all"
|
||||||
cargo +nightly clippy -- -D clippy::all
|
cargo +nightly clippy -- -D clippy::all
|
||||||
|
|
||||||
|
echo "Executing: cargo test"
|
||||||
|
cargo test
|
@ -592,30 +592,33 @@ fn get_default_widget_and_count(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
if widget_type.is_some() {
|
|
||||||
let widget_count = if let Some(widget_count) = matches.value_of("DEFAULT_WIDGET_COUNT") {
|
let widget_count = if let Some(widget_count) = matches.value_of("DEFAULT_WIDGET_COUNT") {
|
||||||
widget_count.parse::<u128>()?
|
Some(widget_count.parse::<u128>()?)
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(widget_count) = flags.default_widget_count {
|
if let Some(widget_count) = flags.default_widget_count {
|
||||||
widget_count as u128
|
Some(widget_count as u128)
|
||||||
} else {
|
} else {
|
||||||
1 as u128
|
None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
1 as u128
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
match (widget_type, widget_count) {
|
||||||
|
(Some(widget_type), Some(widget_count)) => {
|
||||||
if widget_count > std::u64::MAX as u128 {
|
if widget_count > std::u64::MAX as u128 {
|
||||||
Err(BottomError::ConfigError(
|
Err(BottomError::ConfigError(
|
||||||
"set your widget count to be at most unsigned INT_MAX.".to_string(),
|
"set your widget count to be at most unsigned INT_MAX.".to_string(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok((widget_type, widget_count as u64))
|
Ok((Some(widget_type), widget_count as u64))
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
Err(BottomError::ConfigError(
|
(Some(widget_type), None) => Ok((Some(widget_type), 1)),
|
||||||
|
(None, Some(_widget_count)) => Err(BottomError::ConfigError(
|
||||||
"cannot set 'default_widget_count' by itself, it must be used with 'default_widget_type'.".to_string(),
|
"cannot set 'default_widget_count' by itself, it must be used with 'default_widget_type'.".to_string(),
|
||||||
))
|
)),
|
||||||
|
(None, None) => Ok((None, 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,3 +156,17 @@ fn test_invalid_default_widget_2() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_missing_default_widget_type() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
Command::new(get_binary_location())
|
||||||
|
.arg("--default_widget_count")
|
||||||
|
.arg("3")
|
||||||
|
.assert()
|
||||||
|
.failure()
|
||||||
|
.stderr(predicate::str::contains(
|
||||||
|
"The following required arguments were not provided",
|
||||||
|
));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -147,3 +147,14 @@ fn test_empty_battery() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
));
|
));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid_default_widget_count() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
Command::new(get_binary_location())
|
||||||
|
.arg("-C")
|
||||||
|
.arg("./tests/invalid_configs/invalid_default_widget_count.toml")
|
||||||
|
.assert()
|
||||||
|
.failure()
|
||||||
|
.stderr(predicate::str::contains("it must be used with"));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
2
tests/invalid_configs/invalid_default_widget_count.toml
Normal file
2
tests/invalid_configs/invalid_default_widget_count.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[flags]
|
||||||
|
default_widget_count = 3
|
Loading…
x
Reference in New Issue
Block a user