From 409660b07ba75e6773441a630f9c26eba9dea1da Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 12 Oct 2019 16:34:21 +0200 Subject: [PATCH] Add test: check whether default configuration is added when imag-init is called Signed-off-by: Matthias Beyer --- tests/ui/Cargo.toml | 13 +++++++------ tests/ui/src/imag_init.rs | 31 +++++++++++++++++++++++++++++++ tests/ui/src/lib.rs | 1 + 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/tests/ui/Cargo.toml b/tests/ui/Cargo.toml index d5595ca0..44f2d8d7 100644 --- a/tests/ui/Cargo.toml +++ b/tests/ui/Cargo.toml @@ -10,9 +10,10 @@ edition = "2018" publish = false [dependencies] -assert_cmd = "0.11" -assert_fs = "0.11" -duct = "0.13" -env_logger = "0.7" -log = "0.4" -predicates = "1" +assert_cmd = "0.11" +assert_fs = "0.11" +duct = "0.13" +env_logger = "0.7" +log = "0.4" +predicates = "1" +pretty_assertions = "0.6" diff --git a/tests/ui/src/imag_init.rs b/tests/ui/src/imag_init.rs index 2c9cda31..0c3c6cab 100644 --- a/tests/ui/src/imag_init.rs +++ b/tests/ui/src/imag_init.rs @@ -48,3 +48,34 @@ fn test_init_makes_imag_dir() { assert!(imag_home.path().exists(), "imag dir does not exist"); } +#[test] +fn test_init_creates_default_config() { + use pretty_assertions::assert_eq; + + crate::setup_logging(); + let imag_home = crate::imag::make_temphome(); + call(&imag_home); + + const CONFIGURATION_STR : &str = include_str!("../../../imagrc.toml"); + let config = std::fs::read_to_string({ + let mut path = imag_home.path().to_path_buf(); + path.push("imagrc.toml"); + path + }) + .unwrap(); + + // the imagrc is based on the example imagrc from this repository, but the one + // thing that differs is that the default level for logging output is "info" rather than + // "default" + CONFIGURATION_STR + .to_string() + .replace( + r#"level = "debug""#, + r#"level = "info""# + ) + .lines() + .zip(config.lines()) + .for_each(|(orig, created)| { + assert_eq!(orig, created); + }); +} diff --git a/tests/ui/src/lib.rs b/tests/ui/src/lib.rs index 3fffb1f8..827f8505 100644 --- a/tests/ui/src/lib.rs +++ b/tests/ui/src/lib.rs @@ -22,6 +22,7 @@ extern crate assert_fs; extern crate env_logger; extern crate predicates; #[macro_use] extern crate log; +#[macro_use] extern crate pretty_assertions; #[cfg(test)] mod imag; #[cfg(test)] mod imag_annotate;