@@ -7,12 +7,7 @@ extern crate test;
7
7
8
8
use encoding_rs;
9
9
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 ;
14
10
use rustc_serialize:: json:: { self , Json , ToJson } ;
15
- use tempdir:: TempDir ;
16
11
17
12
#[ cfg( feature = "bench" ) ]
18
13
use self :: test:: Bencher ;
@@ -30,29 +25,6 @@ macro_rules! JArray {
30
25
( $( $e: expr) ,* ) => { Json :: Array ( vec!( $( $e. to_json( ) ) ,* ) ) }
31
26
}
32
27
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
-
56
28
fn almost_equals ( a : & Json , b : & Json ) -> bool {
57
29
match ( a, b) {
58
30
( & Json :: I64 ( a) , _) => almost_equals ( & Json :: F64 ( a as f64 ) , b) ,
@@ -93,7 +65,11 @@ fn normalize(json: &mut Json) {
93
65
fn assert_json_eq ( results : json:: Json , mut expected : json:: Json , message : String ) {
94
66
normalize ( & mut expected) ;
95
67
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
+ ) ) ;
97
73
panic ! ( message)
98
74
}
99
75
}
0 commit comments