Permalink
Browse files

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 <jwalker@mozilla.com>
  • Loading branch information...
joewalker committed Feb 16, 2013
1 parent 7dc9ab1 commit 11677df8c54694130ad84192ea208bee33a1ea6d
Showing with 78 additions and 11 deletions.
  1. +9 −2 gcli.js
  2. +40 −0 lib/server/commands/exit.js
  3. +10 −1 lib/server/commands/test.js
  4. +19 −8 lib/server/index.js
View
11 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);
+ }
+ });
}
@@ -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);
+ }
+};
@@ -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;
}
};
View
@@ -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);
};

0 comments on commit 11677df

Please sign in to comment.