From 88f6a3022e008ec1d6aaaaae298f4bb99dccfb0c Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Tue, 31 Jan 2017 20:51:24 -0800 Subject: [PATCH] =?utf8?q?make=20build=20tests=20not=20depend=20on=20minut?= =?utf8?q?i=C3=A6=20of=20rustc=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This little patch arises from the maelstrom of my purity born of pain. It's the pain of seeing rust-lang/rust#38103 in its perfect crystalline beauty waste away on page four of https://github.com/rust-lang/rust/pulls, waiting, ready, itching to land, dying with anticipation to bring the light of clearer lint group error messages to Rust users of all creeds and nations, only for its promise to be cruelly blocked by the fateful, hateful hand of circular dependency. For it is written in src/tools/cargotest/main.rs that the Cargo tests must pass before the PR can receive Appveyor's blessing, but the Cargo tests could not pass (because they depend on fine details of the output that the PR is meant to change), and the Cargo tests could not be changed (because updating the test expectation to match the proposed new compiler output, would fail with the current compiler). The Gordian knot is cut in the bowels of cargotest's very notion of comparison (of JSON objects) itself, by means of introducing a magic string literal `"{...}"`, which can server as a wildcard for any JSON sub-object. And so it will be for the children, and the children's children, and unto the 1.17.0 and 1.18.0 releases, that Cargo's build test expectations will faithfully expect the exact JSON output by Cargo itself, but the string literal `"{...}"` shall be a token upon the JSON output by rustc, and when I see `"{...}"`, I will pass over you, and the failure shall not be upon you. And this day shall be unto you for a memorial. --- tests/build.rs | 37 +++------------------------------- tests/cargotest/support/mod.rs | 7 +++++-- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/tests/build.rs b/tests/build.rs index 6ca86b6d2..75ca7dcee 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -2511,16 +2511,7 @@ fn compiler_json_error_format() { "reason":"compiler-message", "package_id":"bar 0.5.0 ([..])", "target":{"kind":["lib"],"name":"bar","src_path":"[..]lib.rs"}, - "message":{ - "children":[],"code":null,"level":"warning","rendered":null, - "message":"function is never used: `dead`, #[warn(dead_code)] on by default", - "spans":[{ - "byte_end":12,"byte_start":0,"column_end":13,"column_start":1,"expansion":null, - "file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1, - "suggested_replacement":null, - "text":[{"highlight_end":13,"highlight_start":1,"text":"fn dead() {}"}] - }] - } + "message":"{...}" } { @@ -2541,16 +2532,7 @@ fn compiler_json_error_format() { "reason":"compiler-message", "package_id":"foo 0.5.0 ([..])", "target":{"kind":["bin"],"name":"foo","src_path":"[..]main.rs"}, - "message":{ - "children":[],"code":null,"level":"warning","rendered":null, - "message":"unused variable: `unused`, #[warn(unused_variables)] on by default", - "spans":[{ - "byte_end":22,"byte_start":16,"column_end":23,"column_start":17,"expansion":null, - "file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1, - "suggested_replacement":null, - "text":[{"highlight_end":23,"highlight_start":17,"text":"[..]"}] - }] - } + "message":"{...}" } { @@ -2599,20 +2581,7 @@ fn message_format_json_forward_stderr() { "reason":"compiler-message", "package_id":"foo 0.5.0 ([..])", "target":{"kind":["bin"],"name":"foo","src_path":"[..]"}, - "message":{ - "children":[],"code":null,"level":"warning","rendered":null, - "message":"unused variable: `unused`, #[warn(unused_variables)] on by default", - "spans":[{ - "byte_end":22,"byte_start":16,"column_end":23,"column_start":17,"expansion":null, - "file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1, - "suggested_replacement":null, - "text":[{ - "highlight_end":23, - "highlight_start":17, - "text":"fn main() { let unused = 0; }" - }] - }] - } + "message":"{...}" } { diff --git a/tests/cargotest/support/mod.rs b/tests/cargotest/support/mod.rs index de218b6fc..054d35cf7 100644 --- a/tests/cargotest/support/mod.rs +++ b/tests/cargotest/support/mod.rs @@ -570,6 +570,8 @@ fn lines_match_works() { // Compares JSON object for approximate equality. // You can use `[..]` wildcard in strings (useful for OS dependent things such as paths). +// You can use a `"{...}"` string literal as a wildcard for arbitrary nested JSON (useful +// for parts of object emitted by other programs (e.g. rustc) rather than Cargo itself). // Arrays are sorted before comparison. fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json, &'a Json)> { use rustc_serialize::json::Json::*; @@ -586,8 +588,7 @@ fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json, fn sorted(xs: &Vec) -> Vec<&Json> { let mut result = xs.iter().collect::>(); - // `unwrap` should be safe because JSON spec does not allow NaNs - result.sort_by(|x, y| x.partial_cmp(y).unwrap()); + result.sort_by(|x, y| x.partial_cmp(y).expect("JSON spec does not allow NaNs")); result } @@ -606,6 +607,8 @@ fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json, .nth(0) } (&Null, &Null) => None, + // magic string literal "{...}" acts as wildcard for any sub-JSON + (&String(ref l), _) if l == "{...}" => None, _ => Some((expected, actual)), } -- 2.39.5