Skip to content
Merged
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
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.

      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
commit 1b10b701b5893b59da4912105587998f55bddab3
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