Skip to content

Commit

Permalink
test: fix invalid output TAP if there newline in test name
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
pulkit-30 authored and MoLow committed Feb 2, 2023
1 parent 71b659e commit c0854ac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
14 changes: 10 additions & 4 deletions lib/internal/test_runner/tap_stream.js
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/f8ce9117b19702487eb600493d941f7876e00e01/lib/internal/test_runner/tap_stream.js
// https://github.com/nodejs/node/blob/22dc987fde29734c5bcbb7c33da20d184ff61627/lib/internal/test_runner/tap_stream.js

'use strict'

Expand Down Expand Up @@ -134,9 +134,15 @@ class TapStream extends Readable {

// In certain places, # and \ need to be escaped as \# and \\.
function tapEscape (input) {
return StringPrototypeReplaceAll(
StringPrototypeReplaceAll(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) {
Expand Down
4 changes: 2 additions & 2 deletions test/message/test_runner_output.js
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/cb7e0c59df10a42cd6930ca7f99d3acee1ce7627/test/message/test_runner_output.js
// https://github.com/nodejs/node/blob/22dc987fde29734c5bcbb7c33da20d184ff61627/test/message/test_runner_output.js
// Flags: --no-warnings
'use strict'
require('../common')
Expand Down Expand Up @@ -214,7 +214,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' })
Expand Down
8 changes: 4 additions & 4 deletions test/message/test_runner_output.out
Expand Up @@ -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
Expand Down Expand Up @@ -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: *
...
Expand Down

0 comments on commit c0854ac

Please sign in to comment.