From 11677df8c54694130ad84192ea208bee33a1ea6d Mon Sep 17 00:00:00 2001 From: Joe Walker Date: Sat, 16 Feb 2013 12:32:57 +0000 Subject: [PATCH] travis-841337: Reflect test status in return code Travis wants to know if a test passed/failed by the return code, which is reasonable. This change reflects the status of the last command in the return code from the single exec version of gcli.js Signed-off-by: Joe Walker --- gcli.js | 11 ++++++++-- lib/server/commands/exit.js | 40 +++++++++++++++++++++++++++++++++++++ lib/server/commands/test.js | 11 +++++++++- lib/server/index.js | 27 +++++++++++++++++-------- 4 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 lib/server/commands/exit.js diff --git a/gcli.js b/gcli.js index 1b27efa3..e8931b5a 100644 --- a/gcli.js +++ b/gcli.js @@ -66,12 +66,13 @@ else { exports.require('gcli/index'); // Load the commands defined in Node modules -require('./lib/server/commands/unamd').startup(); +require('./lib/server/commands/exit').startup(); require('./lib/server/commands/firefox').startup(); // require('./lib/server/commands/git').startup(); require('./lib/server/commands/make').startup(); require('./lib/server/commands/standard').startup(); require('./lib/server/commands/test').startup(); +require('./lib/server/commands/unamd').startup(); // Load the commands defined in CommonJS modules var help = exports.require('gcli/commands/help'); @@ -89,5 +90,11 @@ if (process.argv.length < 3) { } else { var command = process.argv.slice(2).join(' '); - server.updateExec(command).then(console.log, console.error); + + server.exec(command, function(message, isError) { + console.log(message); + if (isError) { + process.exit(1); + } + }); } diff --git a/lib/server/commands/exit.js b/lib/server/commands/exit.js new file mode 100644 index 00000000..e8654da4 --- /dev/null +++ b/lib/server/commands/exit.js @@ -0,0 +1,40 @@ +/* + * Copyright 2012, Mozilla Foundation and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var main = require('../../../gcli'); +var gcli = main.require('gcli/index'); + +/** + * Registration and de-registration. + */ +exports.startup = function() { + gcli.addCommand(exitCmdSpec); +}; + +exports.shutdown = function() { + gcli.removeCommand(exitCmdSpec); +}; + +/** + * 'exit' build command + */ +var exitCmdSpec = { + name: 'exit', + description: 'Quit from GCLI', + exec: function(args, context) { + process.exit(0); + } +}; diff --git a/lib/server/commands/test.js b/lib/server/commands/test.js index 90ff9781..aea0b0a0 100644 --- a/lib/server/commands/test.js +++ b/lib/server/commands/test.js @@ -22,6 +22,7 @@ var gcli = main.require('gcli/index'); var Display = main.require('gcli/ui/display').Display; main.require('gclitest/suite'); var examiner = main.require('test/examiner'); +var stati = main.require('test/status').stati; /** * Registration and de-registration. @@ -42,6 +43,7 @@ var testCmdSpec = { description: 'Run GCLI unit tests', returnType: 'terminal', exec: function(args, context) { + var deferred = context.defer(); jsdom.env({ html: fs.readFileSync(main.gcliHome + '/index.html').toString(), src: [ ], @@ -61,10 +63,17 @@ var testCmdSpec = { isUnamdized: main.useUnamd }; examiner.run(options).then(function() { - console.log(examiner.detailedResultLog()); + var reply = examiner.detailedResultLog(); + if (examiner.toRemote().summary.status === stati.pass) { + deferred.resolve(reply); + } + else { + deferred.reject(reply); + } }); } }); + return deferred.promise; } }; diff --git a/lib/server/index.js b/lib/server/index.js index 2bf1e7ff..e4a0bc74 100644 --- a/lib/server/index.js +++ b/lib/server/index.js @@ -21,6 +21,7 @@ var jsdom = require('jsdom').jsdom; var main = require('../../gcli'); var requisition = new (main.require('gcli/cli').Requisition)(); +var Status = main.require('gcli/types').Status; /** * Serve '.' to http://localhost:9999/ @@ -44,10 +45,11 @@ exports.serve = function() { }); if (command.length !== 0) { - exports.updateExec(command).then(console.log, console.error); + exports.exec(command, function(message, isError) { + console.log(message); + callback(); + }); } - - callback(); }; console.log('This is also a limited GCLI prompt. ' + @@ -56,10 +58,19 @@ exports.serve = function() { }; /** - * Execute a single command + * Utility to call requisition.update and requisition.exec properly */ -exports.updateExec = function(command) { - return requisition.updateExec(command).then(function(output) { - return output.toString(jsdom()); - }); +exports.exec = function(command, onExec) { + requisition.update(command).then(function() { + if (requisition.getStatus() !== Status.VALID) { + onExec('Invalid command "' + command + "'", true); + } + else { + var output = requisition.exec(); + function display() { + onExec(output.toString(jsdom()), output.error); + }; + output.then(display, display); + } + }).then(null, console.error); };