-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
test_runner: parse yaml #45815
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
Merged
Merged
test_runner: parse yaml #45815
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
77bc2e9
test_runner: parse yaml
MoLow e3da4fe
CR
MoLow cf227ca
fix
MoLow 4779369
CR
MoLow 75a373d
CR
MoLow 5d12968
CR
MoLow cea1b3b
CR
MoLow c414f22
fix merge
MoLow 696861a
Update lib/internal/test_runner/yaml_parser.js
MoLow 99712ac
Apply suggestions from code review
MoLow 12bc970
CR
MoLow ce8fa7e
fix windows
MoLow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
'use strict'; | ||
const { | ||
codes: { | ||
ERR_TEST_FAILURE, | ||
} | ||
} = require('internal/errors'); | ||
const AssertionError = require('internal/assert/assertion_error'); | ||
const { | ||
ArrayPrototypeJoin, | ||
ArrayPrototypePush, | ||
Error, | ||
Number, | ||
NumberIsNaN, | ||
ObjectCreate, | ||
RegExpPrototypeExec, | ||
StringPrototypeEndsWith, | ||
StringPrototypeRepeat, | ||
StringPrototypeSlice, | ||
StringPrototypeStartsWith, | ||
StringPrototypeSubstring, | ||
} = primordials; | ||
|
||
const kYamlKeyRegex = /^(\s+)?(\w+):(\s)+([>|][-+])?(.*)$/; | ||
const kStackDelimiter = ' at '; | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function reConstructError(parsedYaml) { | ||
if (!('error' in parsedYaml)) { | ||
return parsedYaml; | ||
} | ||
const isAssertionError = parsedYaml.code === 'ERR_ASSERTION' || | ||
'actual' in parsedYaml || 'expected' in parsedYaml || 'operator' in parsedYaml; | ||
const isTestFailure = parsedYaml.code === 'ERR_TEST_FAILURE' || 'failureType' in parsedYaml; | ||
const stack = parsedYaml.stack ? kStackDelimiter + ArrayPrototypeJoin(parsedYaml.stack, `\n${kStackDelimiter}`) : ''; | ||
let error, cause; | ||
|
||
if (isAssertionError) { | ||
cause = new AssertionError({ | ||
message: parsedYaml.error, | ||
actual: parsedYaml.actual, | ||
expected: parsedYaml.expected, | ||
operator: parsedYaml.operator | ||
}); | ||
} else { | ||
// eslint-disable-next-line no-restricted-syntax | ||
cause = new Error(parsedYaml.error); | ||
cause.code = parsedYaml.code; | ||
} | ||
cause.stack = stack; | ||
|
||
if (isTestFailure) { | ||
error = new ERR_TEST_FAILURE(cause, parsedYaml.failureType); | ||
error.stack = stack; | ||
} | ||
|
||
parsedYaml.error = error ?? cause; | ||
delete parsedYaml.stack; | ||
delete parsedYaml.code; | ||
delete parsedYaml.failureType; | ||
delete parsedYaml.actual; | ||
delete parsedYaml.expected; | ||
delete parsedYaml.operator; | ||
|
||
return parsedYaml; | ||
} | ||
|
||
function getYamlValue(value) { | ||
if (StringPrototypeStartsWith(value, "'") && StringPrototypeEndsWith(value, "'")) { | ||
return StringPrototypeSlice(value, 1, -1); | ||
} | ||
if (value === 'true') { | ||
return true; | ||
} | ||
if (value === 'false') { | ||
return false; | ||
} | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (value !== '' && !NumberIsNaN(value)) { | ||
return Number(value); | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return value; | ||
} | ||
|
||
// This parses the yaml generated by the TAP reporter in tap_stream.js#jsToYaml | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// the yaml is a subset of the full yaml spec, so we there might be some | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// YAML features that won't be parsed here | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function YAMLToJs(lines) { | ||
const result = ObjectCreate(null); | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let isInYamlBlock = false; | ||
for (let i = 0; i < lines.length; i++) { | ||
const line = lines[i]; | ||
if (isInYamlBlock && !StringPrototypeStartsWith(line, StringPrototypeRepeat(' ', isInYamlBlock.indent))) { | ||
result[isInYamlBlock.key] = isInYamlBlock.key === 'stack' ? | ||
result[isInYamlBlock.key] : ArrayPrototypeJoin(result[isInYamlBlock.key], '\n'); | ||
isInYamlBlock = false; | ||
} | ||
if (isInYamlBlock) { | ||
const blockLine = StringPrototypeSubstring(line, isInYamlBlock.indent); | ||
ArrayPrototypePush(result[isInYamlBlock.key], blockLine); | ||
continue; | ||
} | ||
const match = RegExpPrototypeExec(kYamlKeyRegex, line); | ||
if (match !== null) { | ||
const { 1: leadingSpaces, 2: key, 4: block, 5: value } = match; | ||
if (block) { | ||
isInYamlBlock = { key, indent: (leadingSpaces?.length ?? 0) + 2 }; | ||
result[key] = []; | ||
} else { | ||
result[key] = getYamlValue(value); | ||
} | ||
} | ||
} | ||
return reConstructError(result); | ||
} | ||
|
||
module.exports = { | ||
YAMLToJs, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Flags: --no-warnings | ||
'use strict'; | ||
require('../common'); | ||
const spawn = require('node:child_process').spawn; | ||
spawn(process.execPath, | ||
['--no-warnings', '--test', 'test/message/test_runner_output.js'], { stdio: 'inherit' }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.