Skip to content

Instantly share code, notes, and snippets.

@ralphtheninja
Created March 4, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralphtheninja/6e18d0857f4c5dc2c9d8 to your computer and use it in GitHub Desktop.
Save ralphtheninja/6e18d0857f4c5dc2c9d8 to your computer and use it in GitHub Desktop.
simple script for running a command until it breaks
#!/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()
@ralphtheninja
Copy link
Author

This is a wip. Should also show how long it took, average time and things like that. Could also potentially parse tap output to produce an aggregated tap output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment