Skip to content

Commit

Permalink
split up output tests by type, not name
Browse files Browse the repository at this point in the history
Juggling the alphabet is too hard as the number of tests and cases
increases.  Passing two booleans to a function feels like it should
probably be an options object, but whatever.  We can cross that bridge
later.

Also, this allows running a single case in an ad-hoc manner which is a
bit more convenient in development.
  • Loading branch information
isaacs committed Jan 3, 2017
1 parent 1469b9d commit 9ea5a52
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/test-output-am.js → test/test-bail-buffer.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var runTests = require('./test.js')
runTests('[a-m]*.js')
runTests('*.js', true, true)
2 changes: 1 addition & 1 deletion test/test-output-nz.js → test/test-bail.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var runTests = require('./test.js')
runTests('[n-z]*.js')
runTests('*.js', true, false)
2 changes: 2 additions & 0 deletions test/test-buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var runTests = require('./test.js')
runTests('*.js', false, true)
36 changes: 28 additions & 8 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,41 @@ function regEsc (str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')
}

module.exports = function (pattern) {
glob.sync(dir + pattern).forEach(runTests)
module.exports = function (pattern, bail, buffer) {
glob.sync(dir + pattern).forEach(function (f) {
runTests(f, bail, buffer)
})
}

if (module === require.main) {
if (process.argv[2]) {
module.exports(process.argv[2])
var bail, buffer
process.argv.slice(3).forEach(function (x) {
switch (x) {
case 'bail': return bail = true
case 'buffer': return buffer = true
case 'nobail': return bail = false
case 'nobuffer': return buffer = false
}
})
module.exports(process.argv[2], bail, buffer)
} else {
t.pass('just a common file')
module.exports('*.js', false, false)
}
}

function runTests (file) {
function runTests (file, bail, buffer) {
var bails = [ !!bail ]
var buffs = [ !!buffer ]

if (bail === undefined) {
bails = [ true, false ]
}

if (buffer === undefined) {
buffs = [ true, false ]
}

var skip = false
if (file.match(/\b(timeout.*|pending-handles)\.js$/)) {
if (process.env.TRAVIS) {
Expand All @@ -43,9 +65,7 @@ function runTests (file) {

var f = file.substr(dir.length)
t.test(f, { skip: skip }, function (t) {
var bails = [ true, false ]
var buffs = [ true, false ]
t.plan(4)
t.plan(bails.length * buffs.length)
bails.forEach(function (bail) {
buffs.forEach(function (buff) {
t.test('bail=' + bail + ' buffer=' + buff, function (t) {
Expand Down

0 comments on commit 9ea5a52

Please sign in to comment.