Skip to content

Commit

Permalink
add test to check this in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Sep 12, 2024
1 parent 667f2d6 commit 0910147
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 7 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ filedescriptor = "0.8.2"
assert_cmd = "2.0.16"
cargo-husky = { version = "1.5.0", default-features = false, features = ["user-hooks"] }
predicates = "3.1.2"
tempfile = "3.12.0"

[target.'cfg(all(target_arch = "x86_64", target_os = "linux"))'.dev-dependencies]
portable-pty = "0.8.1"
Expand Down
4 changes: 2 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ pub(crate) const CONFIG_TEXT: &str = r#"# This is a default config file for bott
# How much data is stored at once in terms of time.
#retention = "10m"
# Where to place the legend for the memory widget. One of "none", "top-left", "top", "top-right", "left", "right", "bottom-left", "bottom", "bottom-right".
#memory_legend = "top-right"
#memory_legend = "TopRight"
# Where to place the legend for the network widget. One of "none", "top-left", "top", "top-right", "left", "right", "bottom-left", "bottom", "bottom-right".
#network_legend = "top-right"
#network_legend = "TopRight"
# Processes widget configuration
#[processes]
Expand Down
8 changes: 4 additions & 4 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,11 @@ fn get_network_legend_position(
let result = if let Some(s) = &args.network.network_legend {
match s.to_ascii_lowercase().trim() {
"none" => None,
position => Some(parse_config_value!(position.parse(), "network_legend")?),
position => Some(parse_arg_value!(position.parse(), "network_legend")?),
}
} else if let Some(flags) = &config.flags {
if let Some(legend) = &flags.network_legend {
Some(parse_arg_value!(legend.parse(), "network_legend")?)
Some(parse_config_value!(legend.parse(), "network_legend")?)
} else {
Some(LegendPosition::default())
}
Expand All @@ -978,11 +978,11 @@ fn get_memory_legend_position(
let result = if let Some(s) = &args.memory.memory_legend {
match s.to_ascii_lowercase().trim() {
"none" => None,
position => Some(parse_config_value!(position.parse(), "memory_legend")?),
position => Some(parse_arg_value!(position.parse(), "memory_legend")?),
}
} else if let Some(flags) = &config.flags {
if let Some(legend) = &flags.memory_legend {
Some(parse_arg_value!(legend.parse(), "memory_legend")?)
Some(parse_config_value!(legend.parse(), "memory_legend")?)
} else {
Some(LegendPosition::default())
}
Expand Down
50 changes: 49 additions & 1 deletion tests/integration/valid_config_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//! Tests config files that have sometimes caused issues despite being valid.
use std::{io::Read, thread, time::Duration};
use std::{
io::{Read, Write},
thread,
time::Duration,
};

use regex::Regex;

use crate::util::spawn_btm_in_pty;

Expand Down Expand Up @@ -53,6 +59,48 @@ fn test_empty() {
run_and_kill(&["-C", "./tests/valid_configs/empty_config.toml"]);
}

#[test]
fn test_default() {
// Take the default config file and uncomment everything.
let default_config = match std::fs::File::open("./sample_configs/default_config.toml") {
Ok(mut default_config_file) => {
let mut buf = String::new();
default_config_file
.read_to_string(&mut buf)
.expect("can read file");

buf
}
Err(err) => {
println!("Could not open default config, skipping test_default: {err:?}");
return;
}
};

let default_config = Regex::new(r"(?m)^#([a-zA-Z\[])")
.unwrap()
.replace_all(&default_config, "$1");

let default_config = Regex::new(r"(?m)^#(\s\s+)([a-zA-Z\[])")
.unwrap()
.replace_all(&default_config, "$2");

let Ok(mut uncommented_config) = tempfile::NamedTempFile::new() else {
println!("Could not create a temp file, skipping test_default.");
return;
};

if uncommented_config
.write_all(default_config.as_bytes())
.is_err()
{
println!("Could not write to temp file, skipping test_default.");
return;
}

run_and_kill(&["-C", &uncommented_config.path().to_string_lossy()]);
}

#[test]
fn test_many_proc() {
run_and_kill(&["-C", "./tests/valid_configs/many_proc.toml"]);
Expand Down

0 comments on commit 0910147

Please sign in to comment.