null+****@clear*****
null+****@clear*****
2012年 8月 6日 (月) 12:29:12 JST
SHIMODA Hiroshi 2012-08-06 12:29:12 +0900 (Mon, 06 Aug 2012) New Revision: 791fc7bdd806453ef686339d7b23e811e7d9e9b1 https://github.com/groonga/gcs/commit/791fc7bdd806453ef686339d7b23e811e7d9e9b1 Log: Define "utils.run()" as a shared helper for tests about command line interfaces Modified files: test/gcs.test.js test/test-utils.js Modified: test/gcs.test.js (+6 -24) =================================================================== --- test/gcs.test.js 2012-08-06 13:49:05 +0900 (44d7efd) +++ test/gcs.test.js 2012-08-06 12:29:12 +0900 (b9d4400) @@ -1,32 +1,14 @@ +var utils = require('./test-utils'); var assert = require('chai').assert; -var spawn = require('child_process').spawn; - -function run(options, callback) { - var command, commandPath, output; - commandPath = __dirname + '/../bin/gcs'; - command = spawn(commandPath, options); - output = { - stdout: '', - stderr: '' - }; - command.stdout.on('data', function(data) { - output.stdout += data; - }); - command.stderr.on('data', function(data) { - output.stderr += data; - }); - callback(null, command, output); -} suite('gcs command', function() { test('should output help for --help', function(done) { - run(['--help'], function(error, command, output) { - command.on('exit', function(code) { - assert.equal(output.stderr, ''); - assert.include(output.stdout, 'Usage:'); - assert.equal(code, 0); + utils.run('gcs', '--help') + .next(function(result) { + assert.equal(result.output.stderr, ''); + assert.include(result.output.stdout, 'Usage:'); + assert.equal(result.code, 0); done(); }); - }); }); }); Modified: test/test-utils.js (+26 -0) =================================================================== --- test/test-utils.js 2012-08-06 13:49:05 +0900 (78272d9) +++ test/test-utils.js 2012-08-06 12:29:12 +0900 (ebf620d) @@ -7,6 +7,7 @@ var Deferred = require('jsdeferred').Deferred; var nativeNroonga = require('nroonga'); var wrappedNroonga = require(__dirname + '/../lib/wrapped-nroonga'); var xml2js = require('xml2js'); +var spawn = require('child_process').spawn; var temporaryDirectory = exports.temporaryDirectory = path.join(__dirname, 'tmp'); @@ -153,6 +154,31 @@ function XMLStringToJSON(xml) { } exports.XMLStringToJSON = XMLStringToJSON; +function run() { + var deferred = new Deferred(); + var options = Array.prototype.slice.call(arguments, 0) + + var commandName = options.shift(); + var commandPath = __dirname + '/../bin/' + commandName; + var command = spawn(commandPath, options); + var output = { + stdout: '', + stderr: '' + }; + command.stdout.on('data', function(data) { + output.stdout += data; + }); + command.stderr.on('data', function(data) { + output.stderr += data; + }); + command.on('exit', function(code) { + deferred.call({ code: code, output: output }); + }); + + return deferred; +} +exports.run = run; + // activate diff for chai.assert.deepEqual -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...Download