mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-14 16:37:16 +00:00
dd66ae774c
* refactor: simplify some config -> constraints code * iteratively progress... * update bcr; this might need testing since I removed some old proc code * widget side * fix battery * fix widget tests with bandaid for now The issue was that the calculations assume a certain ratio for CPU legends. * add some tests * bump up * fix proc drawing issues So with the proc widget in certain places, there would be a panic during constraint determination. Looks like back when I wrote this I made some gross assumptions about certain things. In particular, the problem here was that the search added an additional "one" height, so that needs to be accounted for after we removed the "doubling" code. * tests * fix tests * reorganize tests * clippy * fix cross tests not working * fix builds for android
69 lines
1.7 KiB
Rust
69 lines
1.7 KiB
Rust
//! Tests config files that have sometimes caused issues despite being valid.
|
|
|
|
use std::{io::Read, thread, time::Duration};
|
|
|
|
use crate::util::spawn_btm_in_pty;
|
|
|
|
fn reader_to_string(mut reader: Box<dyn Read>) -> String {
|
|
let mut buf = String::default();
|
|
reader.read_to_string(&mut buf).unwrap();
|
|
|
|
buf
|
|
}
|
|
|
|
fn run_and_kill(args: &[&str]) {
|
|
let (master, mut handle) = spawn_btm_in_pty(args);
|
|
let reader = master.try_clone_reader().unwrap();
|
|
let _ = master.take_writer().unwrap();
|
|
|
|
const TIMES_CHECKED: u64 = 6; // Check 6 times, once every 500ms, for 3 seconds total.
|
|
|
|
for _ in 0..TIMES_CHECKED {
|
|
thread::sleep(Duration::from_millis(500));
|
|
match handle.try_wait() {
|
|
Ok(Some(exit)) => {
|
|
println!("output: {}", reader_to_string(reader));
|
|
panic!("program terminated unexpectedly (exit status: {exit:?})");
|
|
}
|
|
Err(e) => {
|
|
println!("output: {}", reader_to_string(reader));
|
|
panic!("error while trying to wait: {e}")
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
handle.kill().unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn test_basic() {
|
|
run_and_kill(&[]);
|
|
}
|
|
|
|
/// A test to ensure that a bad config will fail the `run_and_kill` function.
|
|
#[test]
|
|
#[should_panic]
|
|
fn test_bad_basic() {
|
|
run_and_kill(&["--this_does_not_exist"]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_empty() {
|
|
run_and_kill(&["-C", "./tests/valid_configs/empty_config.toml"]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_many_proc() {
|
|
run_and_kill(&["-C", "./tests/valid_configs/many_proc.toml"]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_all_proc() {
|
|
run_and_kill(&["-C", "./tests/valid_configs/all_proc.toml"]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_cpu_doughnut() {
|
|
run_and_kill(&["-C", "./tests/valid_configs/cpu_doughnut.toml"]);
|
|
}
|