Commit f6fb1c1a authored by isaacs's avatar isaacs

Handle #time directives with buffered subtests

parent 4bfd7ae0
......@@ -22,7 +22,7 @@ module.exports = Parser
// every line outside of a yaml block is one of these things, or
// a comment, or garbage.
var lineTypes = {
testPoint: /^(not )?ok(?: ([0-9]+))?(?:(?: -)?( .*))?\n$/,
testPoint: /^(not )?ok(?: ([0-9]+))?(?:(?: -)?( .*?))?(\{?)\n$/,
pragma: /^pragma ([+-])([a-z]+)\n$/,
bailout: /^bail out!(.*)\n$/i,
version: /^TAP version ([0-9]+)\n$/i,
......@@ -45,7 +45,10 @@ function lineType (line) {
}
function parseDirective (line) {
line = line.trim()
if (!line.trim())
return false
line = line.replace(/\{\s*$/, '').trim()
var time = line.match(/^time=((?:[1-9][0-9]*|0)(?:\.[0-9]+)?)(ms|s)$/i)
if (time) {
var n = +time[1]
......@@ -68,6 +71,7 @@ function parseDirective (line) {
function Result (parsed, count) {
var ok = !parsed[1]
var id = +(parsed[2] || count + 1)
var buffered = parsed[4]
this.ok = ok
this.id = id
......@@ -80,27 +84,23 @@ function Result (parsed, count) {
// now, let's see if there's a directive in there.
var dir = parseDirective(rest.trim())
if (!dir)
name += rest ? '#' + rest : ''
name += (rest ? '#' + rest : '') + buffered
else {
// handle buffered subtests with todo/skip on them, like
// ok 1 - bar # todo foo {\n
var dirKey = dir[0]
var dirValue = dir[1]
if (typeof dirValue === 'string' && dirValue.slice(-1) === '{') {
name += ' {'
dirValue = dirValue.slice(0, -1).trim()
if (!dirValue) {
dirValue = true
}
}
this[dirKey] = dirValue
}
if (/\{$/.test(name)) {
name = name.slice(0, -1).trim()
this.buffered = true
if (/\{\s*$/.test(name)) {
name = name.replace(/\{\s*$/, '')
buffered = '{'
}
if (buffered === '{')
this.buffered = true
if (name)
this.name = name.trim()
......
[
[
"line",
"1..3\n"
],
[
"plan",
{
"start": 1,
"end": 3
}
],
[
"line",
"ok 1 - first # time=12.34ms {\n"
],
[
"child",
[
[
"comment",
"# Subtest: first\n"
],
[
"line",
"ok x\n"
],
[
"assert",
{
"ok": true,
"id": 1,
"name": "x"
}
],
[
"line",
"1..1\n"
],
[
"plan",
{
"start": 1,
"end": 1
}
],
[
"complete",
{
"ok": true,
"count": 1,
"pass": 1,
"fail": 0,
"bailout": false,
"todo": 0,
"skip": 0,
"plan": {
"start": 1,
"end": 1,
"skipAll": false,
"skipReason": "",
"comment": ""
},
"failures": []
}
]
]
],
[
"line",
" ok x\n"
],
[
"line",
" 1..1\n"
],
[
"line",
"}\n"
],
[
"assert",
{
"ok": true,
"id": 1,
"time": 12.34,
"buffered": true,
"name": "first"
}
],
[
"line",
"ok 2 - second { # time=12.34ms\n"
],
[
"child",
[
[
"comment",
"# Subtest: second\n"
],
[
"line",
"ok x\n"
],
[
"assert",
{
"ok": true,
"id": 1,
"name": "x"
}
],
[
"line",
"1..1\n"
],
[
"plan",
{
"start": 1,
"end": 1
}
],
[
"complete",
{
"ok": true,
"count": 1,
"pass": 1,
"fail": 0,
"bailout": false,
"todo": 0,
"skip": 0,
"plan": {
"start": 1,
"end": 1,
"skipAll": false,
"skipReason": "",
"comment": ""
},
"failures": []
}
]
]
],
[
"line",
" ok x\n"
],
[
"line",
" 1..1\n"
],
[
"line",
"}\n"
],
[
"assert",
{
"ok": true,
"id": 2,
"time": 12.34,
"buffered": true,
"name": "second"
}
],
[
"line",
"ok 3 - third # time=43.21ms\n"
],
[
"line",
" ---\n"
],
[
"line",
" some: diagnostic\n"
],
[
"line",
" ...\n"
],
[
"line",
"{\n"
],
[
"child",
[
[
"comment",
"# Subtest: third\n"
],
[
"line",
"ok y\n"
],
[
"assert",
{
"ok": true,
"id": 1,
"name": "y"
}
],
[
"line",
"1..1\n"
],
[
"plan",
{
"start": 1,
"end": 1
}
],
[
"complete",
{
"ok": true,
"count": 1,
"pass": 1,
"fail": 0,
"bailout": false,
"todo": 0,
"skip": 0,
"plan": {
"start": 1,
"end": 1,
"skipAll": false,
"skipReason": "",
"comment": ""
},
"failures": []
}
]
]
],
[
"line",
" ok y\n"
],
[
"line",
" 1..1\n"
],
[
"line",
"}\n"
],
[
"assert",
{
"ok": true,
"id": 3,
"time": 43.21,
"name": "third",
"diag": {
"some": "diagnostic"
},
"buffered": true
}
],
[
"complete",
{
"ok": true,
"count": 3,
"pass": 3,
"fail": 0,
"bailout": false,
"todo": 0,
"skip": 0,
"plan": {
"start": 1,
"end": 3,
"skipAll": false,
"skipReason": "",
"comment": ""
},
"failures": []
}
]
]
[
[
"line",
"1..3\n"
],
[
"plan",
{
"start": 1,
"end": 3
}
],
[
"line",
"ok 1 - first # time=12.34ms {\n"
],
[
"child",
[
[
"comment",
"# Subtest: first\n"
],
[
"line",
"ok x\n"
],
[
"assert",
{
"ok": true,
"id": 1,
"name": "x"
}
],
[
"line",
"1..1\n"
],
[
"plan",
{
"start": 1,
"end": 1
}
],
[
"complete",
{
"ok": true,
"count": 1,
"pass": 1,
"fail": 0,
"bailout": false,
"todo": 0,
"skip": 0,
"plan": {
"start": 1,
"end": 1,
"skipAll": false,
"skipReason": "",
"comment": ""
},
"failures": []
}
]
]
],
[
"line",
" ok x\n"
],
[
"line",
" 1..1\n"
],
[
"line",
"}\n"
],
[
"assert",
{
"ok": true,
"id": 1,
"time": 12.34,
"buffered": true,
"name": "first"
}
],
[
"line",
"ok 2 - second { # time=12.34ms\n"
],
[
"child",
[
[
"comment",
"# Subtest: second\n"
],
[
"line",
"ok x\n"
],
[
"assert",
{
"ok": true,
"id": 1,
"name": "x"
}
],
[
"line",
"1..1\n"
],
[
"plan",
{
"start": 1,
"end": 1
}
],
[
"complete",
{
"ok": true,
"count": 1,
"pass": 1,
"fail": 0,
"bailout": false,
"todo": 0,
"skip": 0,
"plan": {
"start": 1,
"end": 1,
"skipAll": false,
"skipReason": "",
"comment": ""
},
"failures": []
}
]
]
],
[
"line",
" ok x\n"
],
[
"line",
" 1..1\n"
],
[
"line",
"}\n"
],
[
"assert",
{
"ok": true,
"id": 2,
"time": 12.34,
"buffered": true,
"name": "second"
}
],
[
"line",
"ok 3 - third # time=43.21ms\n"
],
[
"line",
" ---\n"
],
[
"line",
" some: diagnostic\n"
],
[
"line",
" ...\n"
],
[
"line",
"{\n"
],
[
"child",
[
[
"comment",
"# Subtest: third\n"
],
[
"line",
"ok y\n"
],
[
"assert",
{
"ok": true,
"id": 1,
"name": "y"
}
],
[
"line",
"1..1\n"
],
[
"plan",
{
"start": 1,
"end": 1
}
],
[
"complete",
{
"ok": true,
"count": 1,
"pass": 1,
"fail": 0,
"bailout": false,
"todo": 0,
"skip": 0,
"plan": {
"start": 1,
"end": 1,
"skipAll": false,
"skipReason": "",
"comment": ""
},
"failures": []
}
]
]
],
[
"line",
" ok y\n"
],
[
"line",
" 1..1\n"
],
[
"line",
"}\n"
],
[
"assert",
{
"ok": true,
"id": 3,
"time": 43.21,
"name": "third",
"diag": {
"some": "diagnostic"
},
"buffered": true
}
],
[
"complete",
{
"ok": true,
"count": 3,
"pass": 3,
"fail": 0,
"bailout": false,
"todo": 0,
"skip": 0,
"plan": {
"start": 1,
"end": 3,
"skipAll": false,
"skipReason": "",
"comment": ""
},
"failures": []
}
]
]
[
[
"line",
"1..3\n"
],
[
"plan",
{
"start": 1,
"end": 3
}
],
[
"line",
"ok 1 - first # time=12.34ms {\n"
],
[
"child",
[
[
"comment",
"# Subtest: first\n"
],
[
"line",
"ok x\n"
],
[
"assert",
{
"ok": true,
"id": 1,
"name": "x"
}
],
[
"line",
"1..1\n"
],
[
"plan",
{
"start": 1,
"end": 1
}
],
[
"complete",
{
"ok": true,
"count": 1,
"pass": 1,
"fail": 0,
"bailout": false,
"todo": 0,
"skip": 0,
"plan": {
"start": 1,
"end": 1,
"skipAll": false,
"skipReason": "",