Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Apr 2, 2018
1 parent eb6bdba commit 2d05caa
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,37 @@ fn run_opt(opt: &Opt) -> Result<()> {
mod tests {
use super::*;

pub static TEST_CONFIG: &'static str = r#"
[[formats]]
name = "Default"
pat = ".*"
[[formats.lines]]
pat = "A(.*) (.*) (.*)"
colors = ["Black", "Blue", "Cyan", "Default"]
[[formats.lines.tokens]]
pat = "A"
colors = ["Green"]
[[formats.lines]]
pat = "B(.*) (.*) (.*)"
colors = ["LightBlack", "LightBlue", "LightCyan", "LightGreen"]
tokens = []
[[formats.lines]]
pat = "C(.*) (.*) (.*)"
colors = ["LightMagenta", "LightRed", "LightWhite", "LightYellow"]
tokens = []
[[formats.lines]]
pat = "D(.*) (.*) (.*)"
colors = ["Magenta", "Red", "White", "Yellow"]
tokens = []
"#;

pub static TEST_DATA: &'static str = r#"
A123 456 789 xyz
B123 456 789 xyz
C123 456 789 xyz
D123 456 789 xyz
"#;

#[test]
fn test_run() {
let args = vec!["pipecolor", "-c", "sample/pipecolor.toml", "sample/access_log", "sample/maillog"];
Expand All @@ -325,4 +356,14 @@ mod tests {
let ret = run_opt(&opt);
assert!(ret.is_err());
}

#[test]
fn test_output() {
let args = vec!["pipecolor"];
let opt = Opt::from_iter(args.iter());
let config: Config = toml::from_str(TEST_CONFIG).unwrap();
let mut reader = BufReader::new(TEST_DATA.as_bytes());
let mut writer = BufWriter::new(stdout());
output(&mut reader, writer.get_mut(), &config, &opt);
}
}

0 comments on commit 2d05caa

Please sign in to comment.