From 37ab3dc5b3560792ae4eab0521e0c08bbbdd95d8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 10 Mar 2019 23:10:40 +0100 Subject: [PATCH] Make js tests work even with resource-suffix option --- src/tools/rustdoc-js-std/tester.js | 33 +++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/tools/rustdoc-js-std/tester.js b/src/tools/rustdoc-js-std/tester.js index f49dd86c8c32d..d5f0ab9f4292d 100644 --- a/src/tools/rustdoc-js-std/tester.js +++ b/src/tools/rustdoc-js-std/tester.js @@ -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 \ @@ -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(); }