Skip to content

Commit 550bd43

Browse files
committed
Auto merge of #3628 - zackmdavis:the_maelstrom_of_my_purity_born_of_pain, r=alexcrichton
make build tests not depend on minutiae of rustc output 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. supersedes #3513 r? @alexcrichton
2 parents 38f52ea + 88f6a30 commit 550bd43

File tree

2 files changed

+8
-36
lines changed

2 files changed

+8
-36
lines changed

tests/build.rs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,16 +2511,7 @@ fn compiler_json_error_format() {
25112511
"reason":"compiler-message",
25122512
"package_id":"bar 0.5.0 ([..])",
25132513
"target":{"kind":["lib"],"name":"bar","src_path":"[..]lib.rs"},
2514-
"message":{
2515-
"children":[],"code":null,"level":"warning","rendered":null,
2516-
"message":"function is never used: `dead`, #[warn(dead_code)] on by default",
2517-
"spans":[{
2518-
"byte_end":12,"byte_start":0,"column_end":13,"column_start":1,"expansion":null,
2519-
"file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1,
2520-
"suggested_replacement":null,
2521-
"text":[{"highlight_end":13,"highlight_start":1,"text":"fn dead() {}"}]
2522-
}]
2523-
}
2514+
"message":"{...}"
25242515
}
25252516
25262517
{
@@ -2541,16 +2532,7 @@ fn compiler_json_error_format() {
25412532
"reason":"compiler-message",
25422533
"package_id":"foo 0.5.0 ([..])",
25432534
"target":{"kind":["bin"],"name":"foo","src_path":"[..]main.rs"},
2544-
"message":{
2545-
"children":[],"code":null,"level":"warning","rendered":null,
2546-
"message":"unused variable: `unused`, #[warn(unused_variables)] on by default",
2547-
"spans":[{
2548-
"byte_end":22,"byte_start":16,"column_end":23,"column_start":17,"expansion":null,
2549-
"file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1,
2550-
"suggested_replacement":null,
2551-
"text":[{"highlight_end":23,"highlight_start":17,"text":"[..]"}]
2552-
}]
2553-
}
2535+
"message":"{...}"
25542536
}
25552537
25562538
{
@@ -2599,20 +2581,7 @@ fn message_format_json_forward_stderr() {
25992581
"reason":"compiler-message",
26002582
"package_id":"foo 0.5.0 ([..])",
26012583
"target":{"kind":["bin"],"name":"foo","src_path":"[..]"},
2602-
"message":{
2603-
"children":[],"code":null,"level":"warning","rendered":null,
2604-
"message":"unused variable: `unused`, #[warn(unused_variables)] on by default",
2605-
"spans":[{
2606-
"byte_end":22,"byte_start":16,"column_end":23,"column_start":17,"expansion":null,
2607-
"file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1,
2608-
"suggested_replacement":null,
2609-
"text":[{
2610-
"highlight_end":23,
2611-
"highlight_start":17,
2612-
"text":"fn main() { let unused = 0; }"
2613-
}]
2614-
}]
2615-
}
2584+
"message":"{...}"
26162585
}
26172586
26182587
{

tests/cargotest/support/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ fn lines_match_works() {
570570

571571
// Compares JSON object for approximate equality.
572572
// You can use `[..]` wildcard in strings (useful for OS dependent things such as paths).
573+
// You can use a `"{...}"` string literal as a wildcard for arbitrary nested JSON (useful
574+
// for parts of object emitted by other programs (e.g. rustc) rather than Cargo itself).
573575
// Arrays are sorted before comparison.
574576
fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json, &'a Json)> {
575577
use rustc_serialize::json::Json::*;
@@ -586,8 +588,7 @@ fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json,
586588

587589
fn sorted(xs: &Vec<Json>) -> Vec<&Json> {
588590
let mut result = xs.iter().collect::<Vec<_>>();
589-
// `unwrap` should be safe because JSON spec does not allow NaNs
590-
result.sort_by(|x, y| x.partial_cmp(y).unwrap());
591+
result.sort_by(|x, y| x.partial_cmp(y).expect("JSON spec does not allow NaNs"));
591592
result
592593
}
593594

@@ -606,6 +607,8 @@ fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json,
606607
.nth(0)
607608
}
608609
(&Null, &Null) => None,
610+
// magic string literal "{...}" acts as wildcard for any sub-JSON
611+
(&String(ref l), _) if l == "{...}" => None,
609612
_ => Some((expected, actual)),
610613
}
611614

0 commit comments

Comments
 (0)