From 4453eaaa393988ba7920f52618190fc75f22fecf Mon Sep 17 00:00:00 2001 From: ClementTsang <34804052+ClementTsang@users.noreply.github.com> Date: Thu, 8 Feb 2024 22:49:24 -0500 Subject: start working on default config gen --- sample_configs/default_config.toml | 1 - src/constants.rs | 234 -------------------------------- src/options/args.rs | 83 ++++++----- src/options/config.rs | 44 +++++- src/options/config/battery.rs | 8 ++ src/options/config/cpu.rs | 13 ++ src/options/config/general.rs | 61 +++++++++ src/options/config/gpu.rs | 8 ++ src/options/config/memory.rs | 8 ++ src/options/config/network.rs | 8 ++ src/options/config/process.rs | 14 ++ src/options/config/style.rs | 8 ++ src/options/config/temperature.rs | 8 ++ tests/integration/valid_config_tests.rs | 21 ++- 14 files changed, 222 insertions(+), 297 deletions(-) diff --git a/sample_configs/default_config.toml b/sample_configs/default_config.toml index 578c33ca..8b137891 100644 --- a/sample_configs/default_config.toml +++ b/sample_configs/default_config.toml @@ -1,2 +1 @@ -# TODO: FIX THIS diff --git a/src/constants.rs b/src/constants.rs index 76c0fd37..26c08c9b 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -257,240 +257,6 @@ pub const DEFAULT_BATTERY_LAYOUT: &str = r#" default=true "#; -// Config and flags -pub const DEFAULT_CONFIG_FILE_PATH: &str = "bottom/bottom.toml"; - -// TODO: Eventually deprecate this, or grab from a file. -// TODO: FIX THIS! -pub const CONFIG_TEXT: &str = r#"# This is a default config file for bottom. All of the settings are commented -# out by default; if you wish to change them uncomment and modify as you see -# fit. - -# This group of options represents a command-line option. Flags explicitly -# added when running (ie: btm -a) will override this config file if an option -# is also set here. -[flags] -# Whether to hide the average cpu entry. -#hide_avg_cpu = false -# Whether to use dot markers rather than braille. -#dot_marker = false -# The update rate of the application. -#rate = "1s" -# Whether to put the CPU legend to the left. -#left_legend = false -# Whether to set CPU% on a process to be based on the total CPU or just current usage. -#current_usage = false -# Whether to set CPU% on a process to be based on the total CPU or per-core CPU% (not divided by the number of cpus). -#unnormalized_cpu = false -# Whether to group processes with the same name together by default. -#group_processes = false -# Whether to make process searching case sensitive by default. -#case_sensitive = false -# Whether to make process searching look for matching the entire word by default. -#whole_word = false -# Whether to make process searching use regex by default. -#regex = false -# Defaults to Celsius. Temperature is one of: -#temperature_type = "k" -#temperature_type = "f" -#temperature_type = "c" -#temperature_type = "kelvin" -#temperature_type = "fahrenheit" -#temperature_type = "celsius" -# The default time interval (in milliseconds). -#default_time_value = "60s" -# The time delta on each zoom in/out action (in milliseconds). -#time_delta = 15000 -# Hides the time scale. -#hide_time = false -# Override layout default widget -#default_widget_type = "proc" -#default_widget_count = 1 -# Expand selected widget upon starting the app -#expanded_on_startup = true -# Use basic mode -#basic = false -# Use the old network legend style -#use_old_network_legend = false -# Remove space in tables -#hide_table_gap = false -# Show the battery widgets -#battery = false -# Disable mouse clicks -#disable_click = false -# Built-in themes. Valid values are "default", "default-light", "gruvbox", "gruvbox-light", "nord", "nord-light" -#color = "default" -# Show memory values in the processes widget as values by default -#mem_as_value = false -# Show tree mode by default in the processes widget. -#tree = false -# Shows an indicator in table widgets tracking where in the list you are. -#show_table_scroll_position = false -# Show processes as their commands by default in the process widget. -#process_command = false -# Displays the network widget with binary prefixes. -#network_use_binary_prefix = false -# Displays the network widget using bytes. -#network_use_bytes = false -# Displays the network widget with a log scale. -#network_use_log = false -# Hides advanced options to stop a process on Unix-like systems. -#disable_advanced_kill = false -# Shows GPU(s) information -#enable_gpu = false -# Shows cache and buffer memory -#enable_cache_memory = false -# How much data is stored at once in terms of time. -#retention = "10m" - -# These are flags around the process widget. -#[processes] -# The columns shown by the process widget. The following columns are supported: -# PID, Name, CPU%, Mem%, R/s, W/s, T.Read, T.Write, User, State, Time, GMem%, GPU% -#columns = ["PID", "Name", "CPU%", "Mem%", "R/s", "W/s", "T.Read", "T.Write", "User", "State", "GMEM%", "GPU%"] - -# [cpu] -# One of "all" (default), "average"/"avg" -# default = "average" - -# These are all the components that support custom theming. Note that colour support -# will depend on terminal support. -#[colors] # Uncomment if you want to use custom colors -# Represents the colour of table headers (processes, CPU, disks, temperature). -#table_header_color="LightBlue" -# Represents the colour of the label each widget has. -#widget_title_color="Gray" -# Represents the average CPU color. -#avg_cpu_color="Red" -# Represents the colour the core will use in the CPU legend and graph. -#cpu_core_colors=["LightMagenta", "LightYellow", "LightCyan", "LightGreen", "LightBlue", "LightRed", "Cyan", "Green", "Blue", "Red"] -# Represents the colour RAM will use in the memory legend and graph. -#ram_color="LightMagenta" -# Represents the colour SWAP will use in the memory legend and graph. -#swap_color="LightYellow" -# Represents the colour ARC will use in the memory legend and graph. -#arc_color="LightCyan" -# Represents the colour the GPU will use in the legend and graph. -#gpu_core_colors=["LightGreen", "LightBlue", "LightRed", "Cyan", "Green", "Blue", "Red"] -# Represents the colour rx will use in the network legend and graph. -#rx_color="LightCyan" -# Represents the colour tx will use in the network legend and graph. -#tx_color="LightGreen" -# Represents the colour of the border of unselected widgets. -#border_color="Gray" -# Represents the colour of the border of selected widgets. -#highlighted_border_color="LightBlue" -# Represents the colour of most text. -#text_color="Gray" -# Represents the colour of text that is selected. -#selected_text_color="Black" -# Represents the background colour of text that is selected. -#selected_bg_color="LightBlue" -# Represents the colour of the lines and text of the graph. -#graph_color="Gray" -# Represents the colours of the battery based on charge -#high_battery_color="green" -#medium_battery_color="yellow" -#low_battery_color="red" - -# Layout - layouts follow a pattern like this: -# [[row]] represents a row in the application. -# [[row.child]] represents either a widget or a column. -# [[row.child.child]] represents a widget. -# -# All widgets must have the type value set to one of ["cpu", "mem", "proc", "net", "temp", "disk", "empty"]. -# All layout components have a ratio value - if this is not set, then it defaults to 1. -# The default widget layout: -#[[row]] -# ratio=30 -# [[row.child]] -# type="cpu" -#[[row]] -# ratio=40 -# [[row.child]] -# ratio=4 -# type="mem" -# [[row.child]] -# ratio=3 -# [[row.child.child]] -# type="temp" -# [[row.child.child]] -# type="disk" -#[[row]] -# ratio=30 -# [[row.child]] -# type="net" -# [[row.child]] -# type="proc" -# default=true - - -# Filters - you can hide specific temperature sensors, network interfaces, and disks using filters. This is admittedly -# a bit hard to use as of now, and there is a planned in-app interface for managing this in the future: -#[disk_filter] -#is_list_ignored = true -#list = ["/dev/sda\\d+", "/dev/nvme0n1p2"] -#regex = true -#case_sensitive = false -#whole_word = false - -#[mount_filter] -#is_list_ignored = true -#list = ["/mnt/.*", "/boot"] -#regex = true -#case_sensitive = false -#whole_word = false - -#[temp_filter] -#is_list_ignored = true -#list = ["cpu", "wifi"] -#regex = false -#case_sensitive = false -#whole_word = false - -#[net_filter] -#is_list_ignored = true -#list = ["virbr0.*"] -#regex = true -#case_sensitive = false -#whole_word = false -"#; - -pub const CONFIG_TOP_HEAD: &str = r##"# This is bottom's config file. -# Values in this config file will change when changed in the interface. -# You can also manually change these values. -# Be aware that contents of this file will be overwritten if something is -# changed in the application; you can disable writing via the -# --no_write flag or no_write config option. - -"##; - -pub const CONFIG_DISPLAY_OPTIONS_HEAD: &str = r#" -# These options represent settings that affect how bottom functions. -# If a setting here corresponds to command-line option, then the flag will temporarily override -# the setting. -"#; - -pub const CONFIG_COLOUR_HEAD: &str = r#" -# These options represent colour values for various parts of bottom. Note that colour support -# will ultimately depend on the terminal - for example, the Terminal for macOS does NOT like -# custom colours and it may glitch out. -"#; - -pub const CONFIG_LAYOUT_HEAD: &str = r#" -# These options represent how bottom will lay out its widgets. Layouts follow a pattern like this: -# [[row]] represents a row in the application. -# [[row.child]] represents either a widget or a column. -# [[row.child.child]] represents a widget. -# -# All widgets must have the valid type value set to one of ["cpu", "mem", "proc", "net", "temp", "disk", "empty"]. -# All layout components have a ratio value - if this is not set, then it defaults to 1. -"#; - -pub const CONFIG_FILTER_HEAD: &str = r#" -# These options represent disabled entries for the temperature and disk widgets. -"#; - #[cfg(test)] mod test { use super::*; diff --git a/src/options/args.rs b/src/options/args.rs index ee80a42c..696ee9dd 100644 --- a/src/options/args.rs +++ b/src/options/args.rs @@ -30,6 +30,14 @@ const VERSION: &str = match option_env!("NIGHTLY_VERSION") { None => crate_version!(), }; +macro_rules! set_if_some { + ($name:ident, $curr:expr, $new:expr) => { + if $new.$name.is_some() { + $curr.$name = $new.$name.clone(); + } + }; +} + #[derive(Clone, Debug, Deserialize)] #[serde(untagged)] pub(crate) enum StringOrNum { @@ -136,6 +144,7 @@ pub(crate) struct GeneralArgs { If it doesn't exist, a default config file is created at the path. If no path is provided, the default config location will be used." )] + #[serde(skip)] pub(crate) config_location: Option, #[arg( @@ -143,8 +152,8 @@ pub(crate) struct GeneralArgs { long, value_name = "TIME", help = "Default time value for graphs.", - long_help = "The default time value for graphs. Takes a number in milliseconds or a human \ - duration (e.g. 60s). The minimum time is 30s, and the default is 60s." + long_help = "Default time value for graphs. Either a number in milliseconds or a 'human duration' \ + (e.g. 60s, 10m). Defaults to 60s, must be at least 30s." )] pub(crate) default_time_value: Option, @@ -177,6 +186,21 @@ pub(crate) struct GeneralArgs { #[arg( long, value_name = "WIDGET", + help = "Sets the default widget type. Use --help for more info.\n", // Newline to force the possible values to be on the next line. + long_help = indoc!{ + "Sets which widget type to use as the default widget. For the default \ + layout, this defaults to the 'process' widget. For a custom layout, it defaults \ + to the first widget it sees. + + For example, suppose we have a layout that looks like: + +-------------------+-----------------------+ + | CPU (1) | CPU (2) | + +---------+---------+-------------+---------+ + | Process | CPU (3) | Temperature | CPU (4) | + +---------+---------+-------------+---------+ + + Setting '--default_widget_type Temp' will make the temperature widget selected by default." + }, value_parser = [ "cpu", "mem", @@ -193,21 +217,6 @@ pub(crate) struct GeneralArgs { #[cfg(feature = "battery")] "battery", ], - help = "Sets the default widget type. Use --help for more info.\n", // Newline to force the possible values to be on the next line. - long_help = indoc!{ - "Sets which widget type to use as the default widget. For the default \ - layout, this defaults to the 'process' widget. For a custom layout, it defaults \ - to the first widget it sees. - - For example, suppose we have a layout that looks like: - +-------------------+-----------------------+ - | CPU (1) | CPU (2) | - +---------+---------+-------------+---------+ - | Process | CPU (3) | Temperature | CPU (4) | - +---------+---------+-------------+---------+ - - Setting '--default_widget_type Temp' will make the temperature widget selected by default." - } )] pub(crate) default_widget_type: Option, @@ -237,11 +246,7 @@ pub(crate) struct GeneralArgs { #[arg(long, help = "Hides spacing between table headers and entries.")] pub(crate) hide_table_gap: Option, - #[arg( - long, - help = "Hides the time scale.", - long_help = "Completely hides the time scale from being shown." - )] + #[arg(long, help = "Hides the time scale from being shown.")] pub(crate) hide_time: Option, #[arg( @@ -249,27 +254,23 @@ pub(crate) struct GeneralArgs { long, value_name = "TIME", help = "Sets how often data is refreshed.", - long_help = "Sets how often data is refreshed. Takes a number in milliseconds or a human-readable duration \ - (e.g. 5s). The minimum is 250ms, and defaults to 1000ms. Smaller values may result in higher \ - system usage by bottom." + long_help = "Sets how often data is refreshed. Either a number in milliseconds or a 'human duration' \ + (e.g. 1s, 1m). Defaults to 1s, must be at least 250ms. Smaller values may result in \ + higher system resource usage." )] pub(crate) rate: Option, #[arg( long, value_name = "TIME", - help = "The timespan of data stored.", - long_help = "How much data is stored at once in terms of time. Takes a number in milliseconds or a \ - human-readable duration (e.g. 20m), with a minimum of 1 minute. Note that higher values \ - will take up more memory. Defaults to 10 minutes." + help = "How far back data will be stored up to.", + long_help = "How far back data will be stored up to. Either a number in milliseconds or a 'human duration' \ + (e.g. 10m, 1h). Defaults to 10 minutes, and must be at least 1 minute. Larger values \ + may result in higher memory usage." )] pub(crate) retention: Option, - #[arg( - long, - help = "Shows the scroll position tracker in table widgets.", - long_help = "Shows the list scroll position tracker in the widget title for table widgets." - )] + #[arg(long, help = "Show the current item entry position for table widgets.")] pub(crate) show_table_scroll_position: Option, #[arg( @@ -277,20 +278,12 @@ pub(crate) struct GeneralArgs { long, value_name = "TIME", help = "The amount of time changed upon zooming.", - long_help = "The amount of time changed when zooming in/out. Takes a number in milliseconds or a \ - human-readable duration (e.g. 30s). The minimum is 1s, and defaults to 15s." + long_help = "How much time the x-axis shifts by each time you zoom in or out. Either a number in milliseconds \ + or a 'human duration' (e.g. 15s, 1m). Defaults to 15 seconds." )] pub(crate) time_delta: Option, } -macro_rules! set_if_some { - ($name:ident, $curr:expr, $new:expr) => { - if $new.$name.is_some() { - $curr.$name = $new.$name.clone(); - } - }; -} - impl GeneralArgs { pub(crate) fn merge(&mut self, other: &Self) { set_if_some!(autohide_time, self, other); @@ -318,7 +311,7 @@ pub(crate) struct ProcessArgs { short = 'S', long, help = "Enables case sensitivity by default.", - long_help = "When searching for a process, enables case sensitivity by default." + long_help = "Enables case sensitivity by default when searching for a process." )] pub(crate) case_sensitive: Option, diff --git a/src/options/config.rs b/src/options/config.rs index f57d613d..7c2e3d5d 100644 --- a/src/options/config.rs +++ b/src/options/config.rs @@ -13,6 +13,7 @@ pub mod temperature; use std::{fs, io::Write, path::PathBuf}; +use indoc::indoc; use serde::Deserialize; pub use style::*; @@ -27,11 +28,13 @@ use self::{ memory::MemoryConfig, network::NetworkConfig, process::ProcessConfig, temperature::TemperatureConfig, }; -use crate::{ - args::BottomArgs, - constants::{CONFIG_TEXT, DEFAULT_CONFIG_FILE_PATH}, - error, -}; +use crate::{args::BottomArgs, error}; + +pub const DEFAULT_CONFIG_FILE_PATH: &str = "bottom/bottom.toml"; + +pub(crate) trait DefaultConfig { + fn default_config() -> String; +} #[derive(Debug, Default, Deserialize)] pub struct ConfigV2 { @@ -85,6 +88,34 @@ impl ConfigV2 { } } +impl DefaultConfig for ConfigV2 { + fn default_config() -> String { + let mut str = String::default(); + + pub const CONFIG_TOP_HEAD: &str = indoc! {" + # This is bottom's config file. All of the settings are commented + # out by default; if you wish to change them, uncomment and modify the + # setting. Make sure to also comment out the relevant section header! + + "}; + + str.push_str(CONFIG_TOP_HEAD); + str.push_str(&GeneralConfig::default_config()); + str.push_str(&ProcessConfig::default_config()); + str.push_str(&TemperatureConfig::default_config()); + str.push_str(&CpuConfig::default_config()); + str.push_str(&MemoryConfig::default_config()); + str.push_str(&NetworkConfig::default_config()); + #[cfg(feature = "battery")] + str.push_str(&BatteryConfig::default_config()); + #[cfg(feature = "gpu")] + str.push_str(&GpuConfig::default_config()); + str.push_str(&StyleConfig::default_config()); + + str + } +} + /// Workaround as per https://github.com/serde-rs/serde/issues/1030 fn default_as_true() -> bool { true @@ -151,7 +182,8 @@ pub fn create_or_get_config(config_path: &Option) -> error::Result String { + todo!() + } +} diff --git a/src/options/config/cpu.rs b/src/options/config/cpu.rs index 71199704..0976dd6d 100644 --- a/src/options/config/cpu.rs +++ b/src/options/config/cpu.rs @@ -1,7 +1,10 @@ +use indoc::indoc; use serde::Deserialize; use crate::args::CpuArgs; +use super::DefaultConfig; + /// The default selection of the CPU widget. If the given selection is invalid, we will fall back to all. #[derive(Clone, Copy, Debug, Default, Deserialize)] #[serde(rename_all = "lowercase")] @@ -22,6 +25,16 @@ pub(crate) struct CpuConfig { pub(crate) default: CpuDefault, } +impl DefaultConfig for CpuConfig { + fn default_config() -> String { + let s = indoc! {r##" + + "##}; + + s.to_string() + } +} + #[cfg(test)] mod test { use super::*; diff --git a/src/options/config/general.rs b/src/options/config/general.rs index 758c3e08..1721d231 100644 --- a/src/options/config/general.rs +++ b/src/options/config/general.rs @@ -1,9 +1,70 @@ +use indoc::indoc; use serde::Deserialize; use crate::args::GeneralArgs; +use super::DefaultConfig; + #[derive(Clone, Debug, Default, Deserialize)] pub(crate) struct GeneralConfig { #[serde(flatten)] pub(crate) args: GeneralArgs, } + +impl DefaultConfig for GeneralConfig { + fn default_config() -> String { + let s = indoc! {r##" + # Temporarily shows the time scale in graphs. If time is disabled via --hide_time then this will + # have no effect. + # autohide_time = false + + # Hides graphs and uses a more basic look. + # basic = false + + # Default time value for graphs. Either a number in milliseconds or a 'human duration' + # (e.g. "60s", "10m"). Defaults to 60s, and must be at least 30s. + # default_time_value = "60s" + + # Sets the n'th selected default widget type as the default. Requires `default_widget_type` + # to be set to have any effect. + # default_widget_count = 1 + + # Sets which widget type to use as the default widget. + # default_widget_type = "process" + + # Disables mouse clicks. + # disable_click = false + + # Use a dot marker for graphs. + # dot_marker = false + + # Expand the default widget upon starting the app. No effect on basic mode. + # expanded = false + + # Hides spacing between table headers and entries. + # hide_table_gap = false + + # Hides the time scale from being shown. + # hide_time = false + + # Sets how often data is refreshed. Either a number in milliseconds or a 'human duration' + # (e.g. "1s", "1m"). Defaults to 1s, and must be at least 250ms. Smaller values may result in + # higher system resource usage. + # rate = "1s" + + # How far back data will be stored up to. Either a number in milliseconds or a 'human duration' + # (e.g. "10m", "1h"). Defaults to 10 minutes, and must be at least 1 minute. Larger values + # may result in higher memory usage. + # retention = "10m" + + # Show the current item entry position for table widgets. + # show_table_scroll_position = false + + # How much time the x-axis shifts by each time you zoom in or out. Either a number in milliseconds or + # a 'human duration' (e.g. "15s", "1m"). Defaults to 15 seconds. + # time_delta = "15s" + "##}; + + s.to_string() + } +} diff --git a/src/options/config/gpu.rs b/src/options/config/gpu.rs index 40b979fa..b71c0fc0 100644 --- a/src/options/config/gpu.rs +++ b/src/options/config/gpu.rs @@ -2,6 +2,8 @@ use serde::Deserialize; use crate::args::GpuArgs; +use super::DefaultConfig; + #[derive(Clone, Debug, Default, Deserialize)] pub(crate) struct GpuConfig { #[serde(flatten)] @@ -13,3 +15,9 @@ impl GpuConfig { self.args.enable_gpu.unwrap_or(false) } } + +impl DefaultConfig for GpuConfig { + fn default_config() -> String { + todo!() + } +} diff --git a/src/options/config/memory.rs b/src/options/config/memory.rs index c7c6ac8b..5a402085 100644 --- a/src/options/config/memory.rs +++ b/src/options/config/memory.rs @@ -2,8 +2,16 @@ use serde::Deserialize; use crate::args::MemoryArgs; +use super::DefaultConfig; + #[derive(Clone, Debug, Default, Deserialize)] pub(crate) struct MemoryConfig { #[serde(flatten)] pub(crate) args: MemoryArgs, } + +impl DefaultConfig for MemoryConfig { + fn default_config() -> String { + todo!() + } +} diff --git a/src/options/config/network.rs b/src/options/config/network.rs index 9723b997..0fa18162 100644 --- a/src/options/config/network.rs +++ b/src/options/config/network.rs @@ -2,8 +2,16 @@ use serde::Deserialize; use crate::args::NetworkArgs; +use super::DefaultConfig; + #[derive(Clone, Debug, Default, Deserialize)] pub(crate) struct NetworkConfig { #[serde(flatten)] pub(crate) args: NetworkArgs, } + +impl DefaultConfig for NetworkConfig { + fn default_config() -> String { + todo!() + } +} diff --git a/src/options/config/process.rs b/src/options/config/process.rs index c48ca044..c4ac66d4 100644 --- a/src/options/config/process.rs +++ b/src/options/config/process.rs @@ -1,7 +1,10 @@ +use indoc::indoc; use serde::Deserialize; use crate::{args::ProcessArgs, widgets::ProcWidgetColumn}; +use super::DefaultConfig; + /// Process column settings. #[derive(Clone, Debug, Default, Deserialize)] pub(crate) struct ProcessConfig { @@ -10,6 +13,17 @@ pub(crate) struct ProcessConfig { pub(crate) columns: Option>, } +impl DefaultConfig for ProcessConfig { + fn default_config() -> String { + let s = indoc! {r##" + # Enables case sensitivity by default when searching for a process. + # case_sensitive = false + "##}; + + s.to_string() + } +} + #[cfg(test)] mod test { use super::ProcessConfig; diff --git a/src/options/config/style.rs b/src/options/config/style.rs index 38d93500..6b9f9983 100644 --- a/src/options/config/style.rs +++ b/src/options/config/style.rs @@ -5,9 +5,17 @@ use serde::Deserialize; use crate::args::StyleArgs; +use super::DefaultConfig; + #[derive(Clone, Debug, Default, Deserialize)] pub(crate) struct StyleConfig { #[serde(flatten)] pub(crate) args: StyleArgs, // TODO: Maybe also put colours here? } + +impl DefaultConfig for StyleConfig { + fn default_config() -> String { + todo!() + } +} diff --git a/src/options/config/temperature.rs b/src/options/config/temperature.rs index 7ae359f9..6fce986f 100644 --- a/src/options/config/temperature.rs +++ b/src/options/config/temperature.rs @@ -2,9 +2,17 @@ use serde::Deserialize; use crate::args::TemperatureArgs; +use super::DefaultConfig; + #[derive(Clone, Debug, Default, Deserialize)] pub(crate) struct TemperatureConfig { #[serde(flatten)] pub(crate) args: TemperatureArgs, pub(crate) temperature_type: Option, } + +impl DefaultConfig for TemperatureConfig { + fn default_config() -> String { + todo!() + } +} diff --git a/tests/integration/valid_config_tests.rs b/tests/integration/valid_config_tests.rs index 687a1f4f..f4334223 100644 --- a/tests/integration/valid_config_tests.rs +++ b/tests/integration/valid_config_tests.rs @@ -1,9 +1,10 @@ //! Tests config files that have sometimes caused issues despite being valid. -use std::{io::Read, thread, time::Duration}; +use std::{io::Read, path::Path, thread, time::Duration}; use crate::util::spawn_btm_in_pty; +/// Convert a reader implementing [`Read`] into a string. fn reader_to_string(mut reader: Box) -> String { let mut buf = String::default(); reader.read_to_string(&mut buf).unwrap(); @@ -11,6 +12,7 @@ fn reader_to_string(mut reader: Box) -> String { buf } +/// Run bottom with the following args. fn run_and_kill(args: &[&str]) { let (master, mut handle) = spawn_btm_in_pty(args); let reader = master.try_clone_reader().unwrap(); @@ -36,6 +38,13 @@ fn run_and_kill(args: &[&str]) { handle.kill().unwrap(); } +// /// Run the binary with the config path only if the path exists. +// fn run_if_exists(config_path: &str) { +// if Path::new(config_path).exists() { +// run_and_kill(&["-C", config_path]); +// } +// } + #[test] fn test_basic() { run_and_kill(&[]); @@ -67,13 +76,3 @@ fn test_all_proc() { fn test_cpu_doughnut() { run_and_kill(&["-C", "./tests/valid_configs/cpu_doughnut.toml"]); } - -#[test] -fn test_default() { - run_and_kill(&["-C", "./sample_configs/default_config.toml"]); -} - -#[test] -fn test_demo() { - run_and_kill(&["-C", "./sample_configs/demo_config.toml"]); -} -- cgit v1.2.3