Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
travis-841337: Reflect test status in return code
Browse files Browse the repository at this point in the history
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 11677df
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
11 changes: 9 additions & 2 deletions gcli.js
Expand Up @@ -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');
Expand All @@ -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);
}
});
}
40 changes: 40 additions & 0 deletions 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);
}
};
11 changes: 10 additions & 1 deletion lib/server/commands/test.js
Expand Up @@ -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.
Expand All @@ -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: [ ],
Expand All @@ -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;
}
};

Expand Down
27 changes: 19 additions & 8 deletions lib/server/index.js
Expand Up @@ -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/
Expand All @@ -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. ' +
Expand All @@ -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.