Created
March 4, 2015 14:02
-
-
Save ralphtheninja/6e18d0857f4c5dc2c9d8 to your computer and use it in GitHub Desktop.
simple script for running a command until it breaks
This file contains 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
#!/usr/bin/env node | |
var spawn = require('child_process').spawn | |
var argv = process.argv.slice(2) | |
if (argv.length === 0) { | |
console.log('missing command') | |
} | |
var cmd = argv[0] | |
var args = argv.splice(1) | |
var runs = 0 | |
var success = 0 | |
var fail = 0 | |
// todo: be able to run: | |
// 1. until it breaks, or | |
// 2. until `runs` reaches some upper limit | |
function run() { | |
// todo: if should be quiet .. do not inherit stdio | |
var child = spawn(cmd, args, { stdio: 'inherit' }) | |
++runs | |
child.on('close', function (code) { | |
if (code === 0) { | |
++success | |
process.nextTick(run) | |
} | |
else { | |
++fail | |
printStats() | |
} | |
}) | |
child.on('error', function (err) {}) | |
} | |
process.on('SIGINT', function () { | |
printStats() | |
process.exit(0) | |
}) | |
function printStats() { | |
console.log('\nran %d times', runs) | |
console.log('succeeded %d times', success) | |
console.log('failed %d times', fail) | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a
wip
. Should also show how long it took, average time and things like that. Could also potentially parsetap
output to produce an aggregated tap output.