Skip to content
Browse files

Allow switching between parseable and normal test output.

  • Loading branch information...
1 parent e6c9a87 commit 15d2dbb34e3e4b07c08e67126b0b3a8dab24a981 @Mossop committed Dec 20, 2012
View
1 app-extension/bootstrap.js
@@ -173,6 +173,7 @@ function startup(data, reasonCode) {
profileMemory: options.profileMemory,
stopOnError: options.stopOnError,
verbose: options.verbose,
+ parseable: options.parseable,
}
}
});
View
37 lib/sdk/deprecated/unit-test.js
@@ -11,6 +11,7 @@ module.metadata = {
const memory = require('./memory');
var timer = require("../timers");
+var cfxArgs = require("@test/options");
exports.findAndRunTests = function findAndRunTests(options) {
var TestFinder = require("./unit-test-finder").TestFinder;
@@ -54,15 +55,23 @@ TestRunner.prototype = {
pass: function pass(message) {
if(!this.expectFailure) {
- this.console.info("TEST-PASS", "|", this.test.name, "|", message);
+ if ("testMessage" in this.console)
+ this.console.testMessage(true, true, this.test.name, message);
+ else
+ this.console.info("pass:", message);
this.passed++;
this.test.passed++;
}
else {
this.expectFailure = false;
this._logTestFailed("failure");
- this.console.error("TEST-UNEXPECTED-PASS", "|", this.test.name, "|", message);
- this.console.trace();
+ if ("testMessage" in this.console) {
+ this.console.testMessage(true, false, this.test.name, message);
+ }
+ else {
+ this.console.error("fail:", 'Failure Expected: ' + message)
+ this.console.trace();
+ }
this.failed++;
this.test.failed++;
}
@@ -71,14 +80,22 @@ TestRunner.prototype = {
fail: function fail(message) {
if(!this.expectFailure) {
this._logTestFailed("failure");
- this.console.error("TEST-UNEXPECTED-FAIL", "|", this.test.name, "|", message);
- this.console.trace();
+ if ("testMessage" in this.console) {
+ this.console.testMessage(false, false, this.test.name, message);
+ }
+ else {
+ this.console.error("fail:", message)
+ this.console.trace();
+ }
this.failed++;
this.test.failed++;
}
else {
this.expectFailure = false;
- this.console.info("TEST-KNOWN-FAIL", "|", this.test.name, "|", message);
+ if ("testMessage" in this.console)
+ this.console.testMessage(false, true, this.test.name, message);
+ else
+ this.console.info("pass:", message);
this.passed++;
this.test.passed++;
}
@@ -434,13 +451,17 @@ TestRunner.prototype = {
this.isDone = false;
this.onDone = function(self) {
- self.console.info("TEST-END", "|", self.test.name);
+ if (cfxArgs.parseable)
+ self.console.print("TEST-END | " + self.test.name + "\n");
options.onDone(self);
}
this.waitTimeout = null;
try {
- this.console.info("TEST-START", "|", this.test.name);
+ if (cfxArgs.parseable)
+ this.console.print("TEST-START | " + this.test.name + "\n");
+ else
+ this.console.info("executing '" + this.test.name + "'");
if(this.test.setup) {
this.test.setup(this);
View
90 lib/sdk/test/harness.js
@@ -25,6 +25,9 @@ const url = require("../url");
var cService = Cc['@mozilla.org/consoleservice;1'].getService()
.QueryInterface(Ci.nsIConsoleService);
+// The console used to log messages
+var testConsole;
+
// Cuddlefish loader in which we load and execute tests.
var loader;
@@ -272,10 +275,32 @@ var consoleListener = {
var pointless = [err for each (err in POINTLESS_ERRORS)
if (message.indexOf(err) == 0)];
if (pointless.length == 0 && message)
- print("\nTEST-INFO | " + message + "\n");
+ testConsole.log(message);
}
};
+function TestRunnerConsole(base, options) {
+ this.__proto__ = {
+ errorsLogged: 0,
+ warn: function warn() {
+ this.errorsLogged++;
+ base.warn.apply(base, arguments);
+ },
+ error: function error() {
+ this.errorsLogged++;
+ base.error.apply(base, arguments);
+ },
+ info: function info(first) {
+ if (options.verbose)
+ base.info.apply(base, arguments);
+ else
+ if (first == "pass:")
+ print(".");
+ },
+ __proto__: base
+ };
+}
+
function stringify(arg) {
try {
return String(arg);
@@ -289,13 +314,7 @@ function stringifyArgs(args) {
return Array.map(args, stringify).join(" ");
}
-function message(print, level, args) {
- if (args[0].substring(0, 5) !== "TEST-")
- print(level + " | ");
- print(stringifyArgs(args) + "\n");
-}
-
-function TestRunnerConsole(options) {
+function TestRunnerTinderboxConsole(options) {
this.print = options.print;
this.verbose = options.verbose;
this.errorsLogged = 0;
@@ -311,41 +330,46 @@ function TestRunnerConsole(options) {
this.trace = this.trace.bind(this);
};
-TestRunnerConsole.prototype = {
+TestRunnerTinderboxConsole.prototype = {
+ testMessage: function testMessage(pass, expected, test, message) {
+ let type = "TEST-";
+ if (expected) {
+ if (pass)
+ type += "PASS";
+ else
+ type += "KNOWN-FAIL";
+ }
+ else {
+ this.errorsLogged++;
+ if (pass)
+ type += "UNEXPECTED-PASS";
+ else
+ type += "UNEXPECTED-FAIL";
+ }
+
+ this.print(type + " | " + test + " | " + message + "\n");
+ },
+
log: function log() {
- if (!this.verbose)
- this.print("\n");
- message(this.print, "TEST-INFO", arguments);
+ this.print("TEST-INFO | " + stringifyArgs(arguments) + "\n");
},
info: function info(first) {
- if (!this.verbose) {
- if (first === "TEST-PASS" || first === "TEST-KNOWN-FAIL")
- this.print(".");
- return;
- }
-
- message(this.print, "TEST-INFO", arguments);
+ this.print("TEST-INFO | " + stringifyArgs(arguments) + "\n");
},
warn: function warn() {
this.errorsLogged++;
- if (!this.verbose)
- this.print("\n");
- message(this.print, "TEST-UNEXPECTED-FAIL", arguments);
+ this.print("TEST-UNEXPECTED-FAIL | " + stringifyArgs(arguments) + "\n");
},
error: function error() {
this.errorsLogged++;
- if (!this.verbose)
- this.print("\n");
- message(this.print, "TEST-UNEXPECTED-FAIL", arguments);
+ this.print("TEST-UNEXPECTED-FAIL | " + stringifyArgs(arguments) + "\n");
},
debug: function debug() {
- if (!this.verbose)
- this.print("\n");
- message(this.print, "TEST-INFO", arguments);
+ this.print("TEST-INFO | " + stringifyArgs(arguments) + "\n");
},
exception: function exception(e) {
@@ -358,9 +382,7 @@ TestRunnerConsole.prototype = {
var traceback = require("../console/traceback");
var stack = traceback.get();
stack.splice(-1, 1);
- if (!this.verbose)
- this.print("\n");
- message(this.print, "TEST-INFO", [traceback.format(stack)]);
+ this.print("TEST-INFO | " + stringify(traceback.format(stack)) + "\n");
}
};
@@ -379,9 +401,13 @@ var runTests = exports.runTests = function runTests(options) {
system.id + ") under " +
system.platform + "/" + system.architecture + ".\n");
+ if (options.parseable)
+ testConsole = new TestRunnerTinderboxConsole(options);
+ else
+ testConsole = new TestRunnerConsole(new PlainTextConsole(print), options);
loader = Loader(module, {
- console: new TestRunnerConsole(options)
+ console: testConsole
});
nextIteration();
View
1 lib/sdk/test/runner.js
@@ -43,6 +43,7 @@ function runTests(findAndRunTests) {
profileMemory: cfxArgs.profileMemory,
stopOnError: cfxArgs.stopOnError,
verbose: cfxArgs.verbose,
+ parseable: cfxArgs.parseable,
print: stdout.write,
onDone: onDone
});
View
8 python-lib/cuddlefish/__init__.py
@@ -138,6 +138,12 @@
metavar=None,
default="{}",
cmds=['run', 'xpi'])),
+ (("", "--parseable",), dict(dest="parseable",
+ help="display test output in a parseable format",
+ action="store_true",
+ default=False,
+ cmds=['test', 'testex', 'testpkgs',
+ 'testall'])),
]
),
@@ -632,7 +638,7 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
if 'tests' not in target_cfg:
target_cfg['tests'] = []
inherited_options.extend(['iterations', 'filter', 'profileMemory',
- 'stopOnError'])
+ 'stopOnError', 'parseable'])
enforce_timeouts = True
elif command == "run":
use_main = True
View
28 test/test-unit-test.js
@@ -139,19 +139,33 @@ exports.testWaitUntilTimeoutInCallback = function(test) {
},
info: function (msg) {
this.calls++;
- if (this.calls == 1) {
- test.assertEqual(arguments[0], "TEST-START");
- test.assertEqual(arguments[2], "wait4ever");
+ if (require("@test/options").parseable) {
+ test.fail("We got unexpected console.info() calls: " + msg)
}
- else if (this.calls == 3) {
- test.assertEqual(arguments[0], "TEST-END");
- test.assertEqual(arguments[2], "wait4ever");
+ else if (this.calls == 1) {
+ test.assertEqual(arguments[0], "executing 'wait4ever'");
}
else {
test.fail("We got unexpected console.info() calls: " + msg);
}
},
- trace: function () {}
+ trace: function () {},
+ exception: function () {},
+ print: function (str) {
+ this.calls++;
+ if (!require("@test/options").parseable) {
+ test.fail("We got unexpected console.print() calls: " + str)
+ }
+ else if (this.calls == 1) {
+ test.assertEqual(str, "TEST-START | wait4ever\n");
+ }
+ else if (this.calls == 3) {
+ test.assertEqual(str, "TEST-END | wait4ever\n");
+ }
+ else {
+ test.fail("We got unexpected console.print() calls: " + str);
+ }
+ }
}
});

0 comments on commit 15d2dbb

Please sign in to comment.
Something went wrong with that request. Please try again.