From 834347ddafee7c33f3fd556c4976275b1111dc8f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 9 Feb 2019 20:28:22 +0100 Subject: [PATCH 1/7] Add rustdoc JS non-std tests --- src/bootstrap/builder.rs | 1 + src/bootstrap/test.rs | 44 +++ src/test/rustdoc-js-not-std/basic.js | 7 + src/test/rustdoc-js-not-std/basic.rs | 1 + src/tools/rustdoc-js-not-std/tester.js | 365 +++++++++++++++++++++++++ src/tools/rustdoc-js/tester.js | 3 +- 6 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-js-not-std/basic.js create mode 100644 src/test/rustdoc-js-not-std/basic.rs create mode 100644 src/tools/rustdoc-js-not-std/tester.js diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 7e6c0a9f52aa2..71b9cd6f9fba4 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -406,6 +406,7 @@ impl<'a> Builder<'a> { test::Clippy, test::CompiletestTest, test::RustdocJS, + test::RustdocJSNotStd, test::RustdocTheme, // Run bootstrap close to the end as it's unlikely to fail test::Bootstrap, diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 51412f79c3d0c..7dcc10e8a0918 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -612,6 +612,50 @@ impl Step for RustdocJS { } } +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct RustdocJSNotStd { + pub host: Interned, + pub target: Interned, + pub compiler: Compiler, +} + +impl Step for RustdocJSNotStd { + type Output = (); + const DEFAULT: bool = true; + const ONLY_HOSTS: bool = true; + + fn should_run(run: ShouldRun) -> ShouldRun { + run.path("src/test/rustdoc-js-not-std") + } + + fn make_run(run: RunConfig) { + let compiler = run.builder.compiler(run.builder.top_stage, run.host); + run.builder.ensure(RustdocJSNotStd { + host: run.host, + target: run.target, + compiler, + }); + } + + fn run(self, builder: &Builder) { + if let Some(ref nodejs) = builder.config.nodejs { + let mut command = Command::new(nodejs); + command.args(&["src/tools/rustdoc-js-not-std/tester.js", + &*self.host, + builder.top_stage.to_string().as_str()]); + builder.ensure(crate::doc::Std { + target: self.target, + stage: builder.top_stage, + }); + builder.run(&mut command); + } else { + builder.info( + "No nodejs found, skipping \"src/test/rustdoc-js-not-std\" tests" + ); + } + } +} + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct RustdocUi { pub host: Interned, diff --git a/src/test/rustdoc-js-not-std/basic.js b/src/test/rustdoc-js-not-std/basic.js new file mode 100644 index 0000000000000..d99b23468b60c --- /dev/null +++ b/src/test/rustdoc-js-not-std/basic.js @@ -0,0 +1,7 @@ +const QUERY = 'Fo'; + +const EXPECTED = { + 'others': [ + { 'path': 'basic', 'name': 'Foo' }, + ], +}; diff --git a/src/test/rustdoc-js-not-std/basic.rs b/src/test/rustdoc-js-not-std/basic.rs new file mode 100644 index 0000000000000..4a835673a596b --- /dev/null +++ b/src/test/rustdoc-js-not-std/basic.rs @@ -0,0 +1 @@ +pub struct Foo; diff --git a/src/tools/rustdoc-js-not-std/tester.js b/src/tools/rustdoc-js-not-std/tester.js new file mode 100644 index 0000000000000..61490b2f48d03 --- /dev/null +++ b/src/tools/rustdoc-js-not-std/tester.js @@ -0,0 +1,365 @@ +const fs = require('fs'); +const { spawnSync } = require('child_process'); + +const TEST_FOLDER = 'src/test/rustdoc-js-not-std/'; + +function getNextStep(content, pos, stop) { + while (pos < content.length && content[pos] !== stop && + (content[pos] === ' ' || content[pos] === '\t' || content[pos] === '\n')) { + pos += 1; + } + if (pos >= content.length) { + return null; + } + if (content[pos] !== stop) { + return pos * -1; + } + return pos; +} + +// Stupid function extractor based on indent. Doesn't support block +// comments. If someone puts a ' or an " in a block comment this +// will blow up. Template strings are not tested and might also be +// broken. +function extractFunction(content, functionName) { + var indent = 0; + var splitter = "function " + functionName + "("; + + while (true) { + var start = content.indexOf(splitter); + if (start === -1) { + break; + } + var pos = start; + while (pos < content.length && content[pos] !== ')') { + pos += 1; + } + if (pos >= content.length) { + break; + } + pos = getNextStep(content, pos + 1, '{'); + if (pos === null) { + break; + } else if (pos < 0) { + content = content.slice(-pos); + continue; + } + while (pos < content.length) { + // Eat single-line comments + if (content[pos] === '/' && pos > 0 && content[pos-1] === '/') { + do { + pos += 1; + } while (pos < content.length && content[pos] !== '\n'); + + // Eat quoted strings + } else if (content[pos] === '"' || content[pos] === "'" || content[pos] === "`") { + var stop = content[pos]; + var is_escaped = false; + do { + if (content[pos] === '\\') { + pos += 2; + } else { + pos += 1; + } + } while (pos < content.length && + (content[pos] !== stop || content[pos - 1] === '\\')); + + // Otherwise, check for indent + } else if (content[pos] === '{') { + indent += 1; + } else if (content[pos] === '}') { + indent -= 1; + if (indent === 0) { + return content.slice(start, pos + 1); + } + } + pos += 1; + } + content = content.slice(start + 1); + } + return null; +} + +// Stupid function extractor for array. +function extractArrayVariable(content, arrayName) { + var splitter = "var " + arrayName; + while (true) { + var start = content.indexOf(splitter); + if (start === -1) { + break; + } + var pos = getNextStep(content, start, '='); + if (pos === null) { + break; + } else if (pos < 0) { + content = content.slice(-pos); + continue; + } + pos = getNextStep(content, pos, '['); + if (pos === null) { + break; + } else if (pos < 0) { + content = content.slice(-pos); + continue; + } + while (pos < content.length) { + if (content[pos] === '"' || content[pos] === "'") { + var stop = content[pos]; + do { + if (content[pos] === '\\') { + pos += 2; + } else { + pos += 1; + } + } while (pos < content.length && + (content[pos] !== stop || content[pos - 1] === '\\')); + } else if (content[pos] === ']' && + pos + 1 < content.length && + content[pos + 1] === ';') { + return content.slice(start, pos + 2); + } + pos += 1; + } + content = content.slice(start + 1); + } + return null; +} + +// Stupid function extractor for variable. +function extractVariable(content, varName) { + var splitter = "var " + varName; + while (true) { + var start = content.indexOf(splitter); + if (start === -1) { + break; + } + var pos = getNextStep(content, start, '='); + if (pos === null) { + break; + } else if (pos < 0) { + content = content.slice(-pos); + continue; + } + while (pos < content.length) { + if (content[pos] === '"' || content[pos] === "'") { + var stop = content[pos]; + do { + if (content[pos] === '\\') { + pos += 2; + } else { + pos += 1; + } + } while (pos < content.length && + (content[pos] !== stop || content[pos - 1] === '\\')); + } else if (content[pos] === ';') { + return content.slice(start, pos + 1); + } + pos += 1; + } + content = content.slice(start + 1); + } + return null; +} + +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'); +} + +function loadThings(thingsToLoad, kindOfLoad, funcToCall, fileContent) { + var content = ''; + 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] + '"'); + process.exit(1); + } + content += tmp; + content += 'exports.' + thingsToLoad[i] + ' = ' + thingsToLoad[i] + ';'; + } + return content; +} + +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; +} + +function remove_docs(out_dir) { + spawnSync('rm', ['-rf', out_dir]); +} + +function build_docs(out_dir, rustdoc_path, file_to_document) { + remove_docs(out_dir); + var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]); + var s = ''; + if (c.error || c.stderr.length > 0) { + if (c.stderr.length > 0) { + s += '==> STDERR: ' + c.stderr + '\n'; + } + s += '==> ERROR: ' + c.error; + } + return s; +} + +function load_files(out_folder, crate) { + var mainJs = readFile(out_folder + "/main.js"); + var ALIASES = readFile(out_folder + "/aliases.js"); + var searchIndex = readFile(out_folder + "/search-index.js").split("\n"); + if (searchIndex[searchIndex.length - 1].length === 0) { + searchIndex.pop(); + } + searchIndex.pop(); + searchIndex = loadContent(searchIndex.join("\n") + '\nexports.searchIndex = searchIndex;'); + finalJS = ""; + + var arraysToLoad = ["itemTypes"]; + var variablesToLoad = ["MAX_LEV_DISTANCE", "MAX_RESULTS", + "GENERICS_DATA", "NAME", "INPUTS_DATA", "OUTPUT_DATA", + "TY_PRIMITIVE", "TY_KEYWORD", + "levenshtein_row2"]; + // execQuery first parameter is built in getQuery (which takes in the search input). + // execQuery last parameter is built in buildIndex. + // buildIndex requires the hashmap from search-index. + var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult", + "getQuery", "buildIndex", "execQuery", "execSearch"]; + + finalJS += 'window = { "currentCrate": "' + crate + '" };\n'; + finalJS += 'var rootPath = "../";\n'; + finalJS += ALIASES; + finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs); + finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs); + finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs); + + var loaded = loadContent(finalJS); + return [loaded, loaded.buildIndex(searchIndex.searchIndex)]; +} + +function main(argv) { + if (argv.length !== 4) { + console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]"); + return 1; + } + const toolchain = argv[2]; + const stage = argv[3]; + const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc'; + + var errors = 0; + + fs.readdirSync(TEST_FOLDER).forEach(function(file) { + if (!file.endsWith('.js')) { + return; + } + var test_name = file.substring(0, file.length - 3); + process.stdout.write('Checking "' + test_name + '" ... '); + var rust_file = TEST_FOLDER + test_name + '.rs'; + + if (!fs.existsSync(rust_file)) { + console.error("FAILED"); + console.error("==> Missing '" + test_name + ".rs' file..."); + errors += 1; + return; + } + + var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js-not-std/" + + test_name; + + var ret = build_docs(out_folder, rustdoc_path, rust_file); + if (ret.length > 0) { + console.error("FAILED"); + console.error(ret); + errors += 1; + return; + } + + var [loaded, index] = load_files(out_folder, test_name); + var loadedFile = loadContent(readFile(TEST_FOLDER + file) + + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); + const expected = loadedFile.EXPECTED; + const query = loadedFile.QUERY; + 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 error_text = []; + for (var key in expected) { + if (!expected.hasOwnProperty(key)) { + continue; + } + if (!results.hasOwnProperty(key)) { + error_text.push('==> Unknown key "' + key + '"'); + break; + } + var entry = expected[key]; + var prev_pos = -1; + 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 + "': '" + + 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 '" + + 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]) + "'"); + } 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")); + } else { + // In this case, we remove the docs, no need to keep them around. + remove_docs(out_folder); + console.log("OK"); + } + }); + return errors; +} + +process.exit(main(process.argv)); diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index c41da93a98310..38fdcb4f468cf 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -221,7 +221,8 @@ function lookForEntry(entry, data) { function main(argv) { if (argv.length !== 3) { - console.error("Expected toolchain to check as argument (for example 'x86_64-apple-darwin'"); + console.error("Expected toolchain to check as argument (for example \ + 'x86_64-apple-darwin')"); return 1; } var toolchain = argv[2]; From aa3ca321e92c541dce363634c9cea7cf23689a5e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 24 Feb 2019 00:08:43 +0100 Subject: [PATCH 2/7] Rename rustdoc js test suites --- src/bootstrap/builder.rs | 2 +- src/bootstrap/test.rs | 18 ++--- src/test/rustdoc-js-not-std/basic.js | 7 -- .../{rustdoc-js => rustdoc-js-std}/alias-1.js | 0 .../{rustdoc-js => rustdoc-js-std}/alias-2.js | 0 .../{rustdoc-js => rustdoc-js-std}/alias-3.js | 0 .../{rustdoc-js => rustdoc-js-std}/alias.js | 0 src/test/rustdoc-js-std/basic.js | 15 ++++ .../deduplication.js | 0 .../enum-option.js | 0 .../filter-crate.js | 0 .../fn-forget.js | 0 .../{rustdoc-js => rustdoc-js-std}/from_u.js | 0 .../{rustdoc-js => rustdoc-js-std}/keyword.js | 0 .../macro-check.js | 0 .../macro-print.js | 0 .../multi-query.js | 0 .../{rustdoc-js => rustdoc-js-std}/never.js | 0 .../{rustdoc-js => rustdoc-js-std}/quoted.js | 0 .../should-fail.js | 0 .../string-from_ut.js | 0 .../struct-vec.js | 0 .../{rustdoc-js => rustdoc-js-std}/vec-new.js | 0 src/test/rustdoc-js/basic.js | 12 +-- .../basic.rs | 0 .../tester.js | 74 ++++--------------- src/tools/rustdoc-js/tester.js | 65 +++++++++++++--- 27 files changed, 93 insertions(+), 100 deletions(-) delete mode 100644 src/test/rustdoc-js-not-std/basic.js rename src/test/{rustdoc-js => rustdoc-js-std}/alias-1.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/alias-2.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/alias-3.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/alias.js (100%) create mode 100644 src/test/rustdoc-js-std/basic.js rename src/test/{rustdoc-js => rustdoc-js-std}/deduplication.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/enum-option.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/filter-crate.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/fn-forget.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/from_u.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/keyword.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/macro-check.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/macro-print.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/multi-query.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/never.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/quoted.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/should-fail.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/string-from_ut.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/struct-vec.js (100%) rename src/test/{rustdoc-js => rustdoc-js-std}/vec-new.js (100%) rename src/test/{rustdoc-js-not-std => rustdoc-js}/basic.rs (100%) rename src/tools/{rustdoc-js-not-std => rustdoc-js-std}/tester.js (83%) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 71b9cd6f9fba4..a471af257665f 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -405,7 +405,7 @@ impl<'a> Builder<'a> { test::Miri, test::Clippy, test::CompiletestTest, - test::RustdocJS, + test::RustdocJSStd, test::RustdocJSNotStd, test::RustdocTheme, // Run bootstrap close to the end as it's unlikely to fail diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 7dcc10e8a0918..c724d75c2dc06 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -574,22 +574,22 @@ impl Step for RustdocTheme { } #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct RustdocJS { +pub struct RustdocJSStd { pub host: Interned, pub target: Interned, } -impl Step for RustdocJS { +impl Step for RustdocJSStd { type Output = (); const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/test/rustdoc-js") + run.path("src/test/rustdoc-js-std") } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(RustdocJS { + run.builder.ensure(RustdocJSStd { host: run.host, target: run.target, }); @@ -598,7 +598,7 @@ impl Step for RustdocJS { fn run(self, builder: &Builder<'_>) { if let Some(ref nodejs) = builder.config.nodejs { let mut command = Command::new(nodejs); - command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]); + command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]); builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage, @@ -606,7 +606,7 @@ impl Step for RustdocJS { builder.run(&mut command); } else { builder.info( - "No nodejs found, skipping \"src/test/rustdoc-js\" tests" + "No nodejs found, skipping \"src/test/rustdoc-js-std\" tests" ); } } @@ -625,7 +625,7 @@ impl Step for RustdocJSNotStd { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun) -> ShouldRun { - run.path("src/test/rustdoc-js-not-std") + run.path("src/test/rustdoc-js") } fn make_run(run: RunConfig) { @@ -640,7 +640,7 @@ impl Step for RustdocJSNotStd { fn run(self, builder: &Builder) { if let Some(ref nodejs) = builder.config.nodejs { let mut command = Command::new(nodejs); - command.args(&["src/tools/rustdoc-js-not-std/tester.js", + command.args(&["src/tools/rustdoc-js/tester.js", &*self.host, builder.top_stage.to_string().as_str()]); builder.ensure(crate::doc::Std { @@ -650,7 +650,7 @@ impl Step for RustdocJSNotStd { builder.run(&mut command); } else { builder.info( - "No nodejs found, skipping \"src/test/rustdoc-js-not-std\" tests" + "No nodejs found, skipping \"src/test/rustdoc-js\" tests" ); } } diff --git a/src/test/rustdoc-js-not-std/basic.js b/src/test/rustdoc-js-not-std/basic.js deleted file mode 100644 index d99b23468b60c..0000000000000 --- a/src/test/rustdoc-js-not-std/basic.js +++ /dev/null @@ -1,7 +0,0 @@ -const QUERY = 'Fo'; - -const EXPECTED = { - 'others': [ - { 'path': 'basic', 'name': 'Foo' }, - ], -}; diff --git a/src/test/rustdoc-js/alias-1.js b/src/test/rustdoc-js-std/alias-1.js similarity index 100% rename from src/test/rustdoc-js/alias-1.js rename to src/test/rustdoc-js-std/alias-1.js diff --git a/src/test/rustdoc-js/alias-2.js b/src/test/rustdoc-js-std/alias-2.js similarity index 100% rename from src/test/rustdoc-js/alias-2.js rename to src/test/rustdoc-js-std/alias-2.js diff --git a/src/test/rustdoc-js/alias-3.js b/src/test/rustdoc-js-std/alias-3.js similarity index 100% rename from src/test/rustdoc-js/alias-3.js rename to src/test/rustdoc-js-std/alias-3.js diff --git a/src/test/rustdoc-js/alias.js b/src/test/rustdoc-js-std/alias.js similarity index 100% rename from src/test/rustdoc-js/alias.js rename to src/test/rustdoc-js-std/alias.js diff --git a/src/test/rustdoc-js-std/basic.js b/src/test/rustdoc-js-std/basic.js new file mode 100644 index 0000000000000..824cac7108332 --- /dev/null +++ b/src/test/rustdoc-js-std/basic.js @@ -0,0 +1,15 @@ +const QUERY = 'String'; + +const EXPECTED = { + 'others': [ + { 'path': 'std::string', 'name': 'String' }, + { 'path': 'std::ffi', 'name': 'CString' }, + { 'path': 'std::ffi', 'name': 'OsString' }, + ], + 'in_args': [ + { 'path': 'std::str', 'name': 'eq' }, + ], + 'returned': [ + { 'path': 'std::string::String', 'name': 'add' }, + ], +}; diff --git a/src/test/rustdoc-js/deduplication.js b/src/test/rustdoc-js-std/deduplication.js similarity index 100% rename from src/test/rustdoc-js/deduplication.js rename to src/test/rustdoc-js-std/deduplication.js diff --git a/src/test/rustdoc-js/enum-option.js b/src/test/rustdoc-js-std/enum-option.js similarity index 100% rename from src/test/rustdoc-js/enum-option.js rename to src/test/rustdoc-js-std/enum-option.js diff --git a/src/test/rustdoc-js/filter-crate.js b/src/test/rustdoc-js-std/filter-crate.js similarity index 100% rename from src/test/rustdoc-js/filter-crate.js rename to src/test/rustdoc-js-std/filter-crate.js diff --git a/src/test/rustdoc-js/fn-forget.js b/src/test/rustdoc-js-std/fn-forget.js similarity index 100% rename from src/test/rustdoc-js/fn-forget.js rename to src/test/rustdoc-js-std/fn-forget.js diff --git a/src/test/rustdoc-js/from_u.js b/src/test/rustdoc-js-std/from_u.js similarity index 100% rename from src/test/rustdoc-js/from_u.js rename to src/test/rustdoc-js-std/from_u.js diff --git a/src/test/rustdoc-js/keyword.js b/src/test/rustdoc-js-std/keyword.js similarity index 100% rename from src/test/rustdoc-js/keyword.js rename to src/test/rustdoc-js-std/keyword.js diff --git a/src/test/rustdoc-js/macro-check.js b/src/test/rustdoc-js-std/macro-check.js similarity index 100% rename from src/test/rustdoc-js/macro-check.js rename to src/test/rustdoc-js-std/macro-check.js diff --git a/src/test/rustdoc-js/macro-print.js b/src/test/rustdoc-js-std/macro-print.js similarity index 100% rename from src/test/rustdoc-js/macro-print.js rename to src/test/rustdoc-js-std/macro-print.js diff --git a/src/test/rustdoc-js/multi-query.js b/src/test/rustdoc-js-std/multi-query.js similarity index 100% rename from src/test/rustdoc-js/multi-query.js rename to src/test/rustdoc-js-std/multi-query.js diff --git a/src/test/rustdoc-js/never.js b/src/test/rustdoc-js-std/never.js similarity index 100% rename from src/test/rustdoc-js/never.js rename to src/test/rustdoc-js-std/never.js diff --git a/src/test/rustdoc-js/quoted.js b/src/test/rustdoc-js-std/quoted.js similarity index 100% rename from src/test/rustdoc-js/quoted.js rename to src/test/rustdoc-js-std/quoted.js diff --git a/src/test/rustdoc-js/should-fail.js b/src/test/rustdoc-js-std/should-fail.js similarity index 100% rename from src/test/rustdoc-js/should-fail.js rename to src/test/rustdoc-js-std/should-fail.js diff --git a/src/test/rustdoc-js/string-from_ut.js b/src/test/rustdoc-js-std/string-from_ut.js similarity index 100% rename from src/test/rustdoc-js/string-from_ut.js rename to src/test/rustdoc-js-std/string-from_ut.js diff --git a/src/test/rustdoc-js/struct-vec.js b/src/test/rustdoc-js-std/struct-vec.js similarity index 100% rename from src/test/rustdoc-js/struct-vec.js rename to src/test/rustdoc-js-std/struct-vec.js diff --git a/src/test/rustdoc-js/vec-new.js b/src/test/rustdoc-js-std/vec-new.js similarity index 100% rename from src/test/rustdoc-js/vec-new.js rename to src/test/rustdoc-js-std/vec-new.js diff --git a/src/test/rustdoc-js/basic.js b/src/test/rustdoc-js/basic.js index 824cac7108332..d99b23468b60c 100644 --- a/src/test/rustdoc-js/basic.js +++ b/src/test/rustdoc-js/basic.js @@ -1,15 +1,7 @@ -const QUERY = 'String'; +const QUERY = 'Fo'; const EXPECTED = { 'others': [ - { 'path': 'std::string', 'name': 'String' }, - { 'path': 'std::ffi', 'name': 'CString' }, - { 'path': 'std::ffi', 'name': 'OsString' }, - ], - 'in_args': [ - { 'path': 'std::str', 'name': 'eq' }, - ], - 'returned': [ - { 'path': 'std::string::String', 'name': 'add' }, + { 'path': 'basic', 'name': 'Foo' }, ], }; diff --git a/src/test/rustdoc-js-not-std/basic.rs b/src/test/rustdoc-js/basic.rs similarity index 100% rename from src/test/rustdoc-js-not-std/basic.rs rename to src/test/rustdoc-js/basic.rs diff --git a/src/tools/rustdoc-js-not-std/tester.js b/src/tools/rustdoc-js-std/tester.js similarity index 83% rename from src/tools/rustdoc-js-not-std/tester.js rename to src/tools/rustdoc-js-std/tester.js index 61490b2f48d03..f49dd86c8c32d 100644 --- a/src/tools/rustdoc-js-not-std/tester.js +++ b/src/tools/rustdoc-js-std/tester.js @@ -1,7 +1,6 @@ const fs = require('fs'); -const { spawnSync } = require('child_process'); -const TEST_FOLDER = 'src/test/rustdoc-js-not-std/'; +const TEST_FOLDER = 'src/test/rustdoc-js-std/'; function getNextStep(content, pos, stop) { while (pos < content.length && content[pos] !== stop && @@ -220,27 +219,17 @@ function lookForEntry(entry, data) { return null; } -function remove_docs(out_dir) { - spawnSync('rm', ['-rf', out_dir]); -} - -function build_docs(out_dir, rustdoc_path, file_to_document) { - remove_docs(out_dir); - var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]); - var s = ''; - if (c.error || c.stderr.length > 0) { - if (c.stderr.length > 0) { - s += '==> STDERR: ' + c.stderr + '\n'; - } - s += '==> ERROR: ' + c.error; +function main(argv) { + if (argv.length !== 3) { + console.error("Expected toolchain to check as argument (for example \ + 'x86_64-apple-darwin')"); + return 1; } - return s; -} + var toolchain = argv[2]; -function load_files(out_folder, crate) { - var mainJs = readFile(out_folder + "/main.js"); - var ALIASES = readFile(out_folder + "/aliases.js"); - var searchIndex = readFile(out_folder + "/search-index.js").split("\n"); + 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"); if (searchIndex[searchIndex.length - 1].length === 0) { searchIndex.pop(); } @@ -259,7 +248,7 @@ function load_files(out_folder, crate) { var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult", "getQuery", "buildIndex", "execQuery", "execSearch"]; - finalJS += 'window = { "currentCrate": "' + crate + '" };\n'; + finalJS += 'window = { "currentCrate": "std" };\n'; finalJS += 'var rootPath = "../";\n'; finalJS += ALIASES; finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs); @@ -267,47 +256,11 @@ function load_files(out_folder, crate) { finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs); var loaded = loadContent(finalJS); - return [loaded, loaded.buildIndex(searchIndex.searchIndex)]; -} - -function main(argv) { - if (argv.length !== 4) { - console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]"); - return 1; - } - const toolchain = argv[2]; - const stage = argv[3]; - const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc'; + var index = loaded.buildIndex(searchIndex.searchIndex); var errors = 0; fs.readdirSync(TEST_FOLDER).forEach(function(file) { - if (!file.endsWith('.js')) { - return; - } - var test_name = file.substring(0, file.length - 3); - process.stdout.write('Checking "' + test_name + '" ... '); - var rust_file = TEST_FOLDER + test_name + '.rs'; - - if (!fs.existsSync(rust_file)) { - console.error("FAILED"); - console.error("==> Missing '" + test_name + ".rs' file..."); - errors += 1; - return; - } - - var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js-not-std/" + - test_name; - - var ret = build_docs(out_folder, rustdoc_path, rust_file); - if (ret.length > 0) { - console.error("FAILED"); - console.error(ret); - errors += 1; - return; - } - - var [loaded, index] = load_files(out_folder, test_name); var loadedFile = loadContent(readFile(TEST_FOLDER + file) + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); const expected = loadedFile.EXPECTED; @@ -317,6 +270,7 @@ function main(argv) { const exact_check = loadedFile.exact_check; const should_fail = loadedFile.should_fail; var results = loaded.execSearch(loaded.getQuery(query), index); + process.stdout.write('Checking "' + file + '" ... '); var error_text = []; for (var key in expected) { if (!expected.hasOwnProperty(key)) { @@ -354,8 +308,6 @@ function main(argv) { console.error("FAILED"); console.error(error_text.join("\n")); } else { - // In this case, we remove the docs, no need to keep them around. - remove_docs(out_folder); console.log("OK"); } }); diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index 38fdcb4f468cf..f7c15eaf1b07d 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -1,4 +1,5 @@ const fs = require('fs'); +const { spawnSync } = require('child_process'); const TEST_FOLDER = 'src/test/rustdoc-js/'; @@ -219,17 +220,22 @@ function lookForEntry(entry, data) { return null; } -function main(argv) { - if (argv.length !== 3) { - console.error("Expected toolchain to check as argument (for example \ - 'x86_64-apple-darwin')"); - return 1; +function build_docs(out_dir, rustdoc_path, file_to_document) { + var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]); + var s = ''; + if (c.error || c.stderr.length > 0) { + if (c.stderr.length > 0) { + s += '==> STDERR: ' + c.stderr + '\n'; + } + s += '==> ERROR: ' + c.error; } - var toolchain = argv[2]; + return s; +} - 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"); +function load_files(out_folder, crate) { + var mainJs = readFile(out_folder + "/main.js"); + var ALIASES = readFile(out_folder + "/aliases.js"); + var searchIndex = readFile(out_folder + "/search-index.js").split("\n"); if (searchIndex[searchIndex.length - 1].length === 0) { searchIndex.pop(); } @@ -248,7 +254,7 @@ function main(argv) { var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult", "getQuery", "buildIndex", "execQuery", "execSearch"]; - finalJS += 'window = { "currentCrate": "std" };\n'; + finalJS += 'window = { "currentCrate": "' + crate + '" };\n'; finalJS += 'var rootPath = "../";\n'; finalJS += ALIASES; finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs); @@ -256,11 +262,47 @@ function main(argv) { finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs); var loaded = loadContent(finalJS); - var index = loaded.buildIndex(searchIndex.searchIndex); + return [loaded, loaded.buildIndex(searchIndex.searchIndex)]; +} + +function main(argv) { + if (argv.length !== 4) { + console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]"); + return 1; + } + const toolchain = argv[2]; + const stage = argv[3]; + const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc'; var errors = 0; fs.readdirSync(TEST_FOLDER).forEach(function(file) { + if (!file.endsWith('.js')) { + return; + } + var test_name = file.substring(0, file.length - 3); + process.stdout.write('Checking "' + test_name + '" ... '); + var rust_file = TEST_FOLDER + test_name + '.rs'; + + if (!fs.existsSync(rust_file)) { + console.error("FAILED"); + console.error("==> Missing '" + test_name + ".rs' file..."); + errors += 1; + return; + } + + var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js/" + + test_name; + + var ret = build_docs(out_folder, rustdoc_path, rust_file); + if (ret.length > 0) { + console.error("FAILED"); + console.error(ret); + errors += 1; + return; + } + + var [loaded, index] = load_files(out_folder, test_name); var loadedFile = loadContent(readFile(TEST_FOLDER + file) + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); const expected = loadedFile.EXPECTED; @@ -270,7 +312,6 @@ function main(argv) { const exact_check = loadedFile.exact_check; const should_fail = loadedFile.should_fail; var results = loaded.execSearch(loaded.getQuery(query), index); - process.stdout.write('Checking "' + file + '" ... '); var error_text = []; for (var key in expected) { if (!expected.hasOwnProperty(key)) { From be23cd9a2d32295240e265aa2ed38bace71aca65 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 24 Feb 2019 01:04:07 +0100 Subject: [PATCH 3/7] Move documentation build into bootstrap --- src/bootstrap/test.rs | 46 ++++++++++++++++++++++++--- src/tools/rustdoc-js/tester.js | 58 ++++++++++------------------------ 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index c724d75c2dc06..83066468cd435 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -4,7 +4,7 @@ //! our CI. use std::env; -use std::ffi::OsString; +use std::ffi::{OsStr, OsString}; use std::fmt; use std::fs; use std::iter; @@ -639,14 +639,50 @@ impl Step for RustdocJSNotStd { fn run(self, builder: &Builder) { if let Some(ref nodejs) = builder.config.nodejs { - let mut command = Command::new(nodejs); - command.args(&["src/tools/rustdoc-js/tester.js", - &*self.host, - builder.top_stage.to_string().as_str()]); builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage, }); + + let mut tests_to_run = Vec::new(); + let out = Path::new("build").join(&*self.host) + .join(&format!("stage{}", + builder.top_stage.to_string().as_str())) + .join("tests") + .join("rustdoc-js"); + + if let Ok(it) = fs::read_dir("src/test/rustdoc-js/") { + for entry in it { + if let Ok(entry) = entry { + let path = entry.path(); + if path.extension() != Some(&OsStr::new("rs")) || !path.is_file() { + continue + } + let path_clone = path.clone(); + let file_stem = path_clone.file_stem().expect("cannot get file stem"); + let out = out.join(file_stem); + let mut cmd = builder.rustdoc_cmd(self.host); + cmd.arg("-o"); + cmd.arg(out); + cmd.arg(path); + if if builder.config.verbose_tests { + try_run(builder, &mut cmd) + } else { + try_run_quiet(builder, &mut cmd) + } { + tests_to_run.push(file_stem.to_os_string()); + } + } + } + } + assert!(!tests_to_run.is_empty(), "no rustdoc-js test generated..."); + + tests_to_run.insert(0, "src/tools/rustdoc-js/tester.js".into()); + tests_to_run.insert(1, out.into()); + + let mut command = Command::new(nodejs); + command.args(&tests_to_run); + builder.run(&mut command); } else { builder.info( diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index f7c15eaf1b07d..833ce5d137047 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -220,18 +220,6 @@ function lookForEntry(entry, data) { return null; } -function build_docs(out_dir, rustdoc_path, file_to_document) { - var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]); - var s = ''; - if (c.error || c.stderr.length > 0) { - if (c.stderr.length > 0) { - s += '==> STDERR: ' + c.stderr + '\n'; - } - s += '==> ERROR: ' + c.error; - } - return s; -} - function load_files(out_folder, crate) { var mainJs = readFile(out_folder + "/main.js"); var ALIASES = readFile(out_folder + "/aliases.js"); @@ -266,44 +254,32 @@ function load_files(out_folder, crate) { } function main(argv) { - if (argv.length !== 4) { - console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]"); + if (argv.length < 4) { + console.error("USAGE: node tester.js OUT_FOLDER [TESTS]"); return 1; } - const toolchain = argv[2]; - const stage = argv[3]; - const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc'; + if (argv[2].substr(-1) !== "/") { + argv[2] += "/"; + } + const out_folder = argv[2]; var errors = 0; - fs.readdirSync(TEST_FOLDER).forEach(function(file) { - if (!file.endsWith('.js')) { - return; - } - var test_name = file.substring(0, file.length - 3); - process.stdout.write('Checking "' + test_name + '" ... '); - var rust_file = TEST_FOLDER + test_name + '.rs'; + for (var j = 3; j < argv.length; ++j) { + const test_name = argv[j]; - if (!fs.existsSync(rust_file)) { - console.error("FAILED"); - console.error("==> Missing '" + test_name + ".rs' file..."); + process.stdout.write('Checking "' + test_name + '" ... '); + if (!fs.existsSync(TEST_FOLDER + test_name + ".js")) { errors += 1; - return; - } - - var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js/" + - test_name; - - var ret = build_docs(out_folder, rustdoc_path, rust_file); - if (ret.length > 0) { console.error("FAILED"); - console.error(ret); - errors += 1; - return; + console.error("==> Missing '" + test_name + ".js' file..."); + continue; } - var [loaded, index] = load_files(out_folder, test_name); - var loadedFile = loadContent(readFile(TEST_FOLDER + file) + + const test_out_folder = out_folder + test_name; + + var [loaded, index] = load_files(test_out_folder, test_name); + var loadedFile = loadContent(readFile(TEST_FOLDER + test_name + ".js") + 'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;'); const expected = loadedFile.EXPECTED; const query = loadedFile.QUERY; @@ -351,7 +327,7 @@ function main(argv) { } else { console.log("OK"); } - }); + } return errors; } From 240fad04f1c5517d5d38ab62c321f09c35a468d1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Feb 2019 17:47:12 +0100 Subject: [PATCH 4/7] Update to last updates --- src/bootstrap/test.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 83066468cd435..97a5c500b1a47 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -624,11 +624,11 @@ impl Step for RustdocJSNotStd { const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; - fn should_run(run: ShouldRun) -> ShouldRun { + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { run.path("src/test/rustdoc-js") } - fn make_run(run: RunConfig) { + fn make_run(run: RunConfig<'_>) { let compiler = run.builder.compiler(run.builder.top_stage, run.host); run.builder.ensure(RustdocJSNotStd { host: run.host, @@ -637,7 +637,7 @@ impl Step for RustdocJSNotStd { }); } - fn run(self, builder: &Builder) { + fn run(self, builder: &Builder<'_>) { if let Some(ref nodejs) = builder.config.nodejs { builder.ensure(crate::doc::Std { target: self.target, From 405d95080288dc760e117a506278d968d57dfe09 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 28 Feb 2019 18:08:48 +0100 Subject: [PATCH 5/7] Move rustdoc-js testing into compiletest --- src/bootstrap/test.rs | 62 ++++++---------------------- src/test/rustdoc-js/basic.rs | 1 + src/tools/compiletest/src/common.rs | 3 ++ src/tools/compiletest/src/runtest.rs | 29 +++++++++++-- 4 files changed, 42 insertions(+), 53 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 97a5c500b1a47..b7323b2eadc3d 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -4,7 +4,7 @@ //! our CI. use std::env; -use std::ffi::{OsStr, OsString}; +use std::ffi::OsString; use std::fmt; use std::fs; use std::iter; @@ -638,52 +638,15 @@ impl Step for RustdocJSNotStd { } fn run(self, builder: &Builder<'_>) { - if let Some(ref nodejs) = builder.config.nodejs { - builder.ensure(crate::doc::Std { + if builder.config.nodejs.is_some() { + builder.ensure(Compiletest { + compiler: self.compiler, target: self.target, - stage: builder.top_stage, + mode: "js-doc-test", + suite: "rustdoc-js", + path: None, + compare_mode: None, }); - - let mut tests_to_run = Vec::new(); - let out = Path::new("build").join(&*self.host) - .join(&format!("stage{}", - builder.top_stage.to_string().as_str())) - .join("tests") - .join("rustdoc-js"); - - if let Ok(it) = fs::read_dir("src/test/rustdoc-js/") { - for entry in it { - if let Ok(entry) = entry { - let path = entry.path(); - if path.extension() != Some(&OsStr::new("rs")) || !path.is_file() { - continue - } - let path_clone = path.clone(); - let file_stem = path_clone.file_stem().expect("cannot get file stem"); - let out = out.join(file_stem); - let mut cmd = builder.rustdoc_cmd(self.host); - cmd.arg("-o"); - cmd.arg(out); - cmd.arg(path); - if if builder.config.verbose_tests { - try_run(builder, &mut cmd) - } else { - try_run_quiet(builder, &mut cmd) - } { - tests_to_run.push(file_stem.to_os_string()); - } - } - } - } - assert!(!tests_to_run.is_empty(), "no rustdoc-js test generated..."); - - tests_to_run.insert(0, "src/tools/rustdoc-js/tester.js".into()); - tests_to_run.insert(1, out.into()); - - let mut command = Command::new(nodejs); - command.args(&tests_to_run); - - builder.run(&mut command); } else { builder.info( "No nodejs found, skipping \"src/test/rustdoc-js\" tests" @@ -1070,12 +1033,13 @@ impl Step for Compiletest { .arg(builder.sysroot_libdir(compiler, target)); cmd.arg("--rustc-path").arg(builder.rustc(compiler)); - let is_rustdoc_ui = suite.ends_with("rustdoc-ui"); + let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js"); // Avoid depending on rustdoc when we don't need it. if mode == "rustdoc" || (mode == "run-make" && suite.ends_with("fulldeps")) - || (mode == "ui" && is_rustdoc_ui) + || (mode == "ui" && is_rustdoc) + || mode == "js-doc-test" { cmd.arg("--rustdoc-path") .arg(builder.rustdoc(compiler.host)); @@ -1109,12 +1073,12 @@ impl Step for Compiletest { cmd.arg("--nodejs").arg(nodejs); } - let mut flags = if is_rustdoc_ui { + let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] }; - if !is_rustdoc_ui { + if !is_rustdoc { if builder.config.rust_optimize_tests { flags.push("-O".to_string()); } diff --git a/src/test/rustdoc-js/basic.rs b/src/test/rustdoc-js/basic.rs index 4a835673a596b..1b4963fcebea8 100644 --- a/src/test/rustdoc-js/basic.rs +++ b/src/test/rustdoc-js/basic.rs @@ -1 +1,2 @@ +/// Foo pub struct Foo; diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 6b3117a1f74f4..f0991c8cdb547 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -24,6 +24,7 @@ pub enum Mode { Incremental, RunMake, Ui, + JsDocTest, MirOpt, } @@ -59,6 +60,7 @@ impl FromStr for Mode { "incremental" => Ok(Incremental), "run-make" => Ok(RunMake), "ui" => Ok(Ui), + "js-doc-test" => Ok(JsDocTest), "mir-opt" => Ok(MirOpt), _ => Err(()), } @@ -82,6 +84,7 @@ impl fmt::Display for Mode { Incremental => "incremental", RunMake => "run-make", Ui => "ui", + JsDocTest => "js-doc-test", MirOpt => "mir-opt", }; fmt::Display::fmt(s, f) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index bac41a7c57904..f7c02e831a9aa 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -4,7 +4,7 @@ use crate::common::{output_base_dir, output_base_name, output_testname_unique}; use crate::common::{Codegen, CodegenUnits, DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Rustdoc}; use crate::common::{CompileFail, Pretty, RunFail, RunPass, RunPassValgrind}; use crate::common::{Config, TestPaths}; -use crate::common::{Incremental, MirOpt, RunMake, Ui}; +use crate::common::{Incremental, MirOpt, RunMake, Ui, JsDocTest}; use diff; use crate::errors::{self, Error, ErrorKind}; use filetime::FileTime; @@ -275,6 +275,7 @@ impl<'test> TestCx<'test> { RunMake => self.run_rmake_test(), RunPass | Ui => self.run_ui_test(), MirOpt => self.run_mir_opt_test(), + JsDocTest => self.run_js_doc_test(), } } @@ -290,7 +291,7 @@ impl<'test> TestCx<'test> { fn should_compile_successfully(&self) -> bool { match self.config.mode { CompileFail => self.props.compile_pass, - RunPass => true, + RunPass | JsDocTest => true, Ui => self.props.compile_pass, Incremental => { let revision = self.revision @@ -1712,7 +1713,8 @@ impl<'test> TestCx<'test> { } fn make_compile_args(&self, input_file: &Path, output_file: TargetLocation) -> Command { - let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui"); + let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui") || + self.config.src_base.ends_with("rustdoc-js"); let mut rustc = if !is_rustdoc { Command::new(&self.config.rustc_path) } else { @@ -1802,7 +1804,7 @@ impl<'test> TestCx<'test> { rustc.arg(dir_opt); } RunFail | RunPassValgrind | Pretty | DebugInfoBoth | DebugInfoGdb | DebugInfoLldb - | Codegen | Rustdoc | RunMake | CodegenUnits => { + | Codegen | Rustdoc | RunMake | CodegenUnits | JsDocTest => { // do not use JSON output } } @@ -2710,6 +2712,25 @@ impl<'test> TestCx<'test> { fs::remove_dir(path) } + fn run_js_doc_test(&self) { + if let Some(nodejs) = &self.config.nodejs { + let out_dir = self.output_base_dir(); + + self.document(&out_dir); + + let root = self.config.find_rust_src_root().unwrap(); + let res = self.cmd2procres( + Command::new(&nodejs) + .arg(root.join("src/tools/rustdoc-js/tester.js")) + .arg(out_dir.parent().expect("no parent")) + .arg(&self.testpaths.file.file_stem().expect("couldn't get file stem")), + ); + if !res.status.success() { + self.fatal_proc_rec("rustdoc-js test failed!", &res); + } + } + } + fn run_ui_test(&self) { // if the user specified a format in the ui test // print the output to the stderr file, otherwise extract From d6add90c64a27de32a63b933f8f03d0c53fca4d0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 6 Mar 2019 15:01:30 +0100 Subject: [PATCH 6/7] Improve code --- src/tools/compiletest/src/runtest.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f7c02e831a9aa..7781ce74f411e 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -291,7 +291,8 @@ impl<'test> TestCx<'test> { fn should_compile_successfully(&self) -> bool { match self.config.mode { CompileFail => self.props.compile_pass, - RunPass | JsDocTest => true, + RunPass => true, + JsDocTest => true, Ui => self.props.compile_pass, Incremental => { let revision = self.revision @@ -2728,6 +2729,8 @@ impl<'test> TestCx<'test> { if !res.status.success() { self.fatal_proc_rec("rustdoc-js test failed!", &res); } + } else { + self.fatal("no nodeJS"); } } From 37ab3dc5b3560792ae4eab0521e0c08bbbdd95d8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 10 Mar 2019 23:10:40 +0100 Subject: [PATCH 7/7] 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(); }