diff options
| author | Martin Nordholts <martin.nordholts@codetale.se> | 2025-01-03 17:51:32 +0100 |
|---|---|---|
| committer | Martin Nordholts <martin.nordholts@codetale.se> | 2025-02-15 17:22:45 +0100 |
| commit | 9479b6f0ead1787a895f82473eeb57dd74fded5a (patch) | |
| tree | 298d7ca9febaea489a4a8c53f0660677392ff3d7 | |
| parent | 71763208216e44901c4865119458edc8e6e466c1 (diff) | |
| download | rust-9479b6f0ead1787a895f82473eeb57dd74fded5a.tar.gz rust-9479b6f0ead1787a895f82473eeb57dd74fded5a.zip | |
tests: Add regression test for `Debug` impl of raw pointers
| -rw-r--r-- | library/Cargo.lock | 26 | ||||
| -rw-r--r-- | library/coretests/Cargo.toml | 1 | ||||
| -rw-r--r-- | library/coretests/tests/fmt/mod.rs | 31 |
3 files changed, 58 insertions, 0 deletions
diff --git a/library/Cargo.lock b/library/Cargo.lock index 0be2f9a1549..061c8db4e02 100644 --- a/library/Cargo.lock +++ b/library/Cargo.lock @@ -79,6 +79,7 @@ version = "0.0.0" dependencies = [ "rand", "rand_xorshift", + "regex", ] [[package]] @@ -298,6 +299,31 @@ dependencies = [ ] [[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/library/coretests/Cargo.toml b/library/coretests/Cargo.toml index e44f01d347b..88a7e159c95 100644 --- a/library/coretests/Cargo.toml +++ b/library/coretests/Cargo.toml @@ -25,3 +25,4 @@ test = true [dev-dependencies] rand = { version = "0.9.0", default-features = false } rand_xorshift = { version = "0.4.0", default-features = false } +regex = { version = "1.11.1", default-features = false } diff --git a/library/coretests/tests/fmt/mod.rs b/library/coretests/tests/fmt/mod.rs index 381615ed397..13f7bca646f 100644 --- a/library/coretests/tests/fmt/mod.rs +++ b/library/coretests/tests/fmt/mod.rs @@ -20,6 +20,37 @@ fn test_pointer_formats_data_pointer() { } #[test] +fn test_fmt_debug_of_raw_pointers() { + use core::fmt::Debug; + + fn check_fmt<T: Debug>(t: T, expected: &str) { + use std::sync::LazyLock; + + use regex::Regex; + + static ADDR_REGEX: LazyLock<Regex> = + LazyLock::new(|| Regex::new(r"0x[0-9a-fA-F]+").unwrap()); + + let formatted = format!("{:?}", t); + let normalized = ADDR_REGEX.replace_all(&formatted, "$$HEX"); + + assert_eq!(normalized, expected); + } + + let plain = &mut 100; + check_fmt(plain as *mut i32, "$HEX"); + check_fmt(plain as *const i32, "$HEX"); + + let slice = &mut [200, 300, 400][..]; + check_fmt(slice as *mut [i32], "$HEX"); + check_fmt(slice as *const [i32], "$HEX"); + + let vtable = &mut 500 as &mut dyn Debug; + check_fmt(vtable as *mut dyn Debug, "$HEX"); + check_fmt(vtable as *const dyn Debug, "$HEX"); +} + +#[test] fn test_estimated_capacity() { assert_eq!(format_args!("").estimated_capacity(), 0); assert_eq!(format_args!("{}", { "" }).estimated_capacity(), 0); |
