2019-08-08 19:25:30 +02:00
|
|
|
use ansi_term::Color;
|
|
|
|
use std::io;
|
|
|
|
|
|
|
|
use crate::common::{self, TestCommand};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn config_blank_duration_1s() -> io::Result<()> {
|
|
|
|
let output = common::render_module("cmd_duration")
|
2019-12-19 23:38:06 +01:00
|
|
|
.arg("--cmd-duration=1000")
|
2019-08-08 19:25:30 +02:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2019-09-25 10:13:58 +02:00
|
|
|
let expected = "";
|
2019-08-08 19:25:30 +02:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn config_blank_duration_5s() -> io::Result<()> {
|
|
|
|
let output = common::render_module("cmd_duration")
|
2019-12-19 23:38:06 +01:00
|
|
|
.arg("--cmd-duration=5000")
|
2019-08-08 19:25:30 +02:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 08:15:08 +01:00
|
|
|
let expected = format!("took {} ", Color::Yellow.bold().paint("5s"));
|
2019-08-08 19:25:30 +02:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn config_5s_duration_3s() -> io::Result<()> {
|
|
|
|
let output = common::render_module("cmd_duration")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[cmd_duration]
|
2019-12-19 23:38:06 +01:00
|
|
|
min_time = 5000
|
2019-08-08 19:25:30 +02:00
|
|
|
})
|
2019-12-19 23:38:06 +01:00
|
|
|
.arg("--cmd-duration=3000")
|
2019-08-08 19:25:30 +02:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2019-09-25 10:13:58 +02:00
|
|
|
let expected = "";
|
2019-08-08 19:25:30 +02:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn config_5s_duration_10s() -> io::Result<()> {
|
|
|
|
let output = common::render_module("cmd_duration")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[cmd_duration]
|
2019-12-19 23:38:06 +01:00
|
|
|
min_time = 5000
|
2019-08-08 19:25:30 +02:00
|
|
|
})
|
2019-12-19 23:38:06 +01:00
|
|
|
.arg("--cmd-duration=10000")
|
2019-08-08 19:25:30 +02:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 08:15:08 +01:00
|
|
|
let expected = format!("took {} ", Color::Yellow.bold().paint("10s"));
|
2019-08-08 19:25:30 +02:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-09-30 07:26:32 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn config_1s_duration_prefix_underwent() -> io::Result<()> {
|
|
|
|
let output = common::render_module("cmd_duration")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[cmd_duration]
|
|
|
|
prefix = "underwent "
|
|
|
|
})
|
2019-12-19 23:38:06 +01:00
|
|
|
.arg("--cmd-duration=1000")
|
2019-09-30 07:26:32 +02:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = "";
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn config_5s_duration_prefix_underwent() -> io::Result<()> {
|
|
|
|
let output = common::render_module("cmd_duration")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[cmd_duration]
|
|
|
|
prefix = "underwent "
|
|
|
|
})
|
2019-12-19 23:38:06 +01:00
|
|
|
.arg("--cmd-duration=5000")
|
2019-09-30 07:26:32 +02:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2020-01-18 08:15:08 +01:00
|
|
|
let expected = format!("underwent {} ", Color::Yellow.bold().paint("5s"));
|
2019-09-30 07:26:32 +02:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|