Skip to content

Commit

Permalink
fix: fix tap parser fails if a test logs a number
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#46056
Fixes: nodejs/node#46048
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
(cherry picked from commit 4c08c20e575a0954fe3977a20e9f52b4980a2e48)
  • Loading branch information
pulkit-30 authored and MoLow committed Feb 7, 2023
1 parent 22ccbdf commit fba53c3
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 143 deletions.
21 changes: 13 additions & 8 deletions lib/internal/test_runner/tap_parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/931f035bac8326a11f42fc05463d5b21d9bec502/lib/internal/test_runner/tap_parser.js
// https://github.com/nodejs/node/blob/4c08c20e575a0954fe3977a20e9f52b4980a2e48/lib/internal/test_runner/tap_parser.js
'use strict'

const {
Expand Down Expand Up @@ -271,8 +271,19 @@ class TapParser extends Transform {
this.#yamlCurrentIndentationLevel = this.#subTestNestingLevel
}

let node

// Parse current chunk
const node = this.#TAPDocument(chunk)
try {
node = this.#TAPDocument(chunk)
} catch {
node = {
kind: TokenKind.UNKNOWN,
node: {
value: this.#currentChunkAsString
}
}
}

// Emit the parsed node to both the stream and the AST
this.#emitOrBufferCurrentNode(node)
Expand All @@ -283,12 +294,6 @@ class TapParser extends Transform {
}

#error (message) {
if (!this.#isSyncParsingEnabled) {
// When async parsing is enabled, don't throw.
// Unrecognized tokens would be ignored.
return
}

const token = this.#currentToken || { value: '', kind: '' }
// Escape NewLine characters
if (token.value === '\n') {
Expand Down
189 changes: 188 additions & 1 deletion test/parallel/test-runner-tap-parser-stream.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/f8ce9117b19702487eb600493d941f7876e00e01/test/parallel/test-runner-tap-parser-stream.js
// https://github.com/nodejs/node/blob/4c08c20e575a0954fe3977a20e9f52b4980a2e48/test/parallel/test-runner-tap-parser-stream.js
// Flags: --expose-internals
'use strict'
const common = require('../common')
Expand All @@ -19,6 +19,193 @@ const cases = [
}
]
},
{
input: '123',
expected: [
{
kind: 'Unknown',
node: { value: '123' },
nesting: 0,
lexeme: '123'
}
]
},
{
input: '# 123',
expected: [
{
kind: 'Comment',
node: { comment: '123' },
nesting: 0,
lexeme: '# 123'
}
]
},
{
input: '1..',
expected: [
{
kind: 'Unknown',
node: { value: '1..' },
nesting: 0,
lexeme: '1..'
}
]
},
{
input: '1..abc',
expected: [
{
kind: 'Unknown',
node: { value: '1..abc' },
nesting: 0,
lexeme: '1..abc'
}
]
},
{
input: '1..-1',
expected: [
{
kind: 'Unknown',
node: { value: '1..-1' },
nesting: 0,
lexeme: '1..-1'
}
]
},
{
input: '1.1',
expected: [
{
kind: 'Unknown',
node: { value: '1.1' },
nesting: 0,
lexeme: '1.1'
}
]
},
{
input: '1.....4',
expected: [
{
kind: 'Unknown',
node: { value: '1.....4' },
nesting: 0,
lexeme: '1.....4'
}
]
},
{
input: 'TAP 12',
expected: [
{
kind: 'Unknown',
node: { value: 'TAP 12' },
nesting: 0,
lexeme: 'TAP 12'
}
]
},
{
input: 'TAP version',
expected: [
{
kind: 'Unknown',
node: { value: 'TAP version' },
nesting: 0,
lexeme: 'TAP version'
}
]
},
{
input: 'TAP version v14',
expected: [
{
kind: 'Unknown',
node: { value: 'TAP version v14' },
nesting: 0,
lexeme: 'TAP version v14'
}
]
},
{
input: 'TAP TAP TAP',
expected: [
{
kind: 'Unknown',
node: { value: 'TAP TAP TAP' },
nesting: 0,
lexeme: 'TAP TAP TAP'
}
]
},
{
input: '--- yaml',
expected: [
{
kind: 'Unknown',
node: { value: '--- yaml' },
nesting: 0,
lexeme: '--- yaml'
}
]
},
{
input: '... ... yaml',
expected: [
{
kind: 'Unknown',
node: { value: '... ... yaml' },
nesting: 0,
lexeme: '... ... yaml'
}
]
},
{
input: 'ook 1',
expected: [
{
kind: 'Unknown',
node: { value: 'ook 1' },
nesting: 0,
lexeme: 'ook 1'
}
]
},
{
input: ' ok 98',
expected: [
{
kind: 'Unknown',
node: { value: ' ok 98' },
nesting: 0,
lexeme: ' ok 98'
}
]
},
{
input: 'pragma ++++++',
expected: [
{
kind: 'Unknown',
node: { value: 'pragma ++++++' },
nesting: 0,
lexeme: 'pragma ++++++'
}
]
},
{
input: 'Bailout!',
expected: [
{
kind: 'Unknown',
node: { value: 'Bailout!' },
nesting: 0,
lexeme: 'Bailout!'
}
]
},
{
input: 'invalid tap',
expected: [
Expand Down
Loading

0 comments on commit fba53c3

Please sign in to comment.