Skip to content

Commit

Permalink
w: run part of tests only if in terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed May 14, 2024
1 parent 9a68d92 commit 76cc4eb
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tests/by-util/test_w.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ fn test_no_header() {
// As of now, --short is only implemented for Linux
#[cfg(target_os = "linux")]
fn test_option_short() {
use std::io::IsTerminal;

use regex::Regex;
let cmd = new_ucmd!().arg("--short").succeeds();

Expand All @@ -35,17 +37,19 @@ fn test_option_short() {
assert!(line_output_header.contains("USER\tTTY\tIDLE\tWHAT"));
assert!(!line_output_header.contains("USER\tTTY\tLOGIN@\tIDLE\tJCPU\tPCPU\tWHAT"));

let pattern: Vec<Regex> = vec![
Regex::new(r"^(\S+)").unwrap(), // USER
Regex::new(r"(\S+)").unwrap(), // TERMINAL
Regex::new(r"(^$)").unwrap(), // IDLE_TIME => empty str until IDLE_TIME implemented
Regex::new(r"(\d+\.\d+s)?").unwrap(), // COMMAND
];
if std::io::stdout().is_terminal() {
let pattern: Vec<Regex> = vec![
Regex::new(r"^(\S+)").unwrap(), // USER
Regex::new(r"(\S+)").unwrap(), // TERMINAL
Regex::new(r"(^$)").unwrap(), // IDLE_TIME => empty str until IDLE_TIME implemented
Regex::new(r"(\d+\.\d+s)?").unwrap(), // COMMAND
];

assert!(pattern[0].is_match(line_output_data_words[0]));
assert!(pattern[1].is_match(line_output_data_words[1]));
assert!(pattern[2].is_match(line_output_data_words[2]));
assert!(pattern[3].is_match(line_output_data_words[3]));
assert!(pattern[0].is_match(line_output_data_words[0]));
assert!(pattern[1].is_match(line_output_data_words[1]));
assert!(pattern[2].is_match(line_output_data_words[2]));
assert!(pattern[3].is_match(line_output_data_words[3]));
}
}

#[test]
Expand Down

0 comments on commit 76cc4eb

Please sign in to comment.