Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Do not ignore version lines that are in yaml
Browse files Browse the repository at this point in the history
This also has the effect of moving the 'line' event that starts a child
to *after* the child event that it starts, so that we can parse lines
coming out of the child rather than emitting 'line' on the way in.

The downside is that we have to be careful to emit a 'line' event once
we know what the thing is (ie, not a version, not something for a child,
not something that starts a child), so `emit('line')` function calls
happen in many more places.

But the ordering is somewhat more reasonable, in a way.  The child
object is created, and then we see its lines coming out.  And, it's
now possible to use the 'line' events as a pass-through stream that
filters out nested `TAP version 13` lines properly, cuts out
post-bailout noise, and so on.
  • Loading branch information
isaacs committed Jan 5, 2017
1 parent 231d8e2 commit 51e15fe
Show file tree
Hide file tree
Showing 25 changed files with 931 additions and 268 deletions.
42 changes: 27 additions & 15 deletions index.js
Expand Up @@ -124,6 +124,7 @@ function Parser (options, onComplete) {
this.bailingOut = false
this.bailedOut = false
this.syntheticBailout = false
this.syntheticPlan = false
this.omitVersion = !!options.omitVersion
this.planStart = -1
this.planEnd = -1
Expand Down Expand Up @@ -319,7 +320,7 @@ Parser.prototype.end = function (chunk, encoding, cb) {

this.emitResult()

if (this.syntheticBailout) {
if (this.syntheticBailout && this.level === 0) {
var reason = this.bailedOut
if (reason === true)
reason = ''
Expand All @@ -339,6 +340,7 @@ Parser.prototype.end = function (chunk, encoding, cb) {
}
} else if (!this.bailedOut && this.planStart === -1) {
if (this.count === 0) {
this.syntheticPlan = true
this.emit('line', '1..0\n')
this.plan(1, 0, '', '1..0\n')
skipAll = true
Expand Down Expand Up @@ -489,6 +491,9 @@ Parser.prototype.startChild = function (line) {
lineTypes.subtestIndent.test(line)
var unnamed = !maybeBuffered && !unindentStream && !indentStream

if (indentStream)
this.emit('line', line)

// If we have any other result waiting in the wings, we need to emit
// that now. A buffered test emits its test point at the *end* of
// the child subtest block, so as to match streamed test semantics.
Expand All @@ -511,6 +516,15 @@ Parser.prototype.startChild = function (line) {
self.ok = false
})

this.child.on('line', function (l) {
if (this.syntheticPlan)
return

if (l.trim() || self.preserveWhitespace)
l = ' ' + l
self.emit('line', l)
})

// Canonicalize the parsing result of any kind of subtest
// if it's a buffered subtest or a non-indented Subtest directive,
// then synthetically emit the Subtest comment
Expand Down Expand Up @@ -567,31 +581,24 @@ Parser.prototype._parse = function (line) {
// This allows omitting even parsing the version if the test is
// an indented child test. Several parsers get upset when they
// see an indented version field.
if (this.omitVersion && lineTypes.version.test(line))
if (this.omitVersion && lineTypes.version.test(line) && !this.yind)
return

// likewise, we ALWAYS skip the version for child tests.
if (lineTypes.childVersion.test(line))
// check to see if the line is indented.
// if it is, then it's either a subtest, yaml, or garbage.
var indent = line.match(/^[ \t]*/)[0]
if (indent) {
this.parseIndent(line, indent)
return
}

// this is a line we are processing, so emit it
if (this.preserveWhitespace || line.trim() || this.yind)
this.emit('line', line)

if (this.bailedOut)
return

if (line === '\n')
return

// check to see if the line is indented.
// if it is, then it's either a subtest, yaml, or garbage.
var indent = line.match(/^[ \t]*/)[0]
if (indent) {
this.parseIndent(line, indent)
return
}

// buffered subtests must end with a }
if (this.child && this.child.buffered && line === '}\n') {
this.current.name = this.current.name.replace(/{$/, '').trim()
Expand Down Expand Up @@ -705,6 +712,7 @@ Parser.prototype.parseIndent = function (line, indent) {
// continuing/ending yaml block
if (this.yind) {
if (line.indexOf(this.yind) === 0) {
this.emit('line', line)
this.yamlishLine(line)
return
} else {
Expand All @@ -719,6 +727,7 @@ Parser.prototype.parseIndent = function (line, indent) {
// start a yaml block under a test point
if (this.current && !this.yind && line === indent + '---\n') {
this.yind = indent
this.emit('line', line)
return
}

Expand Down Expand Up @@ -753,6 +762,7 @@ Parser.prototype.parseIndent = function (line, indent) {
var type = lineType(s[2])
if (type) {
if (type[0] === 'comment') {
this.emit('line', line)
this.emitComment(line)
} else {
// it's relevant! start as an "unnamed" child subtest
Expand All @@ -764,6 +774,8 @@ Parser.prototype.parseIndent = function (line, indent) {
}

// at this point, it's either a non-subtest comment, or garbage.
this.emit('line', line)

if (lineTypes.comment.test(line)) {
this.emitComment(line)
return
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/garbage-yamlish.json
Expand Up @@ -23,10 +23,6 @@
"line",
" severity: fail\n"
],
[
"line",
" this is not valid yamlish\n"
],
[
"assert",
{
Expand All @@ -39,6 +35,10 @@
"extra",
" ---\n message: \"Failed with error 'hostname peebles.example.com not found'\"\n severity: fail\n"
],
[
"line",
" this is not valid yamlish\n"
],
[
"extra",
" this is not valid yamlish\n"
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/line-break.json
Expand Up @@ -157,6 +157,10 @@
"line",
" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
],
[
"line",
" \n"
],
[
"line",
" yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n"
Expand Down
40 changes: 20 additions & 20 deletions test/fixtures/perl-test2-buffered.json
Expand Up @@ -11,10 +11,6 @@
"line",
"not ok 1 - empty {\n"
],
[
"line",
" 1..0\n"
],
[
"child",
[
Expand Down Expand Up @@ -55,6 +51,10 @@
]
]
],
[
"line",
" 1..0\n"
],
[
"line",
"}\n"
Expand All @@ -71,10 +71,6 @@
"line",
"ok 2 - my_test {\n"
],
[
"line",
" ok 1 - subtest event A\n"
],
[
"child",
[
Expand Down Expand Up @@ -139,6 +135,10 @@
]
]
],
[
"line",
" ok 1 - subtest event A\n"
],
[
"line",
" ok 2 - subtest event B\n"
Expand All @@ -163,10 +163,6 @@
"line",
"ok 3 - my_test_plan {\n"
],
[
"line",
" 1..2\n"
],
[
"child",
[
Expand Down Expand Up @@ -231,6 +227,10 @@
]
]
],
[
"line",
" 1..2\n"
],
[
"line",
" ok 1 - subtest event A\n"
Expand All @@ -255,10 +255,6 @@
"line",
"# Subtest: my_streamy_test\n"
],
[
"line",
" ok 1 - subtest event A\n"
],
[
"child",
[
Expand Down Expand Up @@ -323,6 +319,10 @@
]
]
],
[
"line",
" ok 1 - subtest event A\n"
],
[
"line",
" ok 2 - subtest event B\n"
Expand All @@ -339,10 +339,6 @@
"line",
"# Subtest: my_streamy_test_plan\n"
],
[
"line",
" 1..2\n"
],
[
"assert",
{
Expand Down Expand Up @@ -415,6 +411,10 @@
]
]
],
[
"line",
" 1..2\n"
],
[
"line",
" ok 1 - subtest event A\n"
Expand Down
16 changes: 8 additions & 8 deletions test/fixtures/perl-test2-streamed.json
Expand Up @@ -11,10 +11,6 @@
"line",
"# Subtest: my_streamy_test\n"
],
[
"line",
" ok 1 - subtest event A\n"
],
[
"child",
[
Expand Down Expand Up @@ -79,6 +75,10 @@
]
]
],
[
"line",
" ok 1 - subtest event A\n"
],
[
"line",
" ok 2 - subtest event B\n"
Expand All @@ -95,10 +95,6 @@
"line",
"# Subtest: my_streamy_test_plan\n"
],
[
"line",
" 1..2\n"
],
[
"assert",
{
Expand Down Expand Up @@ -171,6 +167,10 @@
]
]
],
[
"line",
" 1..2\n"
],
[
"line",
" ok 1 - subtest event A\n"
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/plan-in-bad-places-post.json
Expand Up @@ -11,10 +11,6 @@
"line",
"ok subtest {\n"
],
[
"line",
" 1..1\n"
],
[
"child",
[
Expand Down Expand Up @@ -66,6 +62,10 @@
]
]
],
[
"line",
" 1..1\n"
],
[
"line",
"1..99\n"
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/plan-in-bad-places-pre.json
Expand Up @@ -30,10 +30,6 @@
"line",
"ok subtest {\n"
],
[
"line",
" 1..1\n"
],
[
"child",
[
Expand Down Expand Up @@ -85,6 +81,10 @@
]
]
],
[
"line",
" 1..1\n"
],
[
"line",
"1..99\n"
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/pragma-mid-child.json
Expand Up @@ -23,10 +23,6 @@
"line",
"# Subtest\n"
],
[
"line",
" 1..1\n"
],
[
"child",
[
Expand Down Expand Up @@ -78,6 +74,10 @@
]
]
],
[
"line",
" 1..1\n"
],
[
"line",
"pragma +foo\n"
Expand Down

0 comments on commit 51e15fe

Please sign in to comment.