Skip to content

Commit

Permalink
test: fix tap parser fails if a test logs a number
Browse files Browse the repository at this point in the history
PR-URL: nodejs#46056
Fixes: nodejs#46048
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
  • Loading branch information
pulkit-30 authored and MoLow committed Feb 25, 2023
1 parent f4264f0 commit 9c49554
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 140 deletions.
19 changes: 12 additions & 7 deletions lib/internal/test_runner/tap_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,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 @@ -282,12 +293,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
187 changes: 187 additions & 0 deletions test/parallel/test-runner-tap-parser-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 9c49554

Please sign in to comment.