test: fix invalid output TAP if there newline in test name#45742
test: fix invalid output TAP if there newline in test name#45742nodejs-github-bot merged 6 commits intonodejs:mainfrom
Conversation
| return StringPrototypeReplaceAll(StringPrototypeReplaceAll( | ||
| StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#' | ||
| ); | ||
| ), '\n', '\\n'); |
There was a problem hiding this comment.
What about \r, \v, \b, and \f?
Hey @aduh95 |
|
| const assert = require('node:assert'); | ||
| const { TapParser } = require('internal/test_runner/tap_parser'); | ||
| const { TapChecker } = require('internal/test_runner/tap_checker'); | ||
| const { tapEscape } = require('internal/test_runner/tap_stream'); |
There was a problem hiding this comment.
So, I don't think this file is the best place for testing this. This file is more about the TAP parser.
I would test this by doing the following:
- Undo the changes in this file.
- Remove the
tapEscapeexport that this PR adds tolib/internal/test_runner/tap_stream.js. - Add a test to
test/message/test_runner_output.jsthat uses\n,\r, etc (#and\are already tested IIRC). - Update
test/message/test_runner_output.outto reflect the changes in the test output.
There was a problem hiding this comment.
updating this 👍🏽 🚀
| return StringPrototypeReplaceAll( | ||
| StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#' | ||
| ); | ||
| [{ escapeChar: '\\', tappedEscape: '\\\\' }, |
There was a problem hiding this comment.
Even though the resulting code will not look as nice as this, I'm inclined to use a series of StringPrototypeReplaceAll() calls here instead.
There was a problem hiding this comment.
@cjihrig like this... right?
return StringPrototypeReplaceAll(StringPrototypeReplaceAll(
StringPrototypeReplaceAll(StringPrototypeReplaceAll(
StringPrototypeReplaceAll(StringPrototypeReplaceAll(
StringPrototypeReplaceAll(StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#'),
'\b', '\\b'), '\f', '\\f'), '\t', '\\t'), '\n', '\\n'), '\r', '\\r'), '\v', '\\v');There was a problem hiding this comment.
You could do it that way. You could also do something like this to maintain more readability:
let result = StringPrototypeReplaceAll(...);
result = StringPrototypeReplaceAll(...);
result = StringPrototypeReplaceAll(...);
return result;| ); | ||
| let result = StringPrototypeReplaceAll(input, '\\', '\\\\'); | ||
| result = StringPrototypeReplaceAll(result, '#', '\\#'); | ||
| result = StringPrototypeReplaceAll(result,'\b', '\\b'); |
There was a problem hiding this comment.
Same change on the following lines. Other than that, I think this looks good.
| result = StringPrototypeReplaceAll(result,'\b', '\\b'); | |
| result = StringPrototypeReplaceAll(result, '\b', '\\b'); |
There was a problem hiding this comment.
Sorry, didn't notice that 😞
fixed 🚀
|
Landed in 22dc987 |
PR-URL: nodejs#45742 Fixes: nodejs#45396 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs/node#45742 Fixes: nodejs/node#45396 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> (cherry picked from commit 22dc987fde29734c5bcbb7c33da20d184ff61627)
fixes: #45396
fix test outputs invalid TAP if there is a newline in the test name
Fixed Changes
Test Case:
Output