Skip to content

make build tests not depend on minutiae of rustc output #3628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 3 additions & 34 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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":"{...}"
}

{
Expand All @@ -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":"{...}"
}

{
Expand Down Expand Up @@ -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":"{...}"
}

{
Expand Down
7 changes: 5 additions & 2 deletions tests/cargotest/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -586,8 +588,7 @@ fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json,

fn sorted(xs: &Vec<Json>) -> Vec<&Json> {
let mut result = xs.iter().collect::<Vec<_>>();
// `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
}

Expand All @@ -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)),
}

Expand Down