summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPulkit Gupta <pulkit30.bsr@gmail.com>2023-02-06 22:28:51 +0530
committerGitHub <noreply@github.com>2023-02-06 16:58:51 +0000
commit4c08c20e575a0954fe3977a20e9f52b4980a2e48 (patch)
tree3a368cd72a1fae6e8c05252e45c70e14e75a7749
parent138696897e9cff96beeb8368242bf3879db90719 (diff)
downloadnode-new-4c08c20e575a0954fe3977a20e9f52b4980a2e48.tar.gz
test: fix tap parser fails if a test logs a number
PR-URL: https://github.com/nodejs/node/pull/46056 Fixes: https://github.com/nodejs/node/issues/46048 Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
-rw-r--r--lib/internal/test_runner/tap_parser.js19
-rw-r--r--test/parallel/test-runner-tap-parser-stream.js187
-rw-r--r--test/parallel/test-runner-tap-parser.js133
3 files changed, 199 insertions, 140 deletions
diff --git a/lib/internal/test_runner/tap_parser.js b/lib/internal/test_runner/tap_parser.js
index c502c05eb8..f4d73bb12b 100644
--- a/lib/internal/test_runner/tap_parser.js
+++ b/lib/internal/test_runner/tap_parser.js
@@ -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);
@@ -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') {
diff --git a/test/parallel/test-runner-tap-parser-stream.js b/test/parallel/test-runner-tap-parser-stream.js
index bd10af29d8..80be92c121 100644
--- a/test/parallel/test-runner-tap-parser-stream.js
+++ b/test/parallel/test-runner-tap-parser-stream.js
@@ -18,6 +18,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: [
{
diff --git a/test/parallel/test-runner-tap-parser.js b/test/parallel/test-runner-tap-parser.js
index 530e56626a..b14f7a9a6b 100644
--- a/test/parallel/test-runner-tap-parser.js
+++ b/test/parallel/test-runner-tap-parser.js
@@ -73,24 +73,6 @@ function TAPParser(input) {
]);
}
-{
- assert.throws(() => TAPParser('TAP version'), {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected a version number, received "version" (VersionKeyword) at line 1, column 5 (start 4, end 10)',
- });
-}
-
-{
- assert.throws(() => TAPParser('TAP'), {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected "version" keyword, received "TAP" (TAPKeyword) at line 1, column 1 (start 0, end 2)',
- });
-}
-
// Test plan
{
@@ -123,42 +105,6 @@ function TAPParser(input) {
]);
}
-{
- assert.throws(() => TAPParser('1..'), {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected a plan end count, received "" (EOL) at line 1, column 4 (start 3, end 3)',
- });
-}
-
-{
- assert.throws(() => TAPParser('1..abc'), {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected ".." symbol, received "..abc" (Literal) at line 1, column 2 (start 1, end 5)',
- });
-}
-
-{
- assert.throws(() => TAPParser('1..-1'), {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected a plan end count, received "-" (Dash) at line 1, column 4 (start 3, end 3)',
- });
-}
-
-{
- assert.throws(() => TAPParser('1.1'), {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected ".." symbol, received "." (Literal) at line 1, column 2 (start 1, end 1)',
- });
-}
-
// Test point
{
@@ -919,24 +865,6 @@ ok 6 - nested1
() =>
TAPParser(
`
- message: 'description'
- property: 'value'
- ...`
- ),
- {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Unexpected YAML end marker, received "..." (YamlEndKeyword) at line 4, column 3 (start 48, end 50)',
- }
- );
-}
-
-{
- assert.throws(
- () =>
- TAPParser(
- `
---
message: 'description'
property: 'value'`
@@ -953,26 +881,6 @@ ok 6 - nested1
{
assert.throws(
() =>
- // Note the leading 3 spaces before ---
- TAPParser(
- `
- ---
- message: 'description'
- property: 'value'
- ...`
- ),
- {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected valid YAML indentation (2 spaces), received " " (Whitespace) at line 2, column 3 (start 3, end 3)',
- }
- );
-}
-
-{
- assert.throws(
- () =>
// Note the leading 5 spaces before ---
// This is a special case because the YAML block is indented by 1 space
// the extra 4 spaces are those of the subtest nesting level.
@@ -998,27 +906,6 @@ ok 6 - nested1
{
assert.throws(
() =>
- // Note the leading 4 spaces before ---
- TAPParser(
- `
- ---
- message: 'description'
- property: 'value'
- ...
- `
- ),
- {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected a valid token, received "---" (YamlStartKeyword) at line 2, column 5 (start 5, end 7)',
- }
- );
-}
-
-{
- assert.throws(
- () =>
// Note the leading 4 spaces before ...
TAPParser(
`
@@ -1067,26 +954,6 @@ ok 6 - nested1
]);
}
-// Non-recognized
-
-{
- assert.throws(() => TAPParser('abc'), {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected a valid token, received "abc" (Literal) at line 1, column 1 (start 0, end 2)',
- });
-}
-
-{
- assert.throws(() => TAPParser(' abc'), {
- name: 'SyntaxError',
- code: 'ERR_TAP_PARSER_ERROR',
- message:
- 'Expected a valid token, received "abc" (Literal) at line 1, column 5 (start 4, end 6)',
- });
-}
-
// TAP document (with diagnostics)
{