diff --git a/.travis.yml b/.travis.yml index 4079096..753fcb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,13 +8,13 @@ rust: matrix: include: - env: RUSTFMT - rust: 1.25.0 # `stable`: Locking down for consistent behavior + rust: 1.27.0 # `stable`: Locking down for consistent behavior install: - rustup component add rustfmt-preview script: - cargo fmt -- --write-mode=diff - env: RUSTFLAGS="-D warnings" - rust: 1.25.0 # `stable`: Locking down for consistent behavior + rust: 1.27.0 # `stable`: Locking down for consistent behavior install: script: - cargo check --tests --all-features diff --git a/src/assert.rs b/src/assert.rs index 945df8c..6824930 100644 --- a/src/assert.rs +++ b/src/assert.rs @@ -1,3 +1,5 @@ +//! `process::Output` assertions. + use std::fmt; use std::process; use std::str; @@ -400,21 +402,69 @@ where } } -impl IntoOutputPredicate> for &'static [u8] { - type Predicate = predicates::ord::EqPredicate<&'static [u8]>; +// Keep `predicates` concrete Predicates out of our public API. +/// Predicate used by `IntoOutputPredicate` for bytes +#[derive(Debug)] +pub struct BytesContentOutputPredicate(predicates::ord::EqPredicate<&'static [u8]>); + +impl BytesContentOutputPredicate { + pub(crate) fn new(value: &'static [u8]) -> Self { + let pred = predicates::ord::eq(value); + BytesContentOutputPredicate(pred) + } +} + +impl predicates::Predicate<[u8]> for BytesContentOutputPredicate { + fn eval(&self, item: &[u8]) -> bool { + self.0.eval(item) + } +} + +impl fmt::Display for BytesContentOutputPredicate { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + +impl IntoOutputPredicate for &'static [u8] { + type Predicate = BytesContentOutputPredicate; fn into_output(self) -> Self::Predicate { - predicates::ord::eq(self) + Self::Predicate::new(self) } } -impl IntoOutputPredicate> - for &'static str -{ - type Predicate = predicates::str::Utf8Predicate; +// Keep `predicates` concrete Predicates out of our public API. +/// Predicate used by `IntoOutputPredicate` for `str` +#[derive(Debug, Clone)] +pub struct StrContentOutputPredicate( + predicates::str::Utf8Predicate, +); + +impl StrContentOutputPredicate { + pub(crate) fn new(value: &'static str) -> Self { + let pred = predicates::str::similar(value).from_utf8(); + StrContentOutputPredicate(pred) + } +} + +impl predicates::Predicate<[u8]> for StrContentOutputPredicate { + fn eval(&self, item: &[u8]) -> bool { + self.0.eval(item) + } +} + +impl fmt::Display for StrContentOutputPredicate { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + +impl IntoOutputPredicate for &'static str { + type Predicate = StrContentOutputPredicate; fn into_output(self) -> Self::Predicate { - predicates::str::similar(self).from_utf8() + Self::Predicate::new(self) } } diff --git a/src/cargo.rs b/src/cargo.rs index 4a591bd..0f03fbf 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -107,7 +107,8 @@ struct MessageFilter<'a> { fn extract_filenames(msg: &escargot::Message, kind: &str) -> Option { let filter: MessageFilter = msg.convert().ok()?; - if filter.reason != "compiler-artifact" || filter.target.crate_types != ["bin"] + if filter.reason != "compiler-artifact" + || filter.target.crate_types != ["bin"] || filter.target.kind != [kind] { None diff --git a/src/lib.rs b/src/lib.rs index df2fa92..cb32ea3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,8 +45,9 @@ extern crate predicates; #[macro_use] extern crate serde; -mod assert; -pub use assert::*; +pub mod assert; +pub use assert::Assert; +pub use assert::OutputAssertExt; pub mod cargo; mod cmd; pub use cmd::*; diff --git a/src/stdin.rs b/src/stdin.rs index fe88403..ed00735 100644 --- a/src/stdin.rs +++ b/src/stdin.rs @@ -4,8 +4,8 @@ use std::process; use assert::Assert; use assert::OutputAssertExt; -use cmd::OutputOkExt; use cmd::dump_buffer; +use cmd::OutputOkExt; use errors::OutputError; use errors::OutputResult;