From a960c79a361b865e0d770faaf239e3a51e8a5b39 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 27 Jun 2018 12:44:20 -0600 Subject: [PATCH 1/2] fix(assert): Isolate API details Ensure we don't expose predicate impls from `predicates` in our public API. --- src/assert.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++------- src/cargo.rs | 3 ++- src/lib.rs | 5 ++-- src/stdin.rs | 2 +- 4 files changed, 64 insertions(+), 12 deletions(-) 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; From b32476a724881b6bc478c40fb516bd4c0d4942d6 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 27 Jun 2018 13:00:33 -0600 Subject: [PATCH 2/2] chore: Update stable Rust --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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