From 6ea386e6ce638c2b7635257935c96325aadc9b2e Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <76155456+pulkit-30@users.noreply.github.com> Date: Mon, 5 Dec 2022 14:44:58 +0530 Subject: [PATCH 1/6] test: fix invalid output TAP if there newline in test name --- lib/internal/test_runner/tap_stream.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/test_runner/tap_stream.js b/lib/internal/test_runner/tap_stream.js index 3abd7ed5560664..259e686dace629 100644 --- a/lib/internal/test_runner/tap_stream.js +++ b/lib/internal/test_runner/tap_stream.js @@ -131,9 +131,9 @@ class TapStream extends Readable { // In certain places, # and \ need to be escaped as \# and \\. function tapEscape(input) { - return StringPrototypeReplaceAll( + return StringPrototypeReplaceAll(StringPrototypeReplaceAll( StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#' - ); + ), '\n', '\\n'); } function jsToYaml(indent, name, value) { From 7ac8cba1b563d3c915743ccb87c64ede37661daf Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <76155456+pulkit-30@users.noreply.github.com> Date: Wed, 7 Dec 2022 20:53:44 +0530 Subject: [PATCH 2/6] fix to replace some more escape chars --- lib/internal/test_runner/tap_stream.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/internal/test_runner/tap_stream.js b/lib/internal/test_runner/tap_stream.js index 259e686dace629..c501f177085885 100644 --- a/lib/internal/test_runner/tap_stream.js +++ b/lib/internal/test_runner/tap_stream.js @@ -131,9 +131,18 @@ class TapStream extends Readable { // In certain places, # and \ need to be escaped as \# and \\. function tapEscape(input) { - return StringPrototypeReplaceAll(StringPrototypeReplaceAll( - StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#' - ), '\n', '\\n'); + [{ escapeChar: '\\', tappedEscape: '\\\\' }, + { escapeChar: '#', tappedEscape: '\\#' }, + { escapeChar: '\n', tappedEscape: '\\n' }, + { escapeChar: '\t', tappedEscape: '\\t' }, + { escapeChar: '\r', tappedEscape: '\\r' }, + { escapeChar: '\f', tappedEscape: '\\f' }, + { escapeChar: '\b', tappedEscape: '\\b' }, + { escapeChar: '\v', tappedEscape: '\\v' }, + ].forEach(({ escapeChar, tappedEscape }) => { + input = StringPrototypeReplaceAll(input, escapeChar, tappedEscape); + }); + return input; } function jsToYaml(indent, name, value) { From b3bc57f520454719c18cbe1488fbd81634d6d710 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <76155456+pulkit-30@users.noreply.github.com> Date: Thu, 8 Dec 2022 18:54:53 +0530 Subject: [PATCH 3/6] added test for tapEscape function --- lib/internal/test_runner/tap_stream.js | 2 +- test/parallel/test-runner-tap-parser-stream.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/tap_stream.js b/lib/internal/test_runner/tap_stream.js index c501f177085885..72fb2334f5b267 100644 --- a/lib/internal/test_runner/tap_stream.js +++ b/lib/internal/test_runner/tap_stream.js @@ -270,4 +270,4 @@ function isAssertionLike(value) { return value && typeof value === 'object' && 'expected' in value && 'actual' in value; } -module.exports = { TapStream }; +module.exports = { TapStream, tapEscape }; diff --git a/test/parallel/test-runner-tap-parser-stream.js b/test/parallel/test-runner-tap-parser-stream.js index bd10af29d88279..52b4112161e208 100644 --- a/test/parallel/test-runner-tap-parser-stream.js +++ b/test/parallel/test-runner-tap-parser-stream.js @@ -4,6 +4,7 @@ const common = require('../common'); 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'); const cases = [ { @@ -627,3 +628,17 @@ ok 1 - test 1 expected.map((item) => ({ __proto__: null, ...item })) ); })().then(common.mustCall()); + +(async () => { + [{ escapeChar: '\\', tappedEscape: '\\\\' }, + { escapeChar: '#', tappedEscape: '\\#' }, + { escapeChar: '\n', tappedEscape: '\\n' }, + { escapeChar: '\t', tappedEscape: '\\t' }, + { escapeChar: '\r', tappedEscape: '\\r' }, + { escapeChar: '\f', tappedEscape: '\\f' }, + { escapeChar: '\b', tappedEscape: '\\b' }, + { escapeChar: '\v', tappedEscape: '\\v' }, + ].forEach(({ escapeChar, tappedEscape }) => { + assert.strictEqual(tapEscape(escapeChar), tappedEscape); + }); +})().then(common.mustCall()); From e4ea715d37c09b23035e7eb996b1daa85bf078ee Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <76155456+pulkit-30@users.noreply.github.com> Date: Sat, 10 Dec 2022 21:19:54 +0530 Subject: [PATCH 4/6] moved test to test/message/test_runner_output.js file --- test/message/test_runner_output.js | 2 +- test/message/test_runner_output.out | 8 ++++---- test/parallel/test-runner-tap-parser-stream.js | 15 --------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/test/message/test_runner_output.js b/test/message/test_runner_output.js index 2a71cd3e16e143..47087303a715ed 100644 --- a/test/message/test_runner_output.js +++ b/test/message/test_runner_output.js @@ -213,7 +213,7 @@ test('test with a name and options provided', { skip: true }); test({ skip: true }, function functionAndOptions() {}); // A test whose description needs to be escaped. -test('escaped description \\ # \\#\\'); +test('escaped description \\ # \\#\\ \n \t \f \v \b \r'); // A test whose skip message needs to be escaped. test('escaped skip message', { skip: '#skip' }); diff --git a/test/message/test_runner_output.out b/test/message/test_runner_output.out index 96d977b21c5b1a..14479c773bbc86 100644 --- a/test/message/test_runner_output.out +++ b/test/message/test_runner_output.out @@ -127,9 +127,9 @@ not ok 13 - async assertion fail failureType: 'testCodeFailure' error: |- Expected values to be strictly equal: - + true !== false - + code: 'ERR_ASSERTION' expected: false actual: true @@ -353,8 +353,8 @@ ok 36 - functionAndOptions # SKIP --- duration_ms: * ... -# Subtest: escaped description \\ \# \\\#\\ -ok 37 - escaped description \\ \# \\\#\\ +# Subtest: escaped description \\ \# \\\#\\ \n \t \f \v \b \r +ok 37 - escaped description \\ \# \\\#\\ \n \t \f \v \b \r --- duration_ms: * ... diff --git a/test/parallel/test-runner-tap-parser-stream.js b/test/parallel/test-runner-tap-parser-stream.js index 52b4112161e208..bd10af29d88279 100644 --- a/test/parallel/test-runner-tap-parser-stream.js +++ b/test/parallel/test-runner-tap-parser-stream.js @@ -4,7 +4,6 @@ const common = require('../common'); 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'); const cases = [ { @@ -628,17 +627,3 @@ ok 1 - test 1 expected.map((item) => ({ __proto__: null, ...item })) ); })().then(common.mustCall()); - -(async () => { - [{ escapeChar: '\\', tappedEscape: '\\\\' }, - { escapeChar: '#', tappedEscape: '\\#' }, - { escapeChar: '\n', tappedEscape: '\\n' }, - { escapeChar: '\t', tappedEscape: '\\t' }, - { escapeChar: '\r', tappedEscape: '\\r' }, - { escapeChar: '\f', tappedEscape: '\\f' }, - { escapeChar: '\b', tappedEscape: '\\b' }, - { escapeChar: '\v', tappedEscape: '\\v' }, - ].forEach(({ escapeChar, tappedEscape }) => { - assert.strictEqual(tapEscape(escapeChar), tappedEscape); - }); -})().then(common.mustCall()); From 5b8e01eca177e8e5a816e36c1369d06c6a379ab7 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <76155456+pulkit-30@users.noreply.github.com> Date: Sat, 10 Dec 2022 21:35:14 +0530 Subject: [PATCH 5/6] used inclined way to escape chars --- lib/internal/test_runner/tap_stream.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/internal/test_runner/tap_stream.js b/lib/internal/test_runner/tap_stream.js index 72fb2334f5b267..5249b8e7dabd02 100644 --- a/lib/internal/test_runner/tap_stream.js +++ b/lib/internal/test_runner/tap_stream.js @@ -131,18 +131,15 @@ class TapStream extends Readable { // In certain places, # and \ need to be escaped as \# and \\. function tapEscape(input) { - [{ escapeChar: '\\', tappedEscape: '\\\\' }, - { escapeChar: '#', tappedEscape: '\\#' }, - { escapeChar: '\n', tappedEscape: '\\n' }, - { escapeChar: '\t', tappedEscape: '\\t' }, - { escapeChar: '\r', tappedEscape: '\\r' }, - { escapeChar: '\f', tappedEscape: '\\f' }, - { escapeChar: '\b', tappedEscape: '\\b' }, - { escapeChar: '\v', tappedEscape: '\\v' }, - ].forEach(({ escapeChar, tappedEscape }) => { - input = StringPrototypeReplaceAll(input, escapeChar, tappedEscape); - }); - return input; + let result = StringPrototypeReplaceAll(input, '\\', '\\\\'); + result = StringPrototypeReplaceAll(result, '#', '\\#'); + result = StringPrototypeReplaceAll(result,'\b', '\\b'); + result = StringPrototypeReplaceAll(result,'\f', '\\f'); + result = StringPrototypeReplaceAll(result,'\t', '\\t'); + result = StringPrototypeReplaceAll(result,'\n', '\\n'); + result = StringPrototypeReplaceAll(result,'\r', '\\r'); + result = StringPrototypeReplaceAll(result,'\v', '\\v'); + return result; } function jsToYaml(indent, name, value) { @@ -270,4 +267,4 @@ function isAssertionLike(value) { return value && typeof value === 'object' && 'expected' in value && 'actual' in value; } -module.exports = { TapStream, tapEscape }; +module.exports = { TapStream }; From 6a6f57e02edea7fe4f5082ae7da3f19df6917b6f Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <76155456+pulkit-30@users.noreply.github.com> Date: Sat, 10 Dec 2022 21:39:26 +0530 Subject: [PATCH 6/6] fix: lint errors --- lib/internal/test_runner/tap_stream.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/internal/test_runner/tap_stream.js b/lib/internal/test_runner/tap_stream.js index 5249b8e7dabd02..a5834ee46f2014 100644 --- a/lib/internal/test_runner/tap_stream.js +++ b/lib/internal/test_runner/tap_stream.js @@ -133,12 +133,12 @@ class TapStream extends Readable { function tapEscape(input) { let result = StringPrototypeReplaceAll(input, '\\', '\\\\'); result = StringPrototypeReplaceAll(result, '#', '\\#'); - result = StringPrototypeReplaceAll(result,'\b', '\\b'); - result = StringPrototypeReplaceAll(result,'\f', '\\f'); - result = StringPrototypeReplaceAll(result,'\t', '\\t'); - result = StringPrototypeReplaceAll(result,'\n', '\\n'); - result = StringPrototypeReplaceAll(result,'\r', '\\r'); - result = StringPrototypeReplaceAll(result,'\v', '\\v'); + result = StringPrototypeReplaceAll(result, '\b', '\\b'); + result = StringPrototypeReplaceAll(result, '\f', '\\f'); + result = StringPrototypeReplaceAll(result, '\t', '\\t'); + result = StringPrototypeReplaceAll(result, '\n', '\\n'); + result = StringPrototypeReplaceAll(result, '\r', '\\r'); + result = StringPrototypeReplaceAll(result, '\v', '\\v'); return result; }