Skip to content

style: Update to 2018 edition #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ documentation = "http://docs.rs/assert_cmd/"
readme = "README.md"
categories = ["development-tools::testing"]
keywords = ["cli", "test", "assert", "command", "duct"]
edition = "2018"

[[bin]]
name = "bin_fixture"
Expand Down
2 changes: 1 addition & 1 deletion examples/example_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io;
use std::io::Write;
use std::process;

fn run() -> Result<(), Box<Error>> {
fn run() -> Result<(), Box<dyn Error>> {
if let Ok(text) = env::var("stdout") {
println!("{}", text);
}
Expand Down
46 changes: 23 additions & 23 deletions src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use predicates::str::PredicateStrExt;
use predicates_core;
use predicates_tree::CaseTreeExt;

use cmd::dump_buffer;
use cmd::output_fmt;
use crate::cmd::dump_buffer;
use crate::cmd::output_fmt;

/// Assert the state of an [`Output`].
///
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<'c> OutputAssertExt for &'c mut process::Command {
/// [`OutputAssertExt`]: trait.OutputAssertExt.html
pub struct Assert {
output: process::Output,
context: Vec<(&'static str, Box<fmt::Display>)>,
context: Vec<(&'static str, Box<dyn fmt::Display>)>,
}

impl Assert {
Expand Down Expand Up @@ -252,7 +252,7 @@ impl Assert {
self.code_impl(&pred.into_code())
}

fn code_impl(self, pred: &predicates_core::Predicate<i32>) -> Self {
fn code_impl(self, pred: &dyn predicates_core::Predicate<i32>) -> Self {
let actual_code = self
.output
.status
Expand Down Expand Up @@ -346,7 +346,7 @@ impl Assert {
self.stdout_impl(&pred.into_output())
}

fn stdout_impl(self, pred: &predicates_core::Predicate<[u8]>) -> Self {
fn stdout_impl(self, pred: &dyn predicates_core::Predicate<[u8]>) -> Self {
{
let actual = &self.output.stdout;
if let Some(case) = pred.find_case(false, &actual) {
Expand Down Expand Up @@ -438,7 +438,7 @@ impl Assert {
self.stderr_impl(&pred.into_output())
}

fn stderr_impl(self, pred: &predicates_core::Predicate<[u8]>) -> Self {
fn stderr_impl(self, pred: &dyn predicates_core::Predicate<[u8]>) -> Self {
{
let actual = &self.output.stderr;
if let Some(case) = pred.find_case(false, &actual) {
Expand All @@ -450,7 +450,7 @@ impl Assert {
}

impl fmt::Display for Assert {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for &(ref name, ref context) in &self.context {
writeln!(f, "{}=`{}`", name, context)?;
}
Expand All @@ -459,7 +459,7 @@ impl fmt::Display for Assert {
}

impl fmt::Debug for Assert {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Assert")
.field("output", &self.output)
.finish()
Expand Down Expand Up @@ -550,12 +550,12 @@ impl EqCodePredicate {
impl predicates_core::reflection::PredicateReflection for EqCodePredicate {
fn parameters<'a>(
&'a self,
) -> Box<Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
) -> Box<dyn Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
self.0.parameters()
}

/// Nested `Predicate`s of the current `Predicate`.
fn children<'a>(&'a self) -> Box<Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
fn children<'a>(&'a self) -> Box<dyn Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
self.0.children()
}
}
Expand All @@ -575,7 +575,7 @@ impl predicates_core::Predicate<i32> for EqCodePredicate {
}

impl fmt::Display for EqCodePredicate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
Expand Down Expand Up @@ -620,12 +620,12 @@ impl InCodePredicate {
impl predicates_core::reflection::PredicateReflection for InCodePredicate {
fn parameters<'a>(
&'a self,
) -> Box<Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
) -> Box<dyn Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
self.0.parameters()
}

/// Nested `Predicate`s of the current `Predicate`.
fn children<'a>(&'a self) -> Box<Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
fn children<'a>(&'a self) -> Box<dyn Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
self.0.children()
}
}
Expand All @@ -645,7 +645,7 @@ impl predicates_core::Predicate<i32> for InCodePredicate {
}

impl fmt::Display for InCodePredicate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
Expand Down Expand Up @@ -754,12 +754,12 @@ impl BytesContentOutputPredicate {
impl predicates_core::reflection::PredicateReflection for BytesContentOutputPredicate {
fn parameters<'a>(
&'a self,
) -> Box<Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
) -> Box<dyn Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
self.0.parameters()
}

/// Nested `Predicate`s of the current `Predicate`.
fn children<'a>(&'a self) -> Box<Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
fn children<'a>(&'a self) -> Box<dyn Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
self.0.children()
}
}
Expand All @@ -779,7 +779,7 @@ impl predicates_core::Predicate<[u8]> for BytesContentOutputPredicate {
}

impl fmt::Display for BytesContentOutputPredicate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
Expand Down Expand Up @@ -833,12 +833,12 @@ impl StrContentOutputPredicate {
impl predicates_core::reflection::PredicateReflection for StrContentOutputPredicate {
fn parameters<'a>(
&'a self,
) -> Box<Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
) -> Box<dyn Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
self.0.parameters()
}

/// Nested `Predicate`s of the current `Predicate`.
fn children<'a>(&'a self) -> Box<Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
fn children<'a>(&'a self) -> Box<dyn Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
self.0.children()
}
}
Expand All @@ -858,7 +858,7 @@ impl predicates_core::Predicate<[u8]> for StrContentOutputPredicate {
}

impl fmt::Display for StrContentOutputPredicate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
Expand Down Expand Up @@ -924,12 +924,12 @@ where
{
fn parameters<'a>(
&'a self,
) -> Box<Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
) -> Box<dyn Iterator<Item = predicates_core::reflection::Parameter<'a>> + 'a> {
self.0.parameters()
}

/// Nested `Predicate`s of the current `Predicate`.
fn children<'a>(&'a self) -> Box<Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
fn children<'a>(&'a self) -> Box<dyn Iterator<Item = predicates_core::reflection::Child<'a>> + 'a> {
self.0.children()
}
}
Expand All @@ -955,7 +955,7 @@ impl<P> fmt::Display for StrOutputPredicate<P>
where
P: predicates_core::Predicate<str>,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/bin_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io;
use std::io::Write;
use std::process;

fn run() -> Result<(), Box<Error>> {
fn run() -> Result<(), Box<dyn Error>> {
if let Ok(text) = env::var("stdout") {
println!("{}", text);
}
Expand Down
12 changes: 6 additions & 6 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl CommandCargoExt for process::Command {
/// Error when finding crate binary.
#[derive(Debug)]
pub struct CargoError {
cause: Option<Box<Error + Send + Sync + 'static>>,
cause: Option<Box<dyn Error + Send + Sync + 'static>>,
}

impl CargoError {
Expand All @@ -157,16 +157,16 @@ impl Error for CargoError {
"Cargo command failed."
}

fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
self.cause.as_ref().map(|c| {
let c: &Error = c.as_ref();
let c: &dyn Error = c.as_ref();
c
})
}
}

impl fmt::Display for CargoError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(ref cause) = self.cause {
writeln!(f, "Cause: {}", cause)?;
}
Expand All @@ -185,13 +185,13 @@ impl Error for NotFoundError {
"Cargo command not found."
}

fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
None
}
}

impl fmt::Display for NotFoundError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "Cargo command not found: {}", self.path.display())
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Error for OutputError {
"Command failed."
}

fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
if let OutputCause::Unexpected(ref err) = self.cause {
Some(err.as_ref())
} else {
Expand All @@ -257,7 +257,7 @@ impl Error for OutputError {
}

impl fmt::Display for OutputError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(ref cmd) = self.cmd {
writeln!(f, "command=`{}`", cmd)?;
}
Expand All @@ -275,11 +275,11 @@ impl fmt::Display for OutputError {
#[derive(Debug)]
enum OutputCause {
Expected(Output),
Unexpected(Box<Error + Send + Sync + 'static>),
Unexpected(Box<dyn Error + Send + Sync + 'static>),
}

impl fmt::Display for OutputCause {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
OutputCause::Expected(ref e) => write!(f, "{}", e),
OutputCause::Unexpected(ref e) => write!(f, "{}", e),
Expand All @@ -293,12 +293,12 @@ struct Output {
}

impl fmt::Display for Output {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
output_fmt(&self.output, f)
}
}

pub(crate) fn output_fmt(output: &process::Output, f: &mut fmt::Formatter) -> fmt::Result {
pub(crate) fn output_fmt(output: &process::Output, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(code) = output.status.code() {
writeln!(f, "code={}", code)?;
} else {
Expand All @@ -324,7 +324,7 @@ pub(crate) fn dump_buffer(buffer: &[u8]) -> String {
}
}

pub(crate) fn write_buffer(buffer: &[u8], f: &mut fmt::Formatter) -> fmt::Result {
pub(crate) fn write_buffer(buffer: &[u8], f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Ok(buffer) = str::from_utf8(buffer) {
write!(f, "{}", buffer)
} else {
Expand All @@ -344,7 +344,7 @@ impl DebugBuffer {
}

impl fmt::Display for DebugBuffer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write_buffer(&self.buffer, f)
}
}
13 changes: 4 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@

#![warn(missing_docs)]

extern crate escargot;
extern crate predicates;
extern crate predicates_core;
extern crate predicates_tree;

/// Allows you to pull the name from your Cargo.toml at compile time.
///
/// # Examples
Expand Down Expand Up @@ -154,10 +149,10 @@ pub mod stdin;

/// Extension traits that are useful to have available.
pub mod prelude {
pub use assert::OutputAssertExt;
pub use cargo::CommandCargoExt;
pub use cmd::OutputOkExt;
pub use stdin::CommandStdInExt;
pub use crate::assert::OutputAssertExt;
pub use crate::cargo::CommandCargoExt;
pub use crate::cmd::OutputOkExt;
pub use crate::stdin::CommandStdInExt;
}

#[macro_use]
Expand Down
Loading