Skip to content

Commit 4f5aff2

Browse files
pulkit-30juanarbol
authored andcommittedMar 5, 2023
test: fix tap parser fails if a test logs a number
PR-URL: #46056 Backport-PR-URL: #46839 Fixes: #46048 Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent ba784e8 commit 4f5aff2

File tree

3 files changed

+199
-140
lines changed

3 files changed

+199
-140
lines changed
 

‎lib/internal/test_runner/tap_parser.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,19 @@ class TapParser extends Transform {
270270
this.#yamlCurrentIndentationLevel = this.#subTestNestingLevel;
271271
}
272272

273+
let node;
274+
273275
// Parse current chunk
274-
const node = this.#TAPDocument(chunk);
276+
try {
277+
node = this.#TAPDocument(chunk);
278+
} catch {
279+
node = {
280+
kind: TokenKind.UNKNOWN,
281+
node: {
282+
value: this.#currentChunkAsString,
283+
},
284+
};
285+
}
275286

276287
// Emit the parsed node to both the stream and the AST
277288
this.#emitOrBufferCurrentNode(node);
@@ -282,12 +293,6 @@ class TapParser extends Transform {
282293
}
283294

284295
#error(message) {
285-
if (!this.#isSyncParsingEnabled) {
286-
// When async parsing is enabled, don't throw.
287-
// Unrecognized tokens would be ignored.
288-
return;
289-
}
290-
291296
const token = this.#currentToken || { value: '', kind: '' };
292297
// Escape NewLine characters
293298
if (token.value === '\n') {

‎test/parallel/test-runner-tap-parser-stream.js

+187
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,193 @@ const cases = [
1717
},
1818
],
1919
},
20+
{
21+
input: '123',
22+
expected: [
23+
{
24+
kind: 'Unknown',
25+
node: { value: '123' },
26+
nesting: 0,
27+
lexeme: '123',
28+
},
29+
],
30+
},
31+
{
32+
input: '# 123',
33+
expected: [
34+
{
35+
kind: 'Comment',
36+
node: { comment: '123' },
37+
nesting: 0,
38+
lexeme: '# 123',
39+
},
40+
],
41+
},
42+
{
43+
input: '1..',
44+
expected: [
45+
{
46+
kind: 'Unknown',
47+
node: { value: '1..' },
48+
nesting: 0,
49+
lexeme: '1..',
50+
},
51+
],
52+
},
53+
{
54+
input: '1..abc',
55+
expected: [
56+
{
57+
kind: 'Unknown',
58+
node: { value: '1..abc' },
59+
nesting: 0,
60+
lexeme: '1..abc',
61+
},
62+
],
63+
},
64+
{
65+
input: '1..-1',
66+
expected: [
67+
{
68+
kind: 'Unknown',
69+
node: { value: '1..-1' },
70+
nesting: 0,
71+
lexeme: '1..-1',
72+
},
73+
],
74+
},
75+
{
76+
input: '1.1',
77+
expected: [
78+
{
79+
kind: 'Unknown',
80+
node: { value: '1.1' },
81+
nesting: 0,
82+
lexeme: '1.1',
83+
},
84+
],
85+
},
86+
{
87+
input: '1.....4',
88+
expected: [
89+
{
90+
kind: 'Unknown',
91+
node: { value: '1.....4' },
92+
nesting: 0,
93+
lexeme: '1.....4',
94+
},
95+
],
96+
},
97+
{
98+
input: 'TAP 12',
99+
expected: [
100+
{
101+
kind: 'Unknown',
102+
node: { value: 'TAP 12' },
103+
nesting: 0,
104+
lexeme: 'TAP 12',
105+
},
106+
],
107+
},
108+
{
109+
input: 'TAP version',
110+
expected: [
111+
{
112+
kind: 'Unknown',
113+
node: { value: 'TAP version' },
114+
nesting: 0,
115+
lexeme: 'TAP version',
116+
},
117+
],
118+
},
119+
{
120+
input: 'TAP version v14',
121+
expected: [
122+
{
123+
kind: 'Unknown',
124+
node: { value: 'TAP version v14' },
125+
nesting: 0,
126+
lexeme: 'TAP version v14',
127+
},
128+
],
129+
},
130+
{
131+
input: 'TAP TAP TAP',
132+
expected: [
133+
{
134+
kind: 'Unknown',
135+
node: { value: 'TAP TAP TAP' },
136+
nesting: 0,
137+
lexeme: 'TAP TAP TAP',
138+
},
139+
],
140+
},
141+
{
142+
input: '--- yaml',
143+
expected: [
144+
{
145+
kind: 'Unknown',
146+
node: { value: '--- yaml' },
147+
nesting: 0,
148+
lexeme: '--- yaml',
149+
},
150+
],
151+
},
152+
{
153+
input: '... ... yaml',
154+
expected: [
155+
{
156+
kind: 'Unknown',
157+
node: { value: '... ... yaml' },
158+
nesting: 0,
159+
lexeme: '... ... yaml',
160+
},
161+
],
162+
},
163+
{
164+
input: 'ook 1',
165+
expected: [
166+
{
167+
kind: 'Unknown',
168+
node: { value: 'ook 1' },
169+
nesting: 0,
170+
lexeme: 'ook 1',
171+
},
172+
],
173+
},
174+
{
175+
input: ' ok 98',
176+
expected: [
177+
{
178+
kind: 'Unknown',
179+
node: { value: ' ok 98' },
180+
nesting: 0,
181+
lexeme: ' ok 98',
182+
},
183+
],
184+
},
185+
{
186+
input: 'pragma ++++++',
187+
expected: [
188+
{
189+
kind: 'Unknown',
190+
node: { value: 'pragma ++++++' },
191+
nesting: 0,
192+
lexeme: 'pragma ++++++',
193+
},
194+
],
195+
},
196+
{
197+
input: 'Bailout!',
198+
expected: [
199+
{
200+
kind: 'Unknown',
201+
node: { value: 'Bailout!' },
202+
nesting: 0,
203+
lexeme: 'Bailout!',
204+
},
205+
],
206+
},
20207
{
21208
input: 'invalid tap',
22209
expected: [

‎test/parallel/test-runner-tap-parser.js

-133
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,6 @@ function TAPParser(input) {
7373
]);
7474
}
7575

76-
{
77-
assert.throws(() => TAPParser('TAP version'), {
78-
name: 'SyntaxError',
79-
code: 'ERR_TAP_PARSER_ERROR',
80-
message:
81-
'Expected a version number, received "version" (VersionKeyword) at line 1, column 5 (start 4, end 10)',
82-
});
83-
}
84-
85-
{
86-
assert.throws(() => TAPParser('TAP'), {
87-
name: 'SyntaxError',
88-
code: 'ERR_TAP_PARSER_ERROR',
89-
message:
90-
'Expected "version" keyword, received "TAP" (TAPKeyword) at line 1, column 1 (start 0, end 2)',
91-
});
92-
}
93-
9476
// Test plan
9577

9678
{
@@ -123,42 +105,6 @@ function TAPParser(input) {
123105
]);
124106
}
125107

126-
{
127-
assert.throws(() => TAPParser('1..'), {
128-
name: 'SyntaxError',
129-
code: 'ERR_TAP_PARSER_ERROR',
130-
message:
131-
'Expected a plan end count, received "" (EOL) at line 1, column 4 (start 3, end 3)',
132-
});
133-
}
134-
135-
{
136-
assert.throws(() => TAPParser('1..abc'), {
137-
name: 'SyntaxError',
138-
code: 'ERR_TAP_PARSER_ERROR',
139-
message:
140-
'Expected ".." symbol, received "..abc" (Literal) at line 1, column 2 (start 1, end 5)',
141-
});
142-
}
143-
144-
{
145-
assert.throws(() => TAPParser('1..-1'), {
146-
name: 'SyntaxError',
147-
code: 'ERR_TAP_PARSER_ERROR',
148-
message:
149-
'Expected a plan end count, received "-" (Dash) at line 1, column 4 (start 3, end 3)',
150-
});
151-
}
152-
153-
{
154-
assert.throws(() => TAPParser('1.1'), {
155-
name: 'SyntaxError',
156-
code: 'ERR_TAP_PARSER_ERROR',
157-
message:
158-
'Expected ".." symbol, received "." (Literal) at line 1, column 2 (start 1, end 1)',
159-
});
160-
}
161-
162108
// Test point
163109

164110
{
@@ -914,24 +860,6 @@ ok 6 - nested1
914860
]);
915861
}
916862

917-
{
918-
assert.throws(
919-
() =>
920-
TAPParser(
921-
`
922-
message: 'description'
923-
property: 'value'
924-
...`
925-
),
926-
{
927-
name: 'SyntaxError',
928-
code: 'ERR_TAP_PARSER_ERROR',
929-
message:
930-
'Unexpected YAML end marker, received "..." (YamlEndKeyword) at line 4, column 3 (start 48, end 50)',
931-
}
932-
);
933-
}
934-
935863
{
936864
assert.throws(
937865
() =>
@@ -950,26 +878,6 @@ ok 6 - nested1
950878
);
951879
}
952880

953-
{
954-
assert.throws(
955-
() =>
956-
// Note the leading 3 spaces before ---
957-
TAPParser(
958-
`
959-
---
960-
message: 'description'
961-
property: 'value'
962-
...`
963-
),
964-
{
965-
name: 'SyntaxError',
966-
code: 'ERR_TAP_PARSER_ERROR',
967-
message:
968-
'Expected valid YAML indentation (2 spaces), received " " (Whitespace) at line 2, column 3 (start 3, end 3)',
969-
}
970-
);
971-
}
972-
973881
{
974882
assert.throws(
975883
() =>
@@ -995,27 +903,6 @@ ok 6 - nested1
995903
);
996904
}
997905

998-
{
999-
assert.throws(
1000-
() =>
1001-
// Note the leading 4 spaces before ---
1002-
TAPParser(
1003-
`
1004-
---
1005-
message: 'description'
1006-
property: 'value'
1007-
...
1008-
`
1009-
),
1010-
{
1011-
name: 'SyntaxError',
1012-
code: 'ERR_TAP_PARSER_ERROR',
1013-
message:
1014-
'Expected a valid token, received "---" (YamlStartKeyword) at line 2, column 5 (start 5, end 7)',
1015-
}
1016-
);
1017-
}
1018-
1019906
{
1020907
assert.throws(
1021908
() =>
@@ -1067,26 +954,6 @@ ok 6 - nested1
1067954
]);
1068955
}
1069956

1070-
// Non-recognized
1071-
1072-
{
1073-
assert.throws(() => TAPParser('abc'), {
1074-
name: 'SyntaxError',
1075-
code: 'ERR_TAP_PARSER_ERROR',
1076-
message:
1077-
'Expected a valid token, received "abc" (Literal) at line 1, column 1 (start 0, end 2)',
1078-
});
1079-
}
1080-
1081-
{
1082-
assert.throws(() => TAPParser(' abc'), {
1083-
name: 'SyntaxError',
1084-
code: 'ERR_TAP_PARSER_ERROR',
1085-
message:
1086-
'Expected a valid token, received "abc" (Literal) at line 1, column 5 (start 4, end 6)',
1087-
});
1088-
}
1089-
1090957
// TAP document (with diagnostics)
1091958

1092959
{

0 commit comments

Comments
 (0)
Please sign in to comment.