Skip to content

Commit

Permalink
Accept trailing comma in test of impl Debug for PackageId
Browse files Browse the repository at this point in the history
The standard library is planning to begin emitting trailing commas in
multiline Debug representations to align with the dominant style in
modern Rust code.

      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
dtolnay committed Apr 3, 2019
1 parent b9bba2d commit 1b10b70
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 1b10b70

Please sign in to comment.