@@ -1144,8 +1144,6 @@ impl Execs {
11441144 }
11451145
11461146 fn match_json ( & self , expected : & str , line : & str ) -> MatchResult {
1147- let expected = self . normalize_matcher ( expected) ;
1148- let line = self . normalize_matcher ( line) ;
11491147 let actual = match line. parse ( ) {
11501148 Err ( e) => return Err ( format ! ( "invalid json, {}:\n `{}`" , e, line) ) ,
11511149 Ok ( actual) => actual,
@@ -1155,7 +1153,8 @@ impl Execs {
11551153 Ok ( expected) => expected,
11561154 } ;
11571155
1158- find_json_mismatch ( & expected, & actual)
1156+ let cwd = self . process_builder . as_ref ( ) . and_then ( |p| p. get_cwd ( ) ) ;
1157+ find_json_mismatch ( & expected, & actual, cwd)
11591158 }
11601159
11611160 fn diff_lines < ' a > (
@@ -1333,8 +1332,12 @@ fn lines_match_works() {
13331332/// as paths). You can use a `"{...}"` string literal as a wildcard for
13341333/// arbitrary nested JSON (useful for parts of object emitted by other programs
13351334/// (e.g., rustc) rather than Cargo itself).
1336- pub fn find_json_mismatch ( expected : & Value , actual : & Value ) -> Result < ( ) , String > {
1337- match find_json_mismatch_r ( expected, actual) {
1335+ pub fn find_json_mismatch (
1336+ expected : & Value ,
1337+ actual : & Value ,
1338+ cwd : Option < & Path > ,
1339+ ) -> Result < ( ) , String > {
1340+ match find_json_mismatch_r ( expected, actual, cwd) {
13381341 Some ( ( expected_part, actual_part) ) => Err ( format ! (
13391342 "JSON mismatch\n Expected:\n {}\n Was:\n {}\n Expected part:\n {}\n Actual part:\n {}\n " ,
13401343 serde_json:: to_string_pretty( expected) . unwrap( ) ,
@@ -1349,20 +1352,29 @@ pub fn find_json_mismatch(expected: &Value, actual: &Value) -> Result<(), String
13491352fn find_json_mismatch_r < ' a > (
13501353 expected : & ' a Value ,
13511354 actual : & ' a Value ,
1355+ cwd : Option < & Path > ,
13521356) -> Option < ( & ' a Value , & ' a Value ) > {
13531357 use serde_json:: Value :: * ;
13541358 match ( expected, actual) {
13551359 ( & Number ( ref l) , & Number ( ref r) ) if l == r => None ,
13561360 ( & Bool ( l) , & Bool ( r) ) if l == r => None ,
1357- ( & String ( ref l) , & String ( ref r) ) if lines_match ( l, r) => None ,
1361+ ( & String ( ref l) , _) if l == "{...}" => None ,
1362+ ( & String ( ref l) , & String ( ref r) ) => {
1363+ let normalized = normalize_matcher ( r, cwd) ;
1364+ if lines_match ( l, & normalized) {
1365+ None
1366+ } else {
1367+ Some ( ( expected, actual) )
1368+ }
1369+ }
13581370 ( & Array ( ref l) , & Array ( ref r) ) => {
13591371 if l. len ( ) != r. len ( ) {
13601372 return Some ( ( expected, actual) ) ;
13611373 }
13621374
13631375 l. iter ( )
13641376 . zip ( r. iter ( ) )
1365- . filter_map ( |( l, r) | find_json_mismatch_r ( l, r) )
1377+ . filter_map ( |( l, r) | find_json_mismatch_r ( l, r, cwd ) )
13661378 . next ( )
13671379 }
13681380 ( & Object ( ref l) , & Object ( ref r) ) => {
@@ -1373,12 +1385,11 @@ fn find_json_mismatch_r<'a>(
13731385
13741386 l. values ( )
13751387 . zip ( r. values ( ) )
1376- . filter_map ( |( l, r) | find_json_mismatch_r ( l, r) )
1388+ . filter_map ( |( l, r) | find_json_mismatch_r ( l, r, cwd ) )
13771389 . next ( )
13781390 }
13791391 ( & Null , & Null ) => None ,
13801392 // Magic string literal `"{...}"` acts as wildcard for any sub-JSON.
1381- ( & String ( ref l) , _) if l == "{...}" => None ,
13821393 _ => Some ( ( expected, actual) ) ,
13831394 }
13841395}
0 commit comments