Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. var Promise = require('bluebird')
  2. var exec = require('child_process').exec
  3.  
  4. // Array with input/output pairs
  5. var data = [
  6. ['input1', 'output1'],
  7. ['input2', 'output2'],
  8. ...
  9. ]
  10.  
  11. var PROGRAM = 'cat'
  12.  
  13. Promise.some(data.map(function(v) {
  14. var input = v[0]
  15. var output = v[1]
  16.  
  17. new Promise(function(yell, cry) {
  18. // Yes it is ugly, but exec is just saves many lines here
  19. exec('echo "' + input + '" | ' + PROGRAM, function(err, stdout) {
  20. if(err) return cry(err)
  21. yell(stdout)
  22. })
  23. }).then(function(out) {
  24. if(out !== output) throw new Error('Output did not match!')
  25. })
  26. }), data.length) // Require them all to succeed
  27. .then(function() {
  28. // Send succes to user
  29. }).catch(function() {
  30. // Send failure to the user
  31. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement