diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-11-20 13:35:45 -0600 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-11-20 13:35:45 -0600 |
commit | b1438bd27d32e4e2530825026cc39a8ac5456f68 (patch) | |
tree | 5de916dc413e0f9c9c17d9e63828991e1a4a7af8 | |
parent | 4b182e71598c2eda5190b81708bafe6f9681999b (diff) |
test: impl test for `logging::Config` and add `pretty_assertions`
-rw-r--r-- | Cargo.lock | 38 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/config.rs | 1 | ||||
-rw-r--r-- | src/finder.rs | 1 | ||||
-rw-r--r-- | src/finder/config.rs | 1 | ||||
-rw-r--r-- | src/logging/config.rs | 36 | ||||
-rw-r--r-- | src/paths.rs | 1 | ||||
-rw-r--r-- | src/paths/config.rs | 1 |
8 files changed, 80 insertions, 0 deletions
@@ -213,6 +213,22 @@ dependencies = [ ] [[package]] +name = "ctor" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + +[[package]] name = "dirs" version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -481,6 +497,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" [[package]] +name = "output_vt100" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" +dependencies = [ + "winapi", +] + +[[package]] name = "overload" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -579,6 +604,18 @@ dependencies = [ ] [[package]] +name = "pretty_assertions" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" +dependencies = [ + "ctor", + "diff", + "output_vt100", + "yansi", +] + +[[package]] name = "proc-macro-error" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -841,6 +878,7 @@ dependencies = [ "dirs 4.0.0", "figment", "ignore", + "pretty_assertions", "serde", "sled", "ssh_cfg", @@ -15,6 +15,7 @@ clap = { version = "4.0.18", features = ["derive", "env"] } dirs = "4.0.0" figment = { version = "0.10.8", features = ["toml", "env", "test"] } ignore = "0.4.18" +pretty_assertions = "1.3.0" serde = { version = "1.0.147", features = ["derive"] } sled = "0.34.7" ssh_cfg = { version = "0.3.0", optional = true } diff --git a/src/config.rs b/src/config.rs index 00aa1dc..5946102 100644 --- a/src/config.rs +++ b/src/config.rs @@ -45,6 +45,7 @@ impl TryFrom<Figment> for Config { mod tests { use super::*; use figment::providers::{Format, Serialized, Toml}; + use pretty_assertions::assert_eq; #[test] fn test_extract() { diff --git a/src/finder.rs b/src/finder.rs index c5b5bd5..ad7e303 100644 --- a/src/finder.rs +++ b/src/finder.rs @@ -80,6 +80,7 @@ impl DerefMut for FinderChild { #[cfg(test)] mod tests { use super::*; + use pretty_assertions::assert_eq; #[test] fn test_output() { diff --git a/src/finder/config.rs b/src/finder/config.rs index 4ef2b43..4c3abda 100644 --- a/src/finder/config.rs +++ b/src/finder/config.rs @@ -53,6 +53,7 @@ impl Provider for Config { mod tests { use super::*; use figment::providers::{Format, Serialized, Toml}; + use pretty_assertions::assert_eq; #[test] fn test_extract() { diff --git a/src/logging/config.rs b/src/logging/config.rs index 2f7be0f..1663f13 100644 --- a/src/logging/config.rs +++ b/src/logging/config.rs @@ -47,3 +47,39 @@ impl Default for Config { } } } + +#[cfg(test)] +mod tests { + use super::*; + use figment::providers::{Format, Serialized, Toml}; + use pretty_assertions::assert_eq; + + #[test] + fn test_extract() { + figment::Jail::expect_with(|jail| { + jail.create_file( + "tmuxr.toml", + r#" + stdout = "warn" + level = "info" + path = "/path/to/logfile.log" + "#, + )?; + + let config: Config = Figment::from(Serialized::defaults(Config::default())) + .merge(Toml::file("tmuxr.toml")) + .extract()?; + + assert_eq!( + config, + Config { + stdout: Some(Level::WARN), + level: Some(Level::INFO), + path: "/path/to/logfile.log".into() + } + ); + + Ok(()) + }); + } +} diff --git a/src/paths.rs b/src/paths.rs index d9c1214..9b9963a 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -69,6 +69,7 @@ impl Iterator for Paths { #[cfg(test)] mod tests { use super::*; + use pretty_assertions::assert_eq; use std::fs; #[test] diff --git a/src/paths/config.rs b/src/paths/config.rs index 4756d02..e5af2dc 100644 --- a/src/paths/config.rs +++ b/src/paths/config.rs @@ -90,6 +90,7 @@ impl<'de> Deserialize<'de> for PathEntry { mod tests { use super::*; use figment::providers::{Format, Serialized, Toml}; + use pretty_assertions::assert_eq; #[test] fn test_extract() { |