|
1 | 1 | mod redact; |
2 | 2 |
|
3 | 3 | use std::{ |
| 4 | + collections::BTreeMap, |
4 | 5 | env::{self, join_paths, split_paths}, |
5 | 6 | ffi::OsStr, |
6 | 7 | io::Write, |
@@ -59,6 +60,10 @@ struct StepConfig { |
59 | 60 | /// assertion. Default `false` keeps the plain-text behaviour. |
60 | 61 | #[serde(default, rename = "formatted-snapshot")] |
61 | 62 | formatted_snapshot: bool, |
| 63 | + /// Regex → replacement pairs for output that varies between runs, applied |
| 64 | + /// in key order after the global redactions. |
| 65 | + #[serde(default, deserialize_with = "deserialize_redactions")] |
| 66 | + redact: Vec<(regex::Regex, Str)>, |
62 | 67 | } |
63 | 68 |
|
64 | 69 | impl Step { |
@@ -148,6 +153,13 @@ impl Step { |
148 | 153 | Self::Simple(_) => false, |
149 | 154 | } |
150 | 155 | } |
| 156 | + |
| 157 | + fn redactions(&self) -> &[(regex::Regex, Str)] { |
| 158 | + match self { |
| 159 | + Self::Detailed(config) => &config.redact, |
| 160 | + Self::Simple(_) => &[], |
| 161 | + } |
| 162 | + } |
151 | 163 | } |
152 | 164 |
|
153 | 165 | #[derive(serde::Deserialize, Debug, Clone)] |
@@ -221,6 +233,22 @@ impl WriteKey { |
221 | 233 | } |
222 | 234 | } |
223 | 235 |
|
| 236 | +/// Compiles a step's `redact` table in key order, so an invalid regex fails |
| 237 | +/// when the fixtures load. |
| 238 | +fn deserialize_redactions<'de, D>(deserializer: D) -> Result<Vec<(regex::Regex, Str)>, D::Error> |
| 239 | +where |
| 240 | + D: serde::Deserializer<'de>, |
| 241 | +{ |
| 242 | + let table = <BTreeMap<Str, Str> as serde::Deserialize>::deserialize(deserializer)?; |
| 243 | + table |
| 244 | + .into_iter() |
| 245 | + .map(|(pattern, replacement)| { |
| 246 | + let regex = regex::Regex::new(pattern.as_str()).map_err(serde::de::Error::custom)?; |
| 247 | + Ok((regex, replacement)) |
| 248 | + }) |
| 249 | + .collect() |
| 250 | +} |
| 251 | + |
224 | 252 | fn deserialize_cfg_expr<'de, D>( |
225 | 253 | deserializer: D, |
226 | 254 | ) -> Result<Option<cargo_platform::CfgExpr>, D::Error> |
@@ -652,7 +680,7 @@ fn run_case( |
652 | 680 | } |
653 | 681 | } |
654 | 682 |
|
655 | | - e2e_outputs.push_str(&redact_e2e_output(output, e2e_stage_path_str)); |
| 683 | + e2e_outputs.push_str(&redact_e2e_output(output, e2e_stage_path_str, step.redactions())); |
656 | 684 |
|
657 | 685 | // Skip remaining steps if timed out |
658 | 686 | if matches!(termination_state, TerminationState::TimedOut) { |
|
0 commit comments