2017-12-12 22:53:24 +00:00
|
|
|
const fs = require('fs');
|
2020-03-13 23:24:12 +00:00
|
|
|
const path = require('path');
|
2018-01-07 15:20:25 +00:00
|
|
|
|
2020-04-04 16:35:20 +00:00
|
|
|
function loadContent(content) {
|
|
|
|
var Module = module.constructor;
|
|
|
|
var m = new Module();
|
|
|
|
m._compile(content, "tmp.js");
|
|
|
|
m.exports.ignore_order = content.indexOf("\n// ignore-order\n") !== -1 ||
|
|
|
|
content.startsWith("// ignore-order\n");
|
|
|
|
m.exports.exact_check = content.indexOf("\n// exact-check\n") !== -1 ||
|
|
|
|
content.startsWith("// exact-check\n");
|
|
|
|
m.exports.should_fail = content.indexOf("\n// should-fail\n") !== -1 ||
|
|
|
|
content.startsWith("// should-fail\n");
|
|
|
|
return m.exports;
|
|
|
|
}
|
|
|
|
|
|
|
|
function readFile(filePath) {
|
|
|
|
return fs.readFileSync(filePath, 'utf8');
|
|
|
|
}
|
|
|
|
|
2020-11-26 13:02:01 +00:00
|
|
|
function contentToDiffLine(key, value) {
|
|
|
|
return `"${key}": "${value}",`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function is only called when no matching result was found and therefore will only display
|
|
|
|
// the diff between the two items.
|
|
|
|
function betterLookingDiff(entry, data) {
|
|
|
|
let output = ' {\n';
|
|
|
|
let spaces = ' ';
|
|
|
|
for (let key in entry) {
|
|
|
|
if (!entry.hasOwnProperty(key)) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-02-01 10:27:17 +00:00
|
|
|
if (!data || !data.hasOwnProperty(key)) {
|
|
|
|
output += '-' + spaces + contentToDiffLine(key, entry[key]) + '\n';
|
|
|
|
continue;
|
|
|
|
}
|
2020-11-26 13:02:01 +00:00
|
|
|
let value = data[key];
|
|
|
|
if (value !== entry[key]) {
|
|
|
|
output += '-' + spaces + contentToDiffLine(key, entry[key]) + '\n';
|
|
|
|
output += '+' + spaces + contentToDiffLine(key, value) + '\n';
|
|
|
|
} else {
|
|
|
|
output += spaces + contentToDiffLine(key, value) + '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return output + ' }';
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:35:20 +00:00
|
|
|
function lookForEntry(entry, data) {
|
|
|
|
for (var i = 0; i < data.length; ++i) {
|
|
|
|
var allGood = true;
|
|
|
|
for (var key in entry) {
|
|
|
|
if (!entry.hasOwnProperty(key)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var value = data[i][key];
|
|
|
|
// To make our life easier, if there is a "parent" type, we add it to the path.
|
|
|
|
if (key === 'path' && data[i]['parent'] !== undefined) {
|
|
|
|
if (value.length > 0) {
|
|
|
|
value += '::' + data[i]['parent']['name'];
|
|
|
|
} else {
|
|
|
|
value = data[i]['parent']['name'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (value !== entry[key]) {
|
|
|
|
allGood = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allGood === true) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-01-04 14:44:00 +00:00
|
|
|
// This function checks if `expected` has all the required fields needed for the checks.
|
|
|
|
function checkNeededFields(fullPath, expected, error_text, queryName, position) {
|
2021-12-20 15:56:39 +00:00
|
|
|
let fieldsToCheck;
|
|
|
|
if (fullPath.length === 0) {
|
|
|
|
fieldsToCheck = [
|
|
|
|
"foundElems",
|
|
|
|
"original",
|
|
|
|
"returned",
|
|
|
|
"typeFilter",
|
2022-01-03 15:43:30 +00:00
|
|
|
"userQuery",
|
2021-12-20 15:56:39 +00:00
|
|
|
"error",
|
|
|
|
];
|
|
|
|
} else if (fullPath.endsWith("elems") || fullPath.endsWith("generics")) {
|
|
|
|
fieldsToCheck = [
|
|
|
|
"name",
|
|
|
|
"fullPath",
|
|
|
|
"pathWithoutLast",
|
|
|
|
"pathLast",
|
|
|
|
"generics",
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
fieldsToCheck = [];
|
|
|
|
}
|
|
|
|
for (var i = 0; i < fieldsToCheck.length; ++i) {
|
|
|
|
const field = fieldsToCheck[i];
|
|
|
|
if (!expected.hasOwnProperty(field)) {
|
|
|
|
let text = `${queryName}==> Mandatory key \`${field}\` is not present`;
|
|
|
|
if (fullPath.length > 0) {
|
|
|
|
text += ` in field \`${fullPath}\``;
|
|
|
|
if (position != null) {
|
|
|
|
text += ` (position ${position})`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error_text.push(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function valueCheck(fullPath, expected, result, error_text, queryName) {
|
|
|
|
if (Array.isArray(expected)) {
|
|
|
|
for (var i = 0; i < expected.length; ++i) {
|
2022-01-04 14:44:00 +00:00
|
|
|
checkNeededFields(fullPath, expected[i], error_text, queryName, i);
|
2021-12-20 15:56:39 +00:00
|
|
|
if (i >= result.length) {
|
|
|
|
error_text.push(`${queryName}==> EXPECTED has extra value in array from field ` +
|
|
|
|
`\`${fullPath}\` (position ${i}): \`${JSON.stringify(expected[i])}\``);
|
|
|
|
} else {
|
|
|
|
valueCheck(fullPath + '[' + i + ']', expected[i], result[i], error_text, queryName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (; i < result.length; ++i) {
|
|
|
|
error_text.push(`${queryName}==> RESULT has extra value in array from field ` +
|
|
|
|
`\`${fullPath}\` (position ${i}): \`${JSON.stringify(result[i])}\` ` +
|
|
|
|
'compared to EXPECTED');
|
|
|
|
}
|
|
|
|
} else if (expected !== null && typeof expected !== "undefined" &&
|
2022-05-16 04:09:55 +00:00
|
|
|
expected.constructor == Object) {
|
2021-12-20 15:56:39 +00:00
|
|
|
for (const key in expected) {
|
|
|
|
if (!expected.hasOwnProperty(key)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!result.hasOwnProperty(key)) {
|
|
|
|
error_text.push('==> Unknown key "' + key + '"');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const obj_path = fullPath + (fullPath.length > 0 ? '.' : '') + key;
|
|
|
|
valueCheck(obj_path, expected[key], result[key], error_text, queryName);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
expectedValue = JSON.stringify(expected);
|
|
|
|
resultValue = JSON.stringify(result);
|
|
|
|
if (expectedValue != resultValue) {
|
|
|
|
error_text.push(`${queryName}==> Different values for field \`${fullPath}\`:\n` +
|
|
|
|
`EXPECTED: \`${expectedValue}\`\nRESULT: \`${resultValue}\``);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-16 04:09:55 +00:00
|
|
|
function runParser(query, expected, parseQuery, queryName) {
|
2021-12-20 15:56:39 +00:00
|
|
|
var error_text = [];
|
2022-01-04 14:44:00 +00:00
|
|
|
checkNeededFields("", expected, error_text, queryName, null);
|
2021-12-20 15:56:39 +00:00
|
|
|
if (error_text.length === 0) {
|
2022-05-16 04:09:55 +00:00
|
|
|
valueCheck('', expected, parseQuery(query), error_text, queryName);
|
2021-12-20 15:56:39 +00:00
|
|
|
}
|
|
|
|
return error_text;
|
|
|
|
}
|
|
|
|
|
2022-05-16 04:09:55 +00:00
|
|
|
function runSearch(query, expected, doSearch, loadedFile, queryName) {
|
2020-04-04 16:35:20 +00:00
|
|
|
const ignore_order = loadedFile.ignore_order;
|
|
|
|
const exact_check = loadedFile.exact_check;
|
2018-01-07 15:20:25 +00:00
|
|
|
|
2022-05-16 04:09:55 +00:00
|
|
|
var results = doSearch(query, loadedFile.FILTER_CRATE);
|
2020-04-04 16:35:20 +00:00
|
|
|
var error_text = [];
|
2019-02-23 23:08:43 +00:00
|
|
|
|
2020-04-04 16:35:20 +00:00
|
|
|
for (var key in expected) {
|
|
|
|
if (!expected.hasOwnProperty(key)) {
|
2019-02-24 00:04:07 +00:00
|
|
|
continue;
|
2019-02-23 23:08:43 +00:00
|
|
|
}
|
2020-04-04 16:35:20 +00:00
|
|
|
if (!results.hasOwnProperty(key)) {
|
|
|
|
error_text.push('==> Unknown key "' + key + '"');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
var entry = expected[key];
|
2020-06-23 08:18:51 +00:00
|
|
|
|
|
|
|
if (exact_check == true && entry.length !== results[key].length) {
|
|
|
|
error_text.push(queryName + "==> Expected exactly " + entry.length +
|
|
|
|
" results but found " + results[key].length + " in '" + key + "'");
|
|
|
|
}
|
|
|
|
|
2020-04-04 16:35:20 +00:00
|
|
|
var prev_pos = -1;
|
|
|
|
for (var i = 0; i < entry.length; ++i) {
|
|
|
|
var entry_pos = lookForEntry(entry[i], results[key]);
|
|
|
|
if (entry_pos === null) {
|
2020-04-30 13:37:00 +00:00
|
|
|
error_text.push(queryName + "==> Result not found in '" + key + "': '" +
|
2020-04-04 16:35:20 +00:00
|
|
|
JSON.stringify(entry[i]) + "'");
|
2020-11-26 13:02:01 +00:00
|
|
|
// By default, we just compare the two first items.
|
|
|
|
let item_to_diff = 0;
|
|
|
|
if ((ignore_order === false || exact_check === true) && i < results[key].length) {
|
|
|
|
item_to_diff = i;
|
|
|
|
}
|
|
|
|
error_text.push("Diff of first error:\n" +
|
|
|
|
betterLookingDiff(entry[i], results[key][item_to_diff]));
|
2020-04-04 16:35:20 +00:00
|
|
|
} else if (exact_check === true && prev_pos + 1 !== entry_pos) {
|
2020-04-30 13:37:00 +00:00
|
|
|
error_text.push(queryName + "==> Exact check failed at position " + (prev_pos + 1) +
|
|
|
|
": expected '" + JSON.stringify(entry[i]) + "' but found '" +
|
2020-04-04 16:35:20 +00:00
|
|
|
JSON.stringify(results[key][i]) + "'");
|
|
|
|
} else if (ignore_order === false && entry_pos < prev_pos) {
|
2020-04-30 13:37:00 +00:00
|
|
|
error_text.push(queryName + "==> '" + JSON.stringify(entry[i]) + "' was supposed " +
|
|
|
|
"to be before '" + JSON.stringify(results[key][entry_pos]) + "'");
|
2020-04-04 16:35:20 +00:00
|
|
|
} else {
|
|
|
|
prev_pos = entry_pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-30 13:37:00 +00:00
|
|
|
return error_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkResult(error_text, loadedFile, displaySuccess) {
|
|
|
|
if (error_text.length === 0 && loadedFile.should_fail === true) {
|
|
|
|
console.log("FAILED");
|
|
|
|
console.log("==> Test was supposed to fail but all items were found...");
|
|
|
|
} else if (error_text.length !== 0 && loadedFile.should_fail === false) {
|
|
|
|
console.log("FAILED");
|
|
|
|
console.log(error_text.join("\n"));
|
2020-04-04 16:35:20 +00:00
|
|
|
} else {
|
2020-04-30 13:37:00 +00:00
|
|
|
if (displaySuccess) {
|
|
|
|
console.log("OK");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-12-20 15:56:39 +00:00
|
|
|
function runCheck(loadedFile, key, callback) {
|
|
|
|
const expected = loadedFile[key];
|
2020-04-30 13:37:00 +00:00
|
|
|
const query = loadedFile.QUERY;
|
|
|
|
|
|
|
|
if (Array.isArray(query)) {
|
|
|
|
if (!Array.isArray(expected)) {
|
|
|
|
console.log("FAILED");
|
2021-12-20 15:56:39 +00:00
|
|
|
console.log(`==> If QUERY variable is an array, ${key} should be an array too`);
|
2020-04-30 13:37:00 +00:00
|
|
|
return 1;
|
|
|
|
} else if (query.length !== expected.length) {
|
|
|
|
console.log("FAILED");
|
2021-12-20 15:56:39 +00:00
|
|
|
console.log(`==> QUERY variable should have the same length as ${key}`);
|
2020-04-30 13:37:00 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < query.length; ++i) {
|
2021-12-20 15:56:39 +00:00
|
|
|
var error_text = callback(query[i], expected[i], "[ query `" + query[i] + "`]");
|
2020-04-30 13:37:00 +00:00
|
|
|
if (checkResult(error_text, loadedFile, false) !== 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2020-04-04 16:35:20 +00:00
|
|
|
console.log("OK");
|
2021-12-20 15:56:39 +00:00
|
|
|
} else {
|
|
|
|
var error_text = callback(query, expected, "");
|
|
|
|
if (checkResult(error_text, loadedFile, true) !== 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-05-16 04:09:55 +00:00
|
|
|
function runChecks(testFile, doSearch, parseQuery) {
|
2021-12-20 15:56:39 +00:00
|
|
|
var checkExpected = false;
|
|
|
|
var checkParsed = false;
|
|
|
|
var testFileContent = readFile(testFile) + 'exports.QUERY = QUERY;';
|
|
|
|
|
|
|
|
if (testFileContent.indexOf("FILTER_CRATE") !== -1) {
|
|
|
|
testFileContent += "exports.FILTER_CRATE = FILTER_CRATE;";
|
|
|
|
} else {
|
|
|
|
testFileContent += "exports.FILTER_CRATE = null;";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (testFileContent.indexOf("\nconst EXPECTED") !== -1) {
|
|
|
|
testFileContent += 'exports.EXPECTED = EXPECTED;';
|
|
|
|
checkExpected = true;
|
|
|
|
}
|
|
|
|
if (testFileContent.indexOf("\nconst PARSED") !== -1) {
|
|
|
|
testFileContent += 'exports.PARSED = PARSED;';
|
|
|
|
checkParsed = true;
|
|
|
|
}
|
|
|
|
if (!checkParsed && !checkExpected) {
|
|
|
|
console.log("FAILED");
|
|
|
|
console.log("==> At least `PARSED` or `EXPECTED` is needed!");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const loadedFile = loadContent(testFileContent);
|
|
|
|
var res = 0;
|
|
|
|
|
|
|
|
if (checkExpected) {
|
|
|
|
res += runCheck(loadedFile, "EXPECTED", (query, expected, text) => {
|
2022-05-16 04:09:55 +00:00
|
|
|
return runSearch(query, expected, doSearch, loadedFile, text);
|
2021-12-20 15:56:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (checkParsed) {
|
|
|
|
res += runCheck(loadedFile, "PARSED", (query, expected, text) => {
|
2022-05-16 04:09:55 +00:00
|
|
|
return runParser(query, expected, parseQuery, text);
|
2021-12-20 15:56:39 +00:00
|
|
|
});
|
2020-04-04 16:35:20 +00:00
|
|
|
}
|
2021-12-20 15:56:39 +00:00
|
|
|
return res;
|
2020-04-04 16:35:20 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 04:09:55 +00:00
|
|
|
/**
|
|
|
|
* Load searchNNN.js and search-indexNNN.js.
|
|
|
|
*
|
|
|
|
* @param {string} doc_folder - Path to a folder generated by running rustdoc
|
|
|
|
* @param {string} resource_suffix - Version number between filename and .js, e.g. "1.59.0"
|
|
|
|
* @returns {Object} - Object containing two keys: `doSearch`, which runs a search
|
|
|
|
* with the loaded index and returns a table of results; and `parseQuery`, which is the
|
|
|
|
* `parseQuery` function exported from the search module.
|
|
|
|
*/
|
|
|
|
function loadSearchJS(doc_folder, resource_suffix) {
|
|
|
|
const searchJs = path.join(doc_folder, "search" + resource_suffix + ".js");
|
|
|
|
const searchIndexJs = path.join(doc_folder, "search-index" + resource_suffix + ".js");
|
|
|
|
const searchIndex = require(searchIndexJs);
|
|
|
|
const searchModule = require(searchJs);
|
|
|
|
const searchWords = searchModule.initSearch(searchIndex.searchIndex);
|
|
|
|
|
|
|
|
return {
|
|
|
|
doSearch: function (queryStr, filterCrate, currentCrate) {
|
|
|
|
return searchModule.execQuery(searchModule.parseQuery(queryStr), searchWords,
|
|
|
|
filterCrate, currentCrate);
|
|
|
|
},
|
|
|
|
parseQuery: searchModule.parseQuery,
|
|
|
|
}
|
2020-04-04 16:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showHelp() {
|
|
|
|
console.log("rustdoc-js options:");
|
2020-04-11 15:42:47 +00:00
|
|
|
console.log(" --doc-folder [PATH] : location of the generated doc folder");
|
|
|
|
console.log(" --help : show this message then quit");
|
|
|
|
console.log(" --crate-name [STRING] : crate name to be used");
|
2021-11-05 14:58:14 +00:00
|
|
|
console.log(" --test-file [PATHs] : location of the JS test files (can be called " +
|
|
|
|
"multiple times)");
|
2020-04-11 15:42:47 +00:00
|
|
|
console.log(" --test-folder [PATH] : location of the JS tests folder");
|
|
|
|
console.log(" --resource-suffix [STRING] : suffix to refer to the correct files");
|
2020-04-04 16:35:20 +00:00
|
|
|
}
|
2019-02-23 23:08:43 +00:00
|
|
|
|
2020-04-04 16:35:20 +00:00
|
|
|
function parseOptions(args) {
|
|
|
|
var opts = {
|
2020-04-11 15:42:47 +00:00
|
|
|
"crate_name": "",
|
|
|
|
"resource_suffix": "",
|
2020-04-04 16:35:20 +00:00
|
|
|
"doc_folder": "",
|
|
|
|
"test_folder": "",
|
2021-11-05 14:58:14 +00:00
|
|
|
"test_file": [],
|
2020-04-04 16:35:20 +00:00
|
|
|
};
|
2021-11-03 14:44:04 +00:00
|
|
|
var correspondences = {
|
2020-04-11 15:42:47 +00:00
|
|
|
"--resource-suffix": "resource_suffix",
|
2020-04-04 16:35:20 +00:00
|
|
|
"--doc-folder": "doc_folder",
|
|
|
|
"--test-folder": "test_folder",
|
|
|
|
"--test-file": "test_file",
|
2020-04-11 15:42:47 +00:00
|
|
|
"--crate-name": "crate_name",
|
2020-04-04 16:35:20 +00:00
|
|
|
};
|
2019-02-24 00:04:07 +00:00
|
|
|
|
2020-04-04 16:35:20 +00:00
|
|
|
for (var i = 0; i < args.length; ++i) {
|
2021-11-03 14:44:04 +00:00
|
|
|
if (correspondences.hasOwnProperty(args[i])) {
|
2020-04-04 16:35:20 +00:00
|
|
|
i += 1;
|
|
|
|
if (i >= args.length) {
|
2020-04-30 13:37:00 +00:00
|
|
|
console.log("Missing argument after `" + args[i - 1] + "` option.");
|
2020-04-04 16:35:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
2021-11-05 14:58:14 +00:00
|
|
|
if (args[i - 1] !== "--test-file") {
|
|
|
|
opts[correspondences[args[i - 1]]] = args[i];
|
|
|
|
} else {
|
|
|
|
opts[correspondences[args[i - 1]]].push(args[i]);
|
|
|
|
}
|
2020-04-04 16:35:20 +00:00
|
|
|
} else if (args[i] === "--help") {
|
|
|
|
showHelp();
|
|
|
|
process.exit(0);
|
|
|
|
} else {
|
2020-04-30 13:37:00 +00:00
|
|
|
console.log("Unknown option `" + args[i] + "`.");
|
|
|
|
console.log("Use `--help` to see the list of options");
|
2020-04-04 16:35:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (opts["doc_folder"].length < 1) {
|
2020-04-30 13:37:00 +00:00
|
|
|
console.log("Missing `--doc-folder` option.");
|
2020-04-11 15:42:47 +00:00
|
|
|
} else if (opts["crate_name"].length < 1) {
|
2020-04-30 13:37:00 +00:00
|
|
|
console.log("Missing `--crate-name` option.");
|
2020-04-04 16:35:20 +00:00
|
|
|
} else if (opts["test_folder"].length < 1 && opts["test_file"].length < 1) {
|
2020-04-30 13:37:00 +00:00
|
|
|
console.log("At least one of `--test-folder` or `--test-file` option is required.");
|
2020-04-11 15:42:47 +00:00
|
|
|
} else {
|
|
|
|
return opts;
|
2020-04-04 16:35:20 +00:00
|
|
|
}
|
2020-04-11 15:42:47 +00:00
|
|
|
return null;
|
2020-04-04 16:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function main(argv) {
|
|
|
|
var opts = parseOptions(argv.slice(2));
|
|
|
|
if (opts === null) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-05-16 04:09:55 +00:00
|
|
|
let parseAndSearch = loadSearchJS(
|
2020-04-11 15:42:47 +00:00
|
|
|
opts["doc_folder"],
|
2022-05-16 04:09:55 +00:00
|
|
|
opts["resource_suffix"]);
|
2020-04-04 16:35:20 +00:00
|
|
|
var errors = 0;
|
|
|
|
|
2022-05-16 04:09:55 +00:00
|
|
|
let doSearch = function (queryStr, filterCrate) {
|
|
|
|
return parseAndSearch.doSearch(queryStr, filterCrate, opts["crate_name"]);
|
|
|
|
};
|
|
|
|
|
2020-04-04 16:35:20 +00:00
|
|
|
if (opts["test_file"].length !== 0) {
|
2022-05-16 04:09:55 +00:00
|
|
|
opts["test_file"].forEach(function (file) {
|
|
|
|
process.stdout.write(`Testing ${file} ... `);
|
|
|
|
errors += runChecks(file, doSearch, parseAndSearch.parseQuery);
|
2021-11-05 14:58:14 +00:00
|
|
|
});
|
|
|
|
} else if (opts["test_folder"].length !== 0) {
|
2022-05-16 04:09:55 +00:00
|
|
|
fs.readdirSync(opts["test_folder"]).forEach(function (file) {
|
2020-04-04 16:35:20 +00:00
|
|
|
if (!file.endsWith(".js")) {
|
|
|
|
return;
|
|
|
|
}
|
2022-05-16 04:09:55 +00:00
|
|
|
process.stdout.write(`Testing ${file} ... `);
|
|
|
|
errors += runChecks(path.join(opts["test_folder"], file), doSearch,
|
|
|
|
parseAndSearch.parseQuery);
|
2020-04-04 16:35:20 +00:00
|
|
|
});
|
2019-02-24 00:04:07 +00:00
|
|
|
}
|
2020-03-16 20:50:04 +00:00
|
|
|
return errors > 0 ? 1 : 0;
|
2017-12-12 22:53:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-07 15:20:25 +00:00
|
|
|
process.exit(main(process.argv));
|