Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix tap parser fails if a test logs a number #46056

Merged
merged 8 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/internal/test_runner/tap_parser.js
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
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