diff --git a/src/cargo.rs b/src/cargo.rs index 0c31665..ae3cef5 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -31,7 +31,11 @@ fn cargo(project: &Project) -> Command { pub fn build_dependencies(project: &Project) -> Result<()> { let status = cargo(project) - .arg(if project.has_run_at_least { "build" } else { "check" }) + .arg(if project.has_run_at_least { + "build" + } else { + "check" + }) .arg("--bin") .arg(&project.name) .status() @@ -55,7 +59,11 @@ pub fn build_test(project: &Project, name: &Name) -> Result { .status(); cargo(project) - .arg(if project.has_run_at_least { "build" } else { "check" }) + .arg(if project.has_run_at_least { + "build" + } else { + "check" + }) .arg("--bin") .arg(name) .args(features(project)) diff --git a/src/error.rs b/src/error.rs index 9bbc713..a76cf67 100644 --- a/src/error.rs +++ b/src/error.rs @@ -25,7 +25,7 @@ pub enum Error { TomlSer(toml::ser::Error), UpdateVar(OsString), WriteStderr(io::Error), - Shrink(proptest::test_runner::TestError) + Shrink(proptest::test_runner::TestError), } pub type Result = std::result::Result; @@ -53,11 +53,7 @@ impl Display for Error { } TomlDe(e) => write!(f, "{}", e), TomlSer(e) => write!(f, "{}", e), - UpdateVar(var) => write!( - f, - "unrecognized value of KAOS: {:?}", - var.to_string_lossy(), - ), + UpdateVar(var) => write!(f, "unrecognized value of KAOS: {:?}", var.to_string_lossy(),), WriteStderr(e) => write!(f, "failed to write stderr file: {}", e), Shrink(e) => write!(f, "test failed with a randomization: {}", e), } @@ -105,7 +101,6 @@ impl From for Error { } } - impl From> for Error { fn from(err: proptest::test_runner::TestError) -> Self { Error::Shrink(err) diff --git a/src/lib.rs b/src/lib.rs index 014bed4..17a008d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ - //! ####  Chaotic testing harness //! //! **Kaos** is a chaotic testing harness to test your services against random failures. @@ -126,9 +125,7 @@ //! Instead of being compiler-like test harness, it has diverged to be chaos engineering //! oriented harness. -#![doc( - html_logo_url = "https://raw.githubusercontent.com/vertexclique/kaos/master/img/chaos.png" -)] +#![doc(html_logo_url = "https://raw.githubusercontent.com/vertexclique/kaos/master/img/chaos.png")] extern crate humantime; @@ -144,25 +141,24 @@ mod diff; mod env; mod error; mod features; +mod macros; mod manifest; mod message; mod normalize; mod run; mod rustflags; -mod macros; use std::cell::RefCell; use std::path::{Path, PathBuf}; -use std::{time::Duration, thread}; +use std::{thread, time::Duration}; -#[doc(hidden)] -pub use fail::eval as flunker; #[doc(hidden)] pub use fail::cfg as flunker_cfg; #[doc(hidden)] +pub use fail::eval as flunker; +#[doc(hidden)] pub use fail::FailScenario as KaosFailScenario; - pub use macros::*; /// @@ -188,7 +184,7 @@ struct Test { #[derive(Copy, Clone, Debug)] enum Expected { Available, - Chaotic + Chaotic, } impl Runs { diff --git a/src/macros.rs b/src/macros.rs index 05f1bd8..9f0def6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -23,7 +23,6 @@ macro_rules! kaostest { }}; } - #[cfg(test)] mod macro_tests { #[test] diff --git a/src/message.rs b/src/message.rs index 19013c5..7b0a647 100644 --- a/src/message.rs +++ b/src/message.rs @@ -6,10 +6,10 @@ use crate::error::Error; use crate::normalize; use crate::term; +use humantime::format_duration; use std::env; use std::path::Path; use std::process::Output; -use humantime::format_duration; pub(crate) enum Level { Fail, @@ -72,7 +72,10 @@ pub(crate) fn begin_test(test: &Test, show_expected: bool) { if show_expected { match test.expected { - Expected::Available => print!(" [should survive at least {}]", format_duration(test.duration.unwrap()).to_string()), + Expected::Available => print!( + " [should survive at least {}]", + format_duration(test.duration.unwrap()).to_string() + ), Expected::Chaotic => print!(" [should survive from chaos]"), } } diff --git a/src/run.rs b/src/run.rs index 53c1ff4..314506a 100644 --- a/src/run.rs +++ b/src/run.rs @@ -2,7 +2,10 @@ use std::collections::BTreeMap as Map; use std::env; use std::ffi::{OsStr, OsString}; use std::fs::{self, File}; -use std::{time::{Instant, Duration}, path::{Path, PathBuf}}; +use std::{ + path::{Path, PathBuf}, + time::{Duration, Instant}, +}; use super::{Expected, Runner, Test}; use crate::cargo; @@ -14,9 +17,9 @@ use crate::manifest::{Bin, Build, Config, Manifest, Name, Package, Workspace}; use crate::message::{self, Fail, Warn}; use crate::normalize::{self, Context, Variations}; use crate::rustflags; -use std::convert::TryInto; -use proptest::test_runner::{TestRunner, TestCaseError}; use humantime::format_duration; +use proptest::test_runner::{TestCaseError, TestRunner}; +use std::convert::TryInto; #[derive(Debug)] pub struct Project { @@ -83,11 +86,9 @@ impl Runner { } } - let surges: Vec = - tests.iter().map(|t| t.test.max_surge).collect(); + let surges: Vec = tests.iter().map(|t| t.test.max_surge).collect(); - let mut static_durations: Vec> = - vec![None; surges.len()]; + let mut static_durations: Vec> = vec![None; surges.len()]; surges .iter() @@ -296,13 +297,11 @@ impl Test { let res = check(self, project, name, success, stdout, stderr); let elapsed = now.elapsed(); if elapsed < duration { - Err(Error::ChaosTestFailed( - format!( - "availability is low. Expected at least: {}, Found: {}", - format_duration(duration).to_string(), - format_duration(elapsed).to_string() - ) - )) + Err(Error::ChaosTestFailed(format!( + "availability is low. Expected at least: {}, Found: {}", + format_duration(duration).to_string(), + format_duration(elapsed).to_string() + ))) } else { res }