Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bdfdc71
Implement FromStr for OsString
glandium Apr 29, 2020
cf5e4a7
Add explicit references to the BuildHasher trait
Mark-Simulacrum Apr 29, 2020
d80ac14
Extend rustdoc-js tester to allow to test multiple queries in one file
GuillaumeGomez Apr 30, 2020
7590c39
Improve doc alias JS code
GuillaumeGomez Apr 30, 2020
cf41b1d
Improve doc alias discovery
GuillaumeGomez Apr 30, 2020
3a0727e
Add more tests for doc aliases
GuillaumeGomez Apr 30, 2020
9697c46
Update std tests
GuillaumeGomez Apr 30, 2020
f581cf7
Merge aliases and search-index
GuillaumeGomez May 4, 2020
32a46e9
add test case for issue-61076
csmoe May 6, 2020
2e2aac4
add try trait as lang item
csmoe May 6, 2020
114cd00
normalize Future::Ouput
csmoe May 9, 2020
627f473
suggest await before try when performing trait selection
csmoe May 10, 2020
c7e64f5
remove try_trait lang item
csmoe May 10, 2020
23d880b
rustc_driver: factor out computing the exit code
RalfJung May 10, 2020
51e466d
rustc_driver::main: more informative return type
RalfJung May 10, 2020
a1104b4
bless ui tests
csmoe May 10, 2020
883c177
Move doc alias discovery into the Attributes struct and some code imp…
GuillaumeGomez May 4, 2020
c4d9318
Make current crate aliases go first
GuillaumeGomez May 7, 2020
e17ac66
* Update aliases data struct from HashMap to BTreeMap to have more de…
GuillaumeGomez May 13, 2020
0dc74dc
cleanup stale FIXME(#64197)
sergey-melnychuk May 14, 2020
8954379
make sure even unleashed miri does not do pointer stuff
RalfJung May 14, 2020
e84b379
[const-prop] Don't replace Rvalues that are already constants
wesleywiser Apr 23, 2020
257e377
doc: add links to rotate_(left|right)
tesuji May 15, 2020
10d7da4
implement type_implments_trait query
csmoe May 14, 2020
86f48c5
Rollup merge of #71662 - glandium:osstring_from_str, r=sfackler
Dylan-DPC May 16, 2020
21d58a1
Rollup merge of #71677 - Mark-Simulacrum:hasher-docs, r=Amanieu
Dylan-DPC May 16, 2020
154db50
Rollup merge of #71724 - GuillaumeGomez:doc-alias-improvements, r=oll…
Dylan-DPC May 16, 2020
badcf26
Rollup merge of #71948 - csmoe:issue-61076, r=oli-obk
Dylan-DPC May 16, 2020
040e242
Rollup merge of #72090 - RalfJung:rustc_driver-exit-code, r=oli-obk
Dylan-DPC May 16, 2020
c1d5640
Rollup merge of #72206 - sergey-melnychuk:cleanup-stale-fixme, r=petr…
Dylan-DPC May 16, 2020
89866ce
Rollup merge of #72218 - RalfJung:test-unleashed-ptrs, r=oli-obk
Dylan-DPC May 16, 2020
941dfb9
Rollup merge of #72220 - wesleywiser:const_prop_eval_consts, r=oli-obk
Dylan-DPC May 16, 2020
a27b1b6
Rollup merge of #72224 - lzutao:links, r=Dylan-DPC
Dylan-DPC May 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extend rustdoc-js tester to allow to test multiple queries in one file
  • Loading branch information
GuillaumeGomez committed May 7, 2020
commit d80ac14fe69676c34efdec0c1cc589d28cd03ab1
98 changes: 65 additions & 33 deletions src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function loadThings(thingsToLoad, kindOfLoad, funcToCall, fileContent) {
for (var i = 0; i < thingsToLoad.length; ++i) {
var tmp = funcToCall(fileContent, thingsToLoad[i]);
if (tmp === null) {
console.error('unable to find ' + kindOfLoad + ' "' + thingsToLoad[i] + '"');
console.log('unable to find ' + kindOfLoad + ' "' + thingsToLoad[i] + '"');
process.exit(1);
}
content += tmp;
Expand Down Expand Up @@ -223,7 +223,8 @@ function loadMainJsAndIndex(mainJs, aliases, searchIndex, crate) {
searchIndex.pop();
}
searchIndex.pop();
searchIndex = loadContent(searchIndex.join("\n") + '\nexports.searchIndex = searchIndex;');
var fullSearchIndex = searchIndex.join("\n") + '\nexports.rawSearchIndex = searchIndex;';
searchIndex = loadContent(fullSearchIndex);
var finalJS = "";

var arraysToLoad = ["itemTypes"];
Expand All @@ -235,7 +236,7 @@ function loadMainJsAndIndex(mainJs, aliases, searchIndex, crate) {
// execQuery last parameter is built in buildIndex.
// buildIndex requires the hashmap from search-index.
var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult",
"getQuery", "buildIndex", "execQuery", "execSearch"];
"handleAliases", "getQuery", "buildIndex", "execQuery", "execSearch"];

finalJS += 'window = { "currentCrate": "' + crate + '" };\n';
finalJS += 'var rootPath = "../";\n';
Expand All @@ -245,24 +246,19 @@ function loadMainJsAndIndex(mainJs, aliases, searchIndex, crate) {
finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs);

var loaded = loadContent(finalJS);
var index = loaded.buildIndex(searchIndex.searchIndex);
var index = loaded.buildIndex(searchIndex.rawSearchIndex);
// We make it "global" so that the "loaded.execSearch" function will find it.
rawSearchIndex = searchIndex.rawSearchIndex;

return [loaded, index];
}

function runChecks(testFile, loaded, index) {
var errors = 0;
var loadedFile = loadContent(
readFile(testFile) + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');

const expected = loadedFile.EXPECTED;
const query = loadedFile.QUERY;
function runSearch(query, expected, index, loaded, loadedFile, queryName) {
const filter_crate = loadedFile.FILTER_CRATE;
const ignore_order = loadedFile.ignore_order;
const exact_check = loadedFile.exact_check;
const should_fail = loadedFile.should_fail;

var results = loaded.execSearch(loaded.getQuery(query), index);
var results = loaded.execSearch(loaded.getQuery(query), index, filter_crate);
var error_text = [];

for (var key in expected) {
Expand All @@ -278,32 +274,68 @@ function runChecks(testFile, loaded, index) {
for (var i = 0; i < entry.length; ++i) {
var entry_pos = lookForEntry(entry[i], results[key]);
if (entry_pos === null) {
error_text.push("==> Result not found in '" + key + "': '" +
error_text.push(queryName + "==> Result not found in '" + key + "': '" +
JSON.stringify(entry[i]) + "'");
} else if (exact_check === true && prev_pos + 1 !== entry_pos) {
error_text.push("==> Exact check failed at position " + (prev_pos + 1) + ": " +
"expected '" + JSON.stringify(entry[i]) + "' but found '" +
error_text.push(queryName + "==> Exact check failed at position " + (prev_pos + 1) +
": expected '" + JSON.stringify(entry[i]) + "' but found '" +
JSON.stringify(results[key][i]) + "'");
} else if (ignore_order === false && entry_pos < prev_pos) {
error_text.push("==> '" + JSON.stringify(entry[i]) + "' was supposed to be " +
" before '" + JSON.stringify(results[key][entry_pos]) + "'");
error_text.push(queryName + "==> '" + JSON.stringify(entry[i]) + "' was supposed " +
"to be before '" + JSON.stringify(results[key][entry_pos]) + "'");
} else {
prev_pos = entry_pos;
}
}
}
if (error_text.length === 0 && should_fail === true) {
errors += 1;
console.error("FAILED");
console.error("==> Test was supposed to fail but all items were found...");
} else if (error_text.length !== 0 && should_fail === false) {
errors += 1;
console.error("FAILED");
console.error(error_text.join("\n"));
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"));
} else {
if (displaySuccess) {
console.log("OK");
}
return 0;
}
return 1;
}

function runChecks(testFile, loaded, index) {
var loadedFile = loadContent(
readFile(testFile) + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');

const expected = loadedFile.EXPECTED;
const query = loadedFile.QUERY;

if (Array.isArray(query)) {
if (!Array.isArray(expected)) {
console.log("FAILED");
console.log("==> If QUERY variable is an array, EXPECTED should be an array too");
return 1;
} else if (query.length !== expected.length) {
console.log("FAILED");
console.log("==> QUERY variable should have the same length as EXPECTED");
return 1;
}
for (var i = 0; i < query.length; ++i) {
var error_text = runSearch(query[i], expected[i], index, loaded, loadedFile,
"[ query `" + query[i] + "`]");
if (checkResult(error_text, loadedFile, false) !== 0) {
return 1;
}
}
console.log("OK");
return 0;
}
return errors;
var error_text = runSearch(query, expected, index, loaded, loadedFile, "");
return checkResult(error_text, loadedFile, true);
}

function load_files(doc_folder, resource_suffix, crate) {
Expand Down Expand Up @@ -349,25 +381,25 @@ function parseOptions(args) {
|| args[i] === "--crate-name") {
i += 1;
if (i >= args.length) {
console.error("Missing argument after `" + args[i - 1] + "` option.");
console.log("Missing argument after `" + args[i - 1] + "` option.");
return null;
}
opts[correspondances[args[i - 1]]] = args[i];
} else if (args[i] === "--help") {
showHelp();
process.exit(0);
} else {
console.error("Unknown option `" + args[i] + "`.");
console.error("Use `--help` to see the list of options");
console.log("Unknown option `" + args[i] + "`.");
console.log("Use `--help` to see the list of options");
return null;
}
}
if (opts["doc_folder"].length < 1) {
console.error("Missing `--doc-folder` option.");
console.log("Missing `--doc-folder` option.");
} else if (opts["crate_name"].length < 1) {
console.error("Missing `--crate-name` option.");
console.log("Missing `--crate-name` option.");
} else if (opts["test_folder"].length < 1 && opts["test_file"].length < 1) {
console.error("At least one of `--test-folder` or `--test-file` option is required.");
console.log("At least one of `--test-folder` or `--test-file` option is required.");
} else {
return opts;
}
Expand Down