Replace colored_diff with pretty_assertions (#440)

This commit is contained in:
Casey Rodarmor 2019-05-15 14:38:36 -04:00 committed by GitHub
parent d46e6d86a6
commit 22e96447b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 98 deletions

21
Cargo.lock generated
View File

@ -96,16 +96,6 @@ dependencies = [
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "colored-diff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ctor"
version = "0.1.9"
@ -204,14 +194,6 @@ dependencies = [
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itertools"
version = "0.7.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itertools"
version = "0.8.0"
@ -229,7 +211,6 @@ dependencies = [
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"brev 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"colored-diff 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ctrlc 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dotenv 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"edit-distance 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -558,7 +539,6 @@ dependencies = [
"checksum cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a0c56216487bb80eec9c4516337b2588a4f2a2290d72a1416d930e4dcdb0c90d"
"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum colored-diff 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fcbd90537dc19162289fbce7e95c882dded30f4ed41044cf1470612528d7163"
"checksum ctor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3b4c17619643c1252b5f690084b82639dd7fac141c57c8e77a00e0148132092c"
"checksum ctrlc 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5531b7f0698d9220b4729f8811931dbe0e91a05be2f7b3245fdc50dd856bae26"
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
@ -572,7 +552,6 @@ dependencies = [
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d"
"checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)" = "c6785aa7dd976f5fbf3b71cfd9cd49d7f783c1ff565a858d71031c6c313aa5c6"

View File

@ -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"

View File

@ -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.
///
@ -85,48 +93,30 @@ 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;
}
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");
}
assert_eq!(have, want, "bad output");
if expected_status == EXIT_SUCCESS {
test_round_trip(tmp.path());
}
}
fn test_round_trip(tmpdir: &Path) {
println!("Reparsing...");
let output = Command::new(&executable_path("just"))
.current_dir(tmp.path())
.current_dir(tmpdir)
.arg("--dump")
.output()
.expect("just invocation failed");
@ -137,12 +127,12 @@ fn integration_test(
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();
let output = Command::new(&executable_path("just"))
.current_dir(tmp.path())
.current_dir(tmpdir)
.arg("--justfile")
.arg(&reparsed_path)
.arg("--dump")
@ -155,16 +145,7 @@ fn integration_test(
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! {