Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Promise = require('bluebird')
- var exec = require('child_process').exec
- // Array with input/output pairs
- var data = [
- ['input1', 'output1'],
- ['input2', 'output2'],
- ...
- ]
- var PROGRAM = 'cat'
- Promise.some(data.map(function(v) {
- var input = v[0]
- var output = v[1]
- new Promise(function(yell, cry) {
- // Yes it is ugly, but exec is just saves many lines here
- exec('echo "' + input + '" | ' + PROGRAM, function(err, stdout) {
- if(err) return cry(err)
- yell(stdout)
- })
- }).then(function(out) {
- if(out !== output) throw new Error('Output did not match!')
- })
- }), data.length) // Require them all to succeed
- .then(function() {
- // Send succes to user
- }).catch(function() {
- // Send failure to the user
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement