2019-08-08 17:25:30 +00: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-09-25 08:13:58 +00:00
|
|
|
.arg("--cmd-duration=1")
|
2019-08-08 17:25:30 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2019-09-25 08:13:58 +00:00
|
|
|
let expected = "";
|
2019-08-08 17:25:30 +00:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn config_blank_duration_5s() -> io::Result<()> {
|
|
|
|
let output = common::render_module("cmd_duration")
|
2019-09-25 08:13:58 +00:00
|
|
|
.arg("--cmd-duration=5")
|
2019-08-08 17:25:30 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = format!("{} ", Color::Yellow.bold().paint("took 5s"));
|
|
|
|
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-09-25 08:13:58 +00:00
|
|
|
min_time = 5
|
2019-08-08 17:25:30 +00:00
|
|
|
})
|
2019-09-25 08:13:58 +00:00
|
|
|
.arg("--cmd-duration=3")
|
2019-08-08 17:25:30 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
2019-09-25 08:13:58 +00:00
|
|
|
let expected = "";
|
2019-08-08 17:25:30 +00: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-09-25 08:13:58 +00:00
|
|
|
min_time = 5
|
2019-08-08 17:25:30 +00:00
|
|
|
})
|
2019-09-25 08:13:58 +00:00
|
|
|
.arg("--cmd-duration=10")
|
2019-08-08 17:25:30 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = format!("{} ", Color::Yellow.bold().paint("took 10s"));
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|