2018-05-14 17:33:16 +00:00
|
|
|
/* eslint no-console: 0 */
|
|
|
|
|
|
|
|
/**
|
2018-05-17 15:11:34 +00:00
|
|
|
* Test Runner
|
2018-05-14 17:33:16 +00:00
|
|
|
*
|
|
|
|
* For running the tests in the test register.
|
|
|
|
*
|
|
|
|
* @author tlwr [toby@toby.codes]
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2017
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
import "babel-polyfill";
|
|
|
|
|
|
|
|
// Define global environment functions
|
|
|
|
global.ENVIRONMENT_IS_WORKER = function() {
|
|
|
|
return typeof importScripts === "function";
|
|
|
|
};
|
|
|
|
global.ENVIRONMENT_IS_NODE = function() {
|
|
|
|
return typeof process === "object" && typeof require === "function";
|
|
|
|
};
|
|
|
|
global.ENVIRONMENT_IS_WEB = function() {
|
|
|
|
return typeof window === "object";
|
|
|
|
};
|
|
|
|
|
|
|
|
import TestRegister from "./TestRegister";
|
2018-05-17 15:34:00 +00:00
|
|
|
import "./tests/operations/Base58";
|
2018-05-14 17:33:16 +00:00
|
|
|
import "./tests/operations/Base64";
|
2018-05-17 15:34:00 +00:00
|
|
|
import "./tests/operations/BCD";
|
2018-05-23 17:59:57 +00:00
|
|
|
import "./tests/operations/BitwiseOp";
|
2018-05-21 17:37:32 +00:00
|
|
|
import "./tests/operations/BSON";
|
2018-05-17 15:34:00 +00:00
|
|
|
import "./tests/operations/ByteRepr";
|
2018-05-14 17:33:16 +00:00
|
|
|
import "./tests/operations/CartesianProduct";
|
2018-05-17 15:34:00 +00:00
|
|
|
import "./tests/operations/CharEnc";
|
2018-05-14 17:33:16 +00:00
|
|
|
import "./tests/operations/Ciphers";
|
2018-05-17 15:11:34 +00:00
|
|
|
import "./tests/operations/Checksum";
|
2018-05-27 21:07:09 +00:00
|
|
|
import "./tests/operations/Code";
|
2018-05-21 18:23:05 +00:00
|
|
|
import "./tests/operations/Compress";
|
2018-05-23 17:31:26 +00:00
|
|
|
import "./tests/operations/Crypt";
|
2018-05-21 17:37:32 +00:00
|
|
|
import "./tests/operations/DateTime";
|
2018-05-21 09:58:35 +00:00
|
|
|
import "./tests/operations/Fork";
|
|
|
|
import "./tests/operations/Jump";
|
|
|
|
import "./tests/operations/ConditionalJump";
|
|
|
|
import "./tests/operations/Register";
|
|
|
|
import "./tests/operations/Comment";
|
2018-05-17 15:11:34 +00:00
|
|
|
import "./tests/operations/Hash";
|
2018-05-17 15:34:00 +00:00
|
|
|
import "./tests/operations/Hexdump";
|
2018-05-27 22:27:11 +00:00
|
|
|
import "./tests/operations/Image";
|
2018-05-17 15:34:00 +00:00
|
|
|
import "./tests/operations/MorseCode";
|
|
|
|
import "./tests/operations/MS";
|
2018-05-21 12:35:11 +00:00
|
|
|
import "./tests/operations/PHP";
|
2018-05-17 15:34:00 +00:00
|
|
|
import "./tests/operations/NetBIOS";
|
2018-05-21 12:35:11 +00:00
|
|
|
import "./tests/operations/OTP";
|
2018-05-14 17:33:16 +00:00
|
|
|
import "./tests/operations/PowerSet";
|
2018-05-17 15:34:00 +00:00
|
|
|
// import "./tests/operations/Regex";
|
2018-05-14 17:33:16 +00:00
|
|
|
import "./tests/operations/Rotate";
|
2018-05-27 21:07:09 +00:00
|
|
|
import "./tests/operations/StrUtils";
|
2018-05-17 15:34:00 +00:00
|
|
|
import "./tests/operations/SeqUtils";
|
2018-05-14 17:33:16 +00:00
|
|
|
import "./tests/operations/SetDifference";
|
|
|
|
import "./tests/operations/SetIntersection";
|
|
|
|
import "./tests/operations/SetUnion";
|
|
|
|
import "./tests/operations/SymmetricDifference";
|
|
|
|
|
|
|
|
let allTestsPassing = true;
|
|
|
|
const testStatusCounts = {
|
|
|
|
total: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to convert a status to an icon.
|
|
|
|
*
|
|
|
|
* @param {string} status
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
function statusToIcon(status) {
|
|
|
|
const icons = {
|
|
|
|
erroring: "🔥",
|
|
|
|
failing: "❌",
|
|
|
|
passing: "✔️️",
|
|
|
|
};
|
|
|
|
return icons[status] || "?";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a given test result in the console.
|
|
|
|
*
|
|
|
|
* @param {Object} testResult
|
|
|
|
*/
|
|
|
|
function handleTestResult(testResult) {
|
|
|
|
allTestsPassing = allTestsPassing && testResult.status === "passing";
|
|
|
|
const newCount = (testStatusCounts[testResult.status] || 0) + 1;
|
|
|
|
testStatusCounts[testResult.status] = newCount;
|
|
|
|
testStatusCounts.total += 1;
|
|
|
|
|
|
|
|
console.log([
|
|
|
|
statusToIcon(testResult.status),
|
|
|
|
testResult.test.name
|
|
|
|
].join(" "));
|
|
|
|
|
|
|
|
if (testResult.output) {
|
|
|
|
console.log(
|
|
|
|
testResult.output
|
|
|
|
.trim()
|
|
|
|
.replace(/^/, "\t")
|
|
|
|
.replace(/\n/g, "\n\t")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fail if the process takes longer than 10 seconds.
|
|
|
|
*/
|
|
|
|
setTimeout(function() {
|
|
|
|
console.log("Tests took longer than 10 seconds to run, returning.");
|
|
|
|
process.exit(1);
|
|
|
|
}, 10 * 1000);
|
|
|
|
|
|
|
|
|
|
|
|
TestRegister.runTests()
|
|
|
|
.then(function(results) {
|
|
|
|
results.forEach(handleTestResult);
|
|
|
|
|
|
|
|
console.log("\n");
|
|
|
|
|
|
|
|
for (const testStatus in testStatusCounts) {
|
|
|
|
const count = testStatusCounts[testStatus];
|
|
|
|
if (count > 0) {
|
|
|
|
console.log(testStatus.toUpperCase(), count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!allTestsPassing) {
|
|
|
|
console.log("\nNot all tests are passing");
|
|
|
|
}
|
|
|
|
|
|
|
|
process.exit(allTestsPassing ? 0 : 1);
|
|
|
|
});
|