Skip to content

Commit

Permalink
Replace colored_diff with pretty_assertions (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored May 15, 2019
1 parent d46e6d8 commit 22e9644
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 89 deletions.
21 changes: 0 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ version = "3.1.2"
features = ["termination"]

[dev-dependencies]
colored-diff = "0.2.1"
executable-path = "1.0.0"
pretty_assertions = "0.6.1"
115 changes: 48 additions & 67 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
use colored_diff::PrettyDifference;
use executable_path::executable_path;
use libc::{EXIT_FAILURE, EXIT_SUCCESS};
use pretty_assertions::assert_eq;
use std::{
env, fs,
io::Write,
path::Path,
process::{Command, Stdio},
str,
};
use tempdir::TempDir;

#[derive(PartialEq, Debug)]
struct Output<'a> {
stdout: &'a str,
stderr: &'a str,
status: i32,
}

/// Instantiate integration tests for a given test case using
/// sh, dash, and bash.
///
Expand Down Expand Up @@ -85,86 +93,59 @@ fn integration_test(
.wait_with_output()
.expect("failed to wait for just process");

let mut failure = false;
let have = Output {
status: output.status.code().unwrap(),
stdout: str::from_utf8(&output.stdout).unwrap(),
stderr: str::from_utf8(&output.stderr).unwrap(),
};

let status = output.status.code().unwrap();
if status != expected_status {
println!("bad status: {} != {}", status, expected_status);
failure = true;
}
let want = Output {
status: expected_status,
stdout: expected_stdout,
stderr: expected_stderr,
};

let stdout = str::from_utf8(&output.stdout).unwrap();

if stdout != expected_stdout {
println!(
"bad stdout:\n {}",
PrettyDifference {
expected: expected_stdout,
actual: stdout
},
);
failure = true;
}
assert_eq!(have, want, "bad output");

let stderr = str::from_utf8(&output.stderr).unwrap();
if stderr != expected_stderr {
println!(
"bad stderr: {}",
PrettyDifference {
expected: expected_stderr,
actual: stderr
},
);
failure = true;
}

if failure {
panic!("test failed");
if expected_status == EXIT_SUCCESS {
test_round_trip(tmp.path());
}
}

if expected_status == EXIT_SUCCESS {
println!("Reparsing...");
fn test_round_trip(tmpdir: &Path) {
println!("Reparsing...");

let output = Command::new(&executable_path("just"))
.current_dir(tmp.path())
.arg("--dump")
.output()
.expect("just invocation failed");
let output = Command::new(&executable_path("just"))
.current_dir(tmpdir)
.arg("--dump")
.output()
.expect("just invocation failed");

if !output.status.success() {
panic!("dump failed: {}", output.status);
}
if !output.status.success() {
panic!("dump failed: {}", output.status);
}

let dumped = String::from_utf8(output.stdout).unwrap();
let dumped = String::from_utf8(output.stdout).unwrap();

let reparsed_path = tmp.path().join("reparsed.just");
let reparsed_path = tmpdir.join("reparsed.just");

fs::write(&reparsed_path, &dumped).unwrap();
fs::write(&reparsed_path, &dumped).unwrap();

let output = Command::new(&executable_path("just"))
.current_dir(tmp.path())
.arg("--justfile")
.arg(&reparsed_path)
.arg("--dump")
.output()
.expect("just invocation failed");
let output = Command::new(&executable_path("just"))
.current_dir(tmpdir)
.arg("--justfile")
.arg(&reparsed_path)
.arg("--dump")
.output()
.expect("just invocation failed");

if !output.status.success() {
panic!("reparse failed: {}", output.status);
}
if !output.status.success() {
panic!("reparse failed: {}", output.status);
}

let reparsed = String::from_utf8(output.stdout).unwrap();
let reparsed = String::from_utf8(output.stdout).unwrap();

if reparsed != dumped {
println!(
"reparse mismatch:\n {}",
PrettyDifference {
expected: &dumped,
actual: &reparsed
},
);
}
}
assert_eq!(reparsed, dumped, "reparse mismatch");
}

integration_test! {
Expand Down

0 comments on commit 22e9644

Please sign in to comment.