Skip to content

Commit

Permalink
Auto merge of #6818 - dtolnay:comma, r=alexcrichton
Browse files Browse the repository at this point in the history
Accept trailing comma in test of impl Debug for PackageId

The standard library is planning to begin emitting trailing commas in multiline Debug representations to align with the dominant style in modern Rust code -- rust-lang/rust#59076.

```diff
  PackageId {
      name: "foo",
      version: "1.0.0",
-     source: "registry `https://github.com/rust-lang/crates.io-index`"
+     source: "registry `https://github.com/rust-lang/crates.io-index`",
  }
```

For now, change this tests to accept both with and without trailing comma. Once the trailing comma change reaches the stable channel we will be able to remove one of the cases.
  • Loading branch information
bors committed Apr 3, 2019
2 parents b9bba2d + 1b10b70 commit d62dcd6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,32 @@ mod tests {
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
assert_eq!(r#"PackageId { name: "foo", version: "1.0.0", source: "registry `https://github.com/rust-lang/crates.io-index`" }"#, format!("{:?}", pkg_id));

let pretty = r#"
let expected = r#"
PackageId {
name: "foo",
version: "1.0.0",
source: "registry `https://github.com/rust-lang/crates.io-index`",
}
"#
.trim();

// Can be removed once trailing commas in Debug have reached the stable
// channel.
let expected_without_trailing_comma = r#"
PackageId {
name: "foo",
version: "1.0.0",
source: "registry `https://github.com/rust-lang/crates.io-index`"
}
"#
.trim();
assert_eq!(pretty, format!("{:#?}", pkg_id));

let actual = format!("{:#?}", pkg_id);
if actual.ends_with(",\n}") {
assert_eq!(actual, expected);
} else {
assert_eq!(actual, expected_without_trailing_comma);
}
}

#[test]
Expand Down

0 comments on commit d62dcd6

Please sign in to comment.