From 0cbf912c164416e07756488188f422c52fa13064 Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 19 Aug 2026 00:54:20 -0700 Subject: [PATCH] Escape tabs/newlines in verification diagnostics Item's Display printed raw comment text, so a comment containing a tab or spanning lines embedded raw control bytes in the diagnostic, splitting one logical error across stderr lines/TSV fields (found by corpus-check QA via tools/corpus_check.sh). Use {:?} like parser.rs does for its "found" token, keeping one diagnostic = one line. Co-Authored-By: Claude Fable 5 --- crates/vlog_formatter/src/verify.rs | 5 ++++- crates/vlog_formatter/tests/verification.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/vlog_formatter/src/verify.rs b/crates/vlog_formatter/src/verify.rs index c31280e..dbedda3 100644 --- a/crates/vlog_formatter/src/verify.rs +++ b/crates/vlog_formatter/src/verify.rs @@ -86,7 +86,10 @@ impl Item { impl fmt::Display for Item { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{} `{}` at {}:{}", self.kind, self.text, self.line, self.col) + // `{:?}` escapes embedded tabs/newlines (comment text can contain + // both), keeping every diagnostic a single physical line — CLI + // consumers treat one stderr line as one diagnostic. + write!(f, "{} {:?} at {}:{}", self.kind, self.text, self.line, self.col) } } diff --git a/crates/vlog_formatter/tests/verification.rs b/crates/vlog_formatter/tests/verification.rs index 4ec948e..b3981fc 100644 --- a/crates/vlog_formatter/tests/verification.rs +++ b/crates/vlog_formatter/tests/verification.rs @@ -187,6 +187,19 @@ fn format_source_reports_source_errors_as_source_errors() { } } +#[test] +fn diagnostics_stay_on_one_physical_line() { + // Comment text can carry tabs and newlines; the rendered diagnostic + // must escape them, since CLI consumers (e.g. tools/corpus_check.sh) + // treat one stderr line as one diagnostic. + let input = "module m;\n /* a\tb\n c */\n wire x;\nendmodule\n"; + let output = "module m;\n wire x;\nendmodule\n"; + let rendered = expect_divergence(input, output).to_string(); + assert!(!rendered.contains('\t'), "raw tab in: {rendered}"); + assert!(!rendered.contains('\n'), "raw newline in: {rendered}"); + assert!(rendered.contains("\\t") && rendered.contains("\\n"), "{rendered}"); +} + #[test] fn format_source_would_reject_a_non_equivalent_output() { // The real formatter is expected never to produce such output, so the