Skip to content

Commit 56c3a70

Browse files
committed
Stop using temporary files and an external program for diffs in test failures.
1 parent 20b509a commit 56c3a70

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exclude = ["src/css-parsing-tests"]
1616

1717
[dev-dependencies]
1818
rustc-serialize = "0.3"
19-
tempdir = "0.3"
19+
difference = "1.0"
2020
encoding_rs = "0.5"
2121

2222
[dependencies]

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
7373
#[macro_use] extern crate procedural_masquerade;
7474
#[doc(hidden)] pub extern crate phf as _internal__phf;
7575
#[cfg(test)] extern crate encoding_rs;
76-
#[cfg(test)] extern crate tempdir;
76+
#[cfg(test)] extern crate difference;
7777
#[cfg(test)] extern crate rustc_serialize;
7878
#[cfg(feature = "serde")] extern crate serde;
7979
#[cfg(feature = "heapsize")] #[macro_use] extern crate heapsize;

src/tests.rs

+5-29
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ extern crate test;
77

88
use encoding_rs;
99
use std::borrow::Cow::{self, Borrowed};
10-
use std::fs::File;
11-
use std::io::{self, Write};
12-
use std::path::Path;
13-
use std::process::Command;
1410
use rustc_serialize::json::{self, Json, ToJson};
15-
use tempdir::TempDir;
1611

1712
#[cfg(feature = "bench")]
1813
use self::test::Bencher;
@@ -30,29 +25,6 @@ macro_rules! JArray {
3025
($($e: expr),*) => { Json::Array(vec!( $( $e.to_json() ),* )) }
3126
}
3227

33-
34-
fn write_whole_file(path: &Path, data: &str) -> io::Result<()> {
35-
(try!(File::create(path))).write_all(data.as_bytes())
36-
}
37-
38-
39-
fn print_json_diff(results: &Json, expected: &Json) -> io::Result<()> {
40-
let temp = try!(TempDir::new("rust-cssparser-tests"));
41-
let results = results.pretty().to_string() + "\n";
42-
let expected = expected.pretty().to_string() + "\n";
43-
let result_path = temp.path().join("results.json");
44-
let expected_path = temp.path().join("expected.json");
45-
try!(write_whole_file(&result_path, &results));
46-
try!(write_whole_file(&expected_path, &expected));
47-
try!(Command::new("colordiff")
48-
.arg("-u1000")
49-
.arg(&result_path)
50-
.arg(&expected_path)
51-
.status());
52-
Ok(())
53-
}
54-
55-
5628
fn almost_equals(a: &Json, b: &Json) -> bool {
5729
match (a, b) {
5830
(&Json::I64(a), _) => almost_equals(&Json::F64(a as f64), b),
@@ -93,7 +65,11 @@ fn normalize(json: &mut Json) {
9365
fn assert_json_eq(results: json::Json, mut expected: json::Json, message: String) {
9466
normalize(&mut expected);
9567
if !almost_equals(&results, &expected) {
96-
print_json_diff(&results, &expected).unwrap();
68+
println!("{}", ::difference::Changeset::new(
69+
&results.pretty().to_string(),
70+
&expected.pretty().to_string(),
71+
"\n",
72+
));
9773
panic!(message)
9874
}
9975
}

0 commit comments

Comments
 (0)