Reduce the failure without changing it
Begin with authorized, non-sensitive input and remove unrelated lines, fields and values one at a time. Keep one positive case, one near miss and one clearly negative case. A useful minimal fixture preserves Unicode, line endings, whitespace and delimiters that affect the behavior while removing credentials, personal data and production identifiers.
Write the expected observation before running a tool. For a regex, name the complete matches and capture groups. For a diff, name whether order and whitespace matter. For SQL, state whether the goal is readability, syntactic validity, equivalent results or an execution plan. These are different tests and need different authorities.
Test the exact regular-expression engine
Regex syntax and behavior vary across JavaScript, PCRE, RE2, .NET, Java and database engines. Flags, Unicode properties, lookbehind, named groups, anchors and replacement escaping can differ. A browser tester establishes JavaScript behavior in that browser; transfer the fixture to the production language before accepting the expression.
Include empty input, multiline input, non-ASCII text and a long adversarial near match. Backtracking expressions can be fast on examples and unexpectedly expensive on a crafted failure. Set input limits and execution controls where untrusted users influence a pattern or sample, and prefer a linear-time engine when the application threat model requires it.
Interpret a positional line diff correctly
A positional comparer places line one beside line one, line two beside line two and so on. That is helpful for small fixed-layout configuration snapshots. It is not a sequence alignment algorithm: one insertion shifts every later pair and can produce a large apparent change. Move to a version-control diff when insertions and deletions are normal.
Structured formats deserve structured comparison. Parse JSON, YAML, XML or configuration into a model, normalize only documented irrelevant properties and compare semantic values. Do not sort arrays or trim whitespace unless the format says order or spacing is irrelevant. A clean semantic diff should retain a path back to the original source line for review.
Separate SQL formatting from database validation
A lightweight SQL formatter can reveal FROM, WHERE, JOIN and ordering clauses in a simple statement. Whitespace replacement based on keywords does not understand comments, quoted identifiers, dollar-quoted strings, procedural blocks or every dialect operator. Never assume a reformatted statement preserves meaning merely because it looks cleaner.
Use the target database parser for syntax and a non-production transaction or explain-only facility for behavior. Parameter values belong in bound parameters rather than string concatenation. Compare returned rows, types, ordering and query plans when changing a production query, and preserve the original statement for review.
Turn observations into regression tests
Keep the minimal input, expected output, runtime version and reason for the assertion together. Add negative cases that fail for the intended reason and one boundary case that would have caught the original defect. A screenshot or copied output is supporting evidence; an executable test in the target runtime is the durable result.
- State the engine and version for every syntax test.
- Use semantic parsers for structured data.
- Treat formatting as presentation until the target parser verifies it.