Skip to content

Commit 1b10b70

Browse files
committed
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.
1 parent b9bba2d commit 1b10b70

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/cargo/core/package_id.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,32 @@ mod tests {
224224
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
225225
assert_eq!(r#"PackageId { name: "foo", version: "1.0.0", source: "registry `https://github.com/rust-lang/crates.io-index`" }"#, format!("{:?}", pkg_id));
226226

227-
let pretty = r#"
227+
let expected = r#"
228+
PackageId {
229+
name: "foo",
230+
version: "1.0.0",
231+
source: "registry `https://github.com/rust-lang/crates.io-index`",
232+
}
233+
"#
234+
.trim();
235+
236+
// Can be removed once trailing commas in Debug have reached the stable
237+
// channel.
238+
let expected_without_trailing_comma = r#"
228239
PackageId {
229240
name: "foo",
230241
version: "1.0.0",
231242
source: "registry `https://github.com/rust-lang/crates.io-index`"
232243
}
233244
"#
234245
.trim();
235-
assert_eq!(pretty, format!("{:#?}", pkg_id));
246+
247+
let actual = format!("{:#?}", pkg_id);
248+
if actual.ends_with(",\n}") {
249+
assert_eq!(actual, expected);
250+
} else {
251+
assert_eq!(actual, expected_without_trailing_comma);
252+
}
236253
}
237254

238255
#[test]

0 commit comments

Comments
 (0)