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 <[email protected]>
This commit is contained in:
1 parent
980bd9c5d4
commit
0cbf912c16
2 files changed
+17
-1
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user