Skip to content

Commit

Permalink
Make js tests work even with resource-suffix option
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Mar 10, 2019
1 parent d6add90 commit 37ab3dc
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/tools/rustdoc-js-std/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,32 @@ function lookForEntry(entry, data) {
return null;
}

function findFile(dir, name, extension) {
var entries = fs.readdirSync(dir);
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
var file_type = fs.statSync(dir + entry);
if (file_type.isDirectory()) {
continue;
}
if (entry.startsWith(name) && entry.endsWith(extension)) {
return entry;
}
}
return null;
}

function readFileMatching(dir, name, extension) {
if (dir.endsWith("/") === false) {
dir += "/";
}
var f = findFile(dir, name, extension);
if (f === null) {
return "";
}
return readFile(dir + f);
}

function main(argv) {
if (argv.length !== 3) {
console.error("Expected toolchain to check as argument (for example \
Expand All @@ -227,9 +253,10 @@ function main(argv) {
}
var toolchain = argv[2];

var mainJs = readFile("build/" + toolchain + "/doc/main.js");
var ALIASES = readFile("build/" + toolchain + "/doc/aliases.js");
var searchIndex = readFile("build/" + toolchain + "/doc/search-index.js").split("\n");
var mainJs = readFileMatching("build/" + toolchain + "/doc/", "main", ".js");
var ALIASES = readFileMatching("build/" + toolchain + "/doc/", "aliases", ".js");
var searchIndex = readFileMatching("build/" + toolchain + "/doc/",
"search-index", ".js").split("\n");
if (searchIndex[searchIndex.length - 1].length === 0) {
searchIndex.pop();
}
Expand Down

0 comments on commit 37ab3dc

Please sign in to comment.