2017-04-22 20:18:36 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2017-04-22 21:27:00 +00:00
|
|
|
var websocket = null;
|
|
|
|
|
2017-04-22 21:14:04 +00:00
|
|
|
var logger = (function () {
|
2017-04-22 19:17:23 +00:00
|
|
|
let color = {
|
2017-04-22 20:07:29 +00:00
|
|
|
red: "\033[1;31m",
|
|
|
|
green: "\033[1;32m",
|
|
|
|
clear: "\033[0m"
|
2017-04-22 19:17:23 +00:00
|
|
|
};
|
|
|
|
if (platform.isWindows) {
|
|
|
|
color = {
|
2017-04-22 20:07:29 +00:00
|
|
|
red: "",
|
|
|
|
green: "",
|
|
|
|
clear: ""
|
2017-04-22 19:17:23 +00:00
|
|
|
};
|
2017-04-07 14:16:59 +00:00
|
|
|
}
|
2017-04-22 19:17:23 +00:00
|
|
|
|
|
|
|
let sep = "\n/* ### NEXT TESTCASE ############################## */";
|
2017-04-07 14:16:59 +00:00
|
|
|
|
|
|
|
function console(msg) {
|
|
|
|
if (websocket) {
|
|
|
|
websocket.send(msg);
|
|
|
|
}
|
|
|
|
if (typeof window == 'undefined') {
|
|
|
|
print(msg);
|
|
|
|
} else if (window.dump) {
|
|
|
|
window.dump(msg);
|
|
|
|
} else if (window.console && window.console.log) {
|
|
|
|
window.console.log(msg);
|
|
|
|
} else {
|
|
|
|
throw "Unable to run console logger.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 19:17:23 +00:00
|
|
|
function dump(msg) {
|
2017-04-22 20:07:29 +00:00
|
|
|
console(msg);
|
2017-04-22 19:17:23 +00:00
|
|
|
}
|
2017-04-07 14:16:59 +00:00
|
|
|
|
2017-04-22 19:17:23 +00:00
|
|
|
function testcase(msg) {
|
2017-04-22 20:07:29 +00:00
|
|
|
dump("/*L*/ " + JSON.stringify(msg) + "\n");
|
2017-04-22 19:17:23 +00:00
|
|
|
}
|
2017-04-07 14:16:59 +00:00
|
|
|
|
2017-04-22 19:17:23 +00:00
|
|
|
function dumpln(msg) {
|
2017-04-22 20:07:29 +00:00
|
|
|
dump(msg + "\n");
|
2017-04-22 19:17:23 +00:00
|
|
|
}
|
2017-04-07 14:16:59 +00:00
|
|
|
|
2017-04-22 19:17:23 +00:00
|
|
|
function error(msg) {
|
2017-04-22 20:07:29 +00:00
|
|
|
dumpln(color.red + msg + color.clear);
|
2017-04-22 19:17:23 +00:00
|
|
|
}
|
2017-04-07 14:16:59 +00:00
|
|
|
|
2017-04-22 19:17:23 +00:00
|
|
|
function JSError(msg) {
|
2017-04-22 20:07:29 +00:00
|
|
|
error(comment(msg))
|
2017-04-22 19:17:23 +00:00
|
|
|
}
|
2017-04-07 14:16:59 +00:00
|
|
|
|
2017-04-22 19:17:23 +00:00
|
|
|
function comment(msg) {
|
2017-04-22 20:07:29 +00:00
|
|
|
return "/* " + msg + " */";
|
2017-04-22 19:17:23 +00:00
|
|
|
}
|
2017-04-07 14:16:59 +00:00
|
|
|
|
2017-04-22 19:17:23 +00:00
|
|
|
function separator() {
|
2017-04-22 20:07:29 +00:00
|
|
|
dumpln(color.green + sep + color.clear);
|
2017-04-22 19:17:23 +00:00
|
|
|
}
|
2017-04-07 14:16:59 +00:00
|
|
|
|
2017-04-22 21:14:04 +00:00
|
|
|
function traceback() {
|
|
|
|
error("===[ Traceback ]");
|
|
|
|
try {
|
|
|
|
throw new Error();
|
|
|
|
} catch (e) {
|
|
|
|
dump(e.stack || e.stacktrace || "");
|
|
|
|
}
|
|
|
|
error("===");
|
|
|
|
}
|
|
|
|
|
2017-04-07 14:16:59 +00:00
|
|
|
return {
|
|
|
|
console: console,
|
|
|
|
dump: dump,
|
|
|
|
error: error,
|
|
|
|
JSError: JSError,
|
|
|
|
dumpln: dumpln,
|
|
|
|
comment: comment,
|
|
|
|
testcase: testcase,
|
2017-04-22 21:14:04 +00:00
|
|
|
separator: separator,
|
|
|
|
traceback: traceback
|
2017-04-07 14:16:59 +00:00
|
|
|
};
|
|
|
|
})();
|