Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Commit c17c1aa

Browse files
committed
Merge #49
49: Run and add rustfmt r=killercup a=killercup
2 parents 177493e + cc255a1 commit c17c1aa

File tree

8 files changed

+94
-57
lines changed

8 files changed

+94
-57
lines changed

.travis.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ rust:
88
matrix:
99
include:
1010
- rust: nightly-2017-10-09
11-
env: CLIPPY=YESPLEASE
11+
env: CLIPPY_VERS="0.0.165"
12+
before_script: |
13+
[[ "$(cargo +nightly-2017-10-09 clippy --version)" != "$CLIPPY_VERS" ]] && \
14+
cargo +nightly-2017-10-09 install clippy --vers "$CLIPPY_VERS" --force
1215
script: |
13-
cargo +nightly-2017-10-09 install clippy --vers "0.0.165"
14-
cargo +nightly-2017-10-09 clippy -- -D warnings
16+
cargo +nightly-2017-10-09 clippy -- -D warnings
17+
- rust: nightly-2017-10-09
18+
env: RUSTFMT_VERS="0.2.8"
19+
before_script: |
20+
[[ "$(cargo +nightly-2017-10-09 fmt -- --version)" != "$RUSTFMT_VERS"* ]] && \
21+
cargo +nightly-2017-10-09 install rustfmt-nightly --vers "$RUSTFMT_VERS" --force
22+
script: |
23+
cargo +nightly-2017-10-09 fmt --all -- --write-mode=diff
1524
before_script:
1625
- |
1726
pip install 'travis-cargo<0.2' --user &&

rustfmt.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
format_strings = false
22
reorder_imports = true
3-

src/assert.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
use errors::*;
2+
use output::{OutputAssertion, OutputKind};
13
use std::default;
2-
use std::process::{Command, Stdio};
4+
use std::io::Write;
35
use std::path::PathBuf;
6+
use std::process::{Command, Stdio};
47
use std::vec::Vec;
5-
use std::io::Write;
6-
7-
use errors::*;
8-
use output::{OutputAssertion, OutputKind};
98

109
/// Assertions for a specific command.
1110
#[derive(Debug)]
@@ -25,7 +24,9 @@ impl default::Default for Assert {
2524
fn default() -> Self {
2625
Assert {
2726
cmd: vec!["cargo", "run", "--"]
28-
.into_iter().map(String::from).collect(),
27+
.into_iter()
28+
.map(String::from)
29+
.collect(),
2930
current_dir: None,
3031
expect_success: Some(true),
3132
expect_exit_code: None,
@@ -49,7 +50,9 @@ impl Assert {
4950
pub fn cargo_binary(name: &str) -> Self {
5051
Assert {
5152
cmd: vec!["cargo", "run", "--bin", name, "--"]
52-
.into_iter().map(String::from).collect(),
53+
.into_iter()
54+
.map(String::from)
55+
.collect(),
5356
..Self::default()
5457
}
5558
}
@@ -265,7 +268,11 @@ impl Assert {
265268
let mut spawned = command.spawn()?;
266269

267270
if let Some(ref contents) = self.stdin_contents {
268-
spawned.stdin.as_mut().expect("Couldn't get mut ref to command stdin").write_all(contents.as_bytes())?;
271+
spawned
272+
.stdin
273+
.as_mut()
274+
.expect("Couldn't get mut ref to command stdin")
275+
.write_all(contents.as_bytes())?;
269276
}
270277
let output = spawned.wait_with_output()?;
271278

@@ -282,8 +289,7 @@ impl Assert {
282289
}
283290
}
284291

285-
if self.expect_exit_code.is_some() &&
286-
self.expect_exit_code != output.status.code() {
292+
if self.expect_exit_code.is_some() && self.expect_exit_code != output.status.code() {
287293
let out = String::from_utf8_lossy(&output.stdout).to_string();
288294
let err = String::from_utf8_lossy(&output.stderr).to_string();
289295
bail!(ErrorKind::ExitCodeMismatch(
@@ -344,7 +350,7 @@ impl OutputAssertionBuilder {
344350
// No clippy, we don't want to implement std::ops::Not :)
345351
#[cfg_attr(feature = "cargo-clippy", allow(should_implement_trait))]
346352
pub fn not(mut self) -> Self {
347-
self.expected_result = ! self.expected_result;
353+
self.expected_result = !self.expected_result;
348354
self
349355
}
350356

src/diff.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
extern crate colored;
22
use self::colored::Colorize;
3-
4-
use difference::{Difference, Changeset};
5-
use std::fmt::{Write, Error as fmtError};
3+
use difference::{Changeset, Difference};
4+
use std::fmt::{Error as fmtError, Write};
65

76
pub fn render(&Changeset { ref diffs, .. }: &Changeset) -> Result<String, fmtError> {
87
let mut t = String::new();
@@ -54,22 +53,35 @@ mod tests {
5453
fn basic_diff() {
5554
let diff = Changeset::new("lol", "yay", "\n");
5655
println!("{}", render(&diff).unwrap());
57-
assert_eq!(render(&diff).unwrap(),
58-
" \n\u{1b}[31m-lol\u{1b}[0m\n\u{1b}[32m+\u{1b}[0m\u{1b}[7;32myay\u{1b}[0m \n")
56+
assert_eq!(
57+
render(&diff).unwrap(),
58+
" \n\u{1b}[31m-lol\u{1b}[0m\n\u{1b}[32m+\u{1b}[0m\u{1b}[7;32myay\u{1b}[0m \n"
59+
)
5960
}
6061

6162
#[test]
6263
fn multiline_diff() {
63-
let diff = Changeset::new("Lorem ipsum dolor sit amet, consectetur adipisicing elit,
64+
let diff = Changeset::new(
65+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
6466
sed do eiusmod tempor incididunt ut labore et dolore magna
6567
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
6668
ullamco laboris nisi ut aliquip ex ea commodo consequat.",
67-
"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
69+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
6870
sed do eiusmod tempor **incididunt** ut labore et dolore magna
6971
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
7072
ullamco laboris nisi ut aliquip ex ea commodo consequat.",
71-
"\n");
73+
"\n",
74+
);
7275
println!("{}", render(&diff).unwrap());
73-
assert_eq!(render(&diff).unwrap(), " Lorem ipsum dolor sit amet, consectetur adipisicing elit,\n\u{1b}[31m-sed do eiusmod tempor incididunt ut labore et dolore magna\u{1b}[0m\n\u{1b}[32m+\u{1b}[0m\u{1b}[32msed do eiusmod tempor\u{1b}[0m \u{1b}[7;32m**incididunt**\u{1b}[0m \u{1b}[32mut labore et dolore magna\u{1b}[0m \n aliqua. Ut enim ad minim veniam, quis nostrud exercitation\nullamco laboris nisi ut aliquip ex ea commodo consequat.\n");
76+
assert_eq!(
77+
render(&diff).unwrap(),
78+
" Lorem ipsum dolor sit amet, consectetur adipisicing elit,\n\
79+
\u{1b}[31m-sed do eiusmod tempor incididunt ut labore et dolore \
80+
magna\u{1b}[0m\n\u{1b}[32m+\u{1b}[0m\u{1b}[32msed do eiusmod tempor\
81+
\u{1b}[0m \u{1b}[7;32m**incididunt**\u{1b}[0m \u{1b}[32mut labore \
82+
et dolore magna\u{1b}[0m \n aliqua. Ut enim ad minim veniam, quis \
83+
nostrud exercitation\nullamco laboris nisi ut aliquip ex ea \
84+
commodo consequat.\n"
85+
);
7486
}
7587
}

src/errors.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,25 @@ error_chain! {
1818
err = err,
1919
)
2020
}
21-
ExitCodeMismatch(cmd: Vec<String>, expected: Option<i32>, got: Option<i32>, out: String, err: String) {
21+
ExitCodeMismatch(
22+
cmd: Vec<String>,
23+
expected: Option<i32>,
24+
got: Option<i32>,
25+
out: String,
26+
err: String
27+
) {
2228
description("Wrong exit code")
2329
display(
24-
"{}: (exit code of `{}` expected to be `{:?}`)\nexit code=`{:?}`\nstdout=```{}```\nstderr=```{}```",
25-
ERROR_PREFIX,
26-
cmd.join(" "),
27-
expected,
28-
got,
29-
out,
30-
err,
30+
"{prefix}: (exit code of `{cmd}` expected to be `{expected:?}`)\n\
31+
exit code=`{code:?}`\n\
32+
stdout=```{stdout}```\n\
33+
stderr=```{stderr}```",
34+
prefix=ERROR_PREFIX,
35+
cmd=cmd.join(" "),
36+
expected=expected,
37+
code=got,
38+
stdout=out,
39+
stderr=err,
3140
)
3241
}
3342
OutputMismatch(cmd: Vec<String>, output_err: ::output::Error, kind: ::output::OutputKind) {

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@
118118
#![deny(missing_docs)]
119119

120120
extern crate difference;
121-
#[macro_use] extern crate error_chain;
121+
#[macro_use]
122+
extern crate error_chain;
122123
extern crate serde_json;
123124

124125
mod errors;
125126

126-
#[macro_use] mod macros;
127+
#[macro_use]
128+
mod macros;
127129
pub use macros::flatten_escaped_string;
128130

129131
mod output;

src/macros.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::borrow::Cow;
21
use serde_json;
2+
use std::borrow::Cow;
33

44
/// Easily construct an `Assert` with a custom command.
55
///
@@ -50,8 +50,7 @@ macro_rules! assert_cmd {
5050
/// If `x` can not be decoded as `String`.
5151
#[doc(hidden)]
5252
fn deserialize_json_string(x: &str) -> String {
53-
serde_json::from_str(x)
54-
.expect(&format!("Unable to deserialize `{:?}` as string.", x))
53+
serde_json::from_str(x).expect(&format!("Unable to deserialize `{:?}` as string.", x))
5554
}
5655

5756
/// Deserialize a JSON-encoded `String`.
@@ -103,26 +102,20 @@ mod test {
103102
use super::*;
104103

105104
#[test]
106-
fn flatten_unquoted()
107-
{
108-
assert_eq!(
109-
flatten_escaped_string("hello world"),
110-
"hello world");
105+
fn flatten_unquoted() {
106+
assert_eq!(flatten_escaped_string("hello world"), "hello world");
111107
}
112108

113109
#[test]
114-
fn flatten_quoted()
115-
{
116-
assert_eq!(
117-
flatten_escaped_string(r#""hello world""#),
118-
"hello world");
110+
fn flatten_quoted() {
111+
assert_eq!(flatten_escaped_string(r#""hello world""#), "hello world");
119112
}
120113

121114
#[test]
122-
fn flatten_escaped()
123-
{
115+
fn flatten_escaped() {
124116
assert_eq!(
125117
flatten_escaped_string(r#""hello world \u0042 A""#),
126-
"hello world B A");
118+
"hello world B A"
119+
);
127120
}
128121
}

src/output.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use std::process::Output;
2-
3-
use difference::Changeset;
4-
51
use self::errors::*;
62
pub use self::errors::{Error, ErrorKind};
73
use diff;
4+
use difference::Changeset;
5+
use std::process::Output;
86

97
#[derive(Debug, Clone)]
108
pub struct OutputAssertion {
@@ -19,7 +17,10 @@ impl OutputAssertion {
1917
let result = got.contains(&self.expect);
2018
if result != self.expected_result {
2119
if self.expected_result {
22-
bail!(ErrorKind::OutputDoesntContain(self.expect.clone(), got.into()));
20+
bail!(ErrorKind::OutputDoesntContain(
21+
self.expect.clone(),
22+
got.into()
23+
));
2324
} else {
2425
bail!(ErrorKind::OutputContains(self.expect.clone(), got.into()));
2526
}
@@ -35,7 +36,11 @@ impl OutputAssertion {
3536
if result != self.expected_result {
3637
if self.expected_result {
3738
let nice_diff = diff::render(&differences)?;
38-
bail!(ErrorKind::OutputDoesntMatch(self.expect.clone(), got.to_owned(), nice_diff));
39+
bail!(ErrorKind::OutputDoesntMatch(
40+
self.expect.clone(),
41+
got.to_owned(),
42+
nice_diff
43+
));
3944
} else {
4045
bail!(ErrorKind::OutputMatches(got.to_owned()));
4146
}
@@ -52,7 +57,9 @@ impl OutputAssertion {
5257
} else {
5358
self.matches_exact(&observed)
5459
};
55-
result.map_err(|e| super::errors::ErrorKind::OutputMismatch(cmd.to_vec(), e, self.kind))?;
60+
result.map_err(|e| {
61+
super::errors::ErrorKind::OutputMismatch(cmd.to_vec(), e, self.kind)
62+
})?;
5663

5764
Ok(())
5865
}

0 commit comments

Comments
 (0)