Skip to content

Commit fa9c685

Browse files
Add Natvis visualizer tests in the CI pipeline to ensure Natvis does not break silently.
1 parent aefa86d commit fa9c685

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

.github/workflows/ci.yml

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
- nightly
2828
- macos
2929
- win-msvc
30+
- win-msvc (nightly)
3031
- win-gnu
3132
include:
3233
- build: pinned
@@ -55,6 +56,9 @@ jobs:
5556
- build: win-msvc
5657
os: windows-2019
5758
rust: stable
59+
- build: win-msvc (nightly)
60+
os: windows-2019
61+
rust: nightly
5862
- build: win-gnu
5963
os: windows-2019
6064
rust: stable-x86_64-gnu
@@ -156,6 +160,15 @@ jobs:
156160
run: |
157161
cargo test --test default --no-default-features --features 'std pattern unicode-perl'
158162
163+
# The #[debugger_visualizer] attribute is currently gated behind an unstable feature flag.
164+
# In order to test the visualizers for the regex crate, they have to be tested on a nightly build.
165+
- if: matrix.build == 'win-msvc (nightly)'
166+
name: Run visualizer tests with debugger_visualizer feature
167+
run: |
168+
# install the Debuginfo Test Runner to test visualizers defined for the regex crate
169+
cargo install dbt --git https://github.com/rust-lang/rust-dbg-ext.git --rev 2a17aa351ab66160464aace0e35370e3d671740a --bin dbt
170+
dbt -d cdb --cargo-workspace tests/visualizers --cargo-profile debug -o target
171+
159172
rustfmt:
160173
name: rustfmt
161174
runs-on: ubuntu-18.04

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ unstable = ["pattern"]
104104
# by default if the unstable feature is enabled.
105105
pattern = []
106106

107+
# Enable to use the #[debugger_visualizer] attribute.
108+
debugger_visualizer = []
109+
107110
# For very fast prefix literal matching.
108111
[dependencies.aho-corasick]
109112
version = "0.7.18"

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ another matching engine with fixed memory requirements.
607607

608608
#![deny(missing_docs)]
609609
#![cfg_attr(feature = "pattern", feature(pattern))]
610+
#![cfg_attr(feature = "debugger_visualizer", feature(debugger_visualizer))]
611+
#![cfg_attr(feature = "debugger_visualizer", debugger_visualizer(natvis_file = "../regex.natvis"))]
610612
#![warn(missing_debug_implementations)]
611613

612614
#[cfg(not(feature = "std"))]

tests/visualizers/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[workspace]
2+
members = [
3+
"natvis",
4+
]
5+
exclude = ["target"]
6+
7+
[profile.release]
8+
debug = 2

tests/visualizers/natvis/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "natvis"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies.regex]
9+
path = "../../../"
10+
features = ["debugger_visualizer"]

tests/visualizers/natvis/src/main.rs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/***
2+
3+
// See https://github.com/rust-lang/rust-dbg-ext/blob/main/test-framework/dbt/README.md
4+
// for more information on how these test scripts work.
5+
6+
#if @cdb
7+
// Start running the program
8+
g
9+
10+
// The following line checks that we actually hit the breakpoint.
11+
#check Breakpoint 0 hit
12+
13+
// Ensure the Natvis file for the regex crate is loaded.
14+
.nvlist
15+
#check natvis.exe (embedded NatVis "@{ .* }@natvis-0.natvis")
16+
17+
// Check the Natvis visualization for re::unicode::Regex
18+
dv
19+
dx re
20+
#check re : { text="hits="[0-9]+"" } [Type: regex::re_unicode::Regex]
21+
#check [<Raw View>] [Type: regex::re_unicode::Regex]
22+
#check [Reference count] : 0x2 [Type: core::sync::atomic::AtomicUsize]
23+
#check [Weak reference count] : 0x1 [Type: core::sync::atomic::AtomicUsize]
24+
#check [+0xc00] res : { len=0x1 } [Type: alloc::vec::Vec<alloc::string::String,alloc::alloc::Global>]
25+
#check [+0x000] nfa [Type: regex::prog::Program]
26+
#check [+0x320] dfa [Type: regex::prog::Program]
27+
#check [+0x640] dfa_reverse [Type: regex::prog::Program]
28+
#check [+0x960] suffixes [Type: regex::literal::imp::LiteralSearcher]
29+
#check [+0xc18] ac : None [Type: enum$<core::option::Option<aho_corasick::ahocorasick::AhoCorasick<u32> >, 0, 1, Some>]
30+
#check [+0xda0] match_type : Dfa [Type: enum$<regex::exec::MatchType>]
31+
32+
dx captures
33+
#check captures : { named_groups=0x0 } [Type: regex::re_unicode::Captures]
34+
#check [<Raw View>] [Type: regex::re_unicode::Captures]
35+
#check [text] : "<Type><hits="12123123123"></hits></Type>" [Type: str]
36+
#check [named_groups] : { len=0x0 } [Type: @{ .* }@]
37+
#check [0] : @{ .* }@ : "hits="12123123123"" [Type: char *]
38+
39+
g
40+
41+
dx m
42+
#check m : "hits="12123123123"" [Type: regex::re_unicode::Match]
43+
#check [<Raw View>] [Type: regex::re_unicode::Match]
44+
#check [text] : "<Type><hits="12123123123"></hits></Type>" [Type: str]
45+
#check [match_text] : "hits="12123123123""
46+
#check [start] : 0x7 [Type: unsigned __int64]
47+
#check [end] : 0x19 [Type: unsigned __int64]
48+
49+
q
50+
51+
#if not @cdb
52+
#ignore-test
53+
54+
***/
55+
56+
use regex::{Regex, Match};
57+
58+
pub fn main() {
59+
let re = Regex::new(r#"hits="[0-9]+""#).unwrap();
60+
let text = r#"<Type><hits="12123123123"></hits></Type>"#;
61+
62+
let captures = re.captures(text).unwrap();
63+
let matches = captures.iter().filter_map(|capture| capture).collect::<Vec<Match>>();
64+
assert_eq!(1, matches.len());
65+
_break(); // #break
66+
67+
for m in matches {
68+
_break(); // #break
69+
assert_eq!(r#"hits="12123123123""#, m.as_str());
70+
}
71+
}
72+
73+
#[inline(never)]
74+
pub fn _break() {}

0 commit comments

Comments
 (0)