tr: handle trailing-backslash warnings for both sets#13488
tr: handle trailing-backslash warnings for both sets#13488EffortlessSteven wants to merge 1 commit into
Conversation
| fn emit_warning(message: impl Display) { | ||
| emit_diagnostic(format_args!("warning: {message}")); | ||
| } |
There was a problem hiding this comment.
i don't think this function is useful
just call
emit_diagnostic(format_args!("warning: {message}"));
directly instead
(please update your agents.md configuration to avoid this in the future btw ;)
also, it needs to use translate!() to allow translation of warnings
There was a problem hiding this comment.
Removed the forwarding helper and moved the complete warning text into Fluent, so the call sites now use emit_diagnostic(translate!(...)) directly.
This changes two existing Fluent source messages from warning bodies into complete warnings, so their external translations will need refreshing. I followed the complete-warning pattern used by sync.
| ); | ||
| } else { | ||
| show_warning!("{}", translate!("tr-warning-invalid-utf8")); | ||
| emit_warning(translate!("tr-warning-invalid-utf8")); |
There was a problem hiding this comment.
yeah, clearly not a useful function :)
|
|
||
| #[cfg(target_os = "linux")] | ||
| #[test] | ||
| fn test_ambiguous_octal_warning_write_failure() { |
There was a problem hiding this comment.
merge this one with the test above
(probably with a loop with the values/expectations)
There was a problem hiding this comment.
Done. Merged the two warning-write cases into one table-driven test.
tr checked only SET1 for an unescaped trailing backslash, so SET2 never produced GNU's portability warning. Warning writes also went through helpers that discard stderr errors, so redirecting a warning to /dev/full still exited successfully. Move terminal-backslash detection from the SET1-only pre-scan in tr.rs to operand parse completion, so SET1 and SET2 are checked in parse order and the warning follows any warning emitted while scanning the same operand. Parse both operands before applying semantic validation, so SET2 warnings and syntax errors surface ahead of a semantic rejection of a syntactically valid SET1. Add a tr-local checked diagnostic writer that records exit status 1 when a warning cannot be written, without returning early, so stdin processing and stdout output continue. Route tr's existing ambiguous-octal and invalid-UTF-8 warnings through the same writer. The shared uucore diagnostic macros are unchanged. Move the localized "warning: " label into the tr-warning-* Fluent messages so the label and its locale-specific punctuation are translated rather than hardcoded in Rust. This changes two existing message keys from warning bodies into complete warnings.
ba373e5 to
f4c2699
Compare
What this does
trchecks only SET1 for an unescaped trailing backslash, sotr . '\'does not emit GNU's portability warning for SET2. Those warning paths discard stderr write errors, sotr . '\' 2>/dev/fullexits 0 where GNU exits 1.Fix: check each operand at parse completion, so both sets warn in operand order. Parse both operands before semantic validation so SET2 diagnostics precede a SET1 semantic error. A checked writer records exit status 1 when a warning cannot be written and keeps translating, preserving stdout. That writer remains local to
tr; shareduucorediagnostic macros are unchanged, and warning text is localized through Fluent.Fixes #12961.
Verification
/dev/full'\\'stays silenttr '[x*]' 'z-a'ordering[c*]error, patched reports GNU's SET2 range errortr.pl,tr-case-class.sh, BusyBoxtrtest_trclippy -D warnings,fmt,cspell, MSRV 1.88)Review map
Sequence::from_str: warns after scanning the whole operand, so the warning follows parser warnings and precedes a syntax error from that operand.Sequence::solve_set_characters: parses SET1 then SET2 before any semantic check, preserving SET1 syntax precedence.emit_diagnostic: writes each localized diagnostic once, recording status 1 on write failure so translation can continue.tr.rsuumain: drops the SET1-only pre-scan and itsshow!(USimpleError::new(0, ...)).tests/by-util/test_tr.rs: operand coverage, ordering, and/dev/fullfailures with stdout preserved.