rustdoc-search: add an integration test for CCI
Part of https://github.com/rust-lang/rust/issues/130676
This commit is contained in:
@@ -522,3 +522,24 @@ const EXPECTED = [
|
||||
},
|
||||
]
|
||||
```
|
||||
|
||||
If the [`//@ revisions`] directive is used, the JS file will
|
||||
have access to a variable called `REVISION`.
|
||||
|
||||
```js
|
||||
const EXPECTED = [
|
||||
// This first test targets name-based search.
|
||||
{
|
||||
query: "constructor",
|
||||
others: REVISION === "has_constructor" ?
|
||||
[
|
||||
{ path: "constructor_search", name: "constructor" },
|
||||
] :
|
||||
[],
|
||||
in_args: [],
|
||||
returned: [],
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
[`//@ revisions`]: ../tests/compiletest.md#revisions
|
||||
|
||||
@@ -18,7 +18,9 @@ impl TestCx<'_> {
|
||||
.arg("--crate-name")
|
||||
.arg(file_stem.replace("-", "_"))
|
||||
.arg("--test-file")
|
||||
.arg(self.testpaths.file.with_extension("js")),
|
||||
.arg(self.testpaths.file.with_extension("js"))
|
||||
.arg("--revision")
|
||||
.arg(self.revision.unwrap_or_default()),
|
||||
);
|
||||
if !res.status.success() {
|
||||
self.fatal_proc_rec("rustdoc-js test failed!", &res);
|
||||
|
||||
@@ -364,10 +364,10 @@ function hasCheck(content, checkName) {
|
||||
return content.startsWith(`const ${checkName}`) || content.includes(`\nconst ${checkName}`);
|
||||
}
|
||||
|
||||
async function runChecks(testFile, doSearch, parseQuery) {
|
||||
async function runChecks(testFile, doSearch, parseQuery, revision) {
|
||||
let checkExpected = false;
|
||||
let checkParsed = false;
|
||||
let testFileContent = readFile(testFile);
|
||||
let testFileContent = `const REVISION = "${revision}";\n${readFile(testFile)}`;
|
||||
|
||||
if (testFileContent.indexOf("FILTER_CRATE") !== -1) {
|
||||
testFileContent += "exports.FILTER_CRATE = FILTER_CRATE;";
|
||||
@@ -548,6 +548,7 @@ function parseOptions(args) {
|
||||
"doc_folder": "",
|
||||
"test_folder": "",
|
||||
"test_file": [],
|
||||
"revision": "",
|
||||
};
|
||||
const correspondences = {
|
||||
"--resource-suffix": "resource_suffix",
|
||||
@@ -555,6 +556,7 @@ function parseOptions(args) {
|
||||
"--test-folder": "test_folder",
|
||||
"--test-file": "test_file",
|
||||
"--crate-name": "crate_name",
|
||||
"--revision": "revision",
|
||||
};
|
||||
|
||||
for (let i = 0; i < args.length; ++i) {
|
||||
@@ -611,7 +613,7 @@ async function main(argv) {
|
||||
if (opts["test_file"].length !== 0) {
|
||||
for (const file of opts["test_file"]) {
|
||||
process.stdout.write(`Testing ${file} ... `);
|
||||
errors += await runChecks(file, doSearch, parseAndSearch.parseQuery);
|
||||
errors += await runChecks(file, doSearch, parseAndSearch.parseQuery, opts.revision);
|
||||
}
|
||||
} else if (opts["test_folder"].length !== 0) {
|
||||
for (const file of fs.readdirSync(opts["test_folder"])) {
|
||||
@@ -619,7 +621,7 @@ async function main(argv) {
|
||||
continue;
|
||||
}
|
||||
process.stdout.write(`Testing ${file} ... `);
|
||||
errors += await runChecks(path.join(opts["test_folder"], file), doSearch,
|
||||
errors += await runChecks(path.join(opts["test_folder"], file, ""), doSearch,
|
||||
parseAndSearch.parseQuery);
|
||||
}
|
||||
}
|
||||
|
||||
6
tests/rustdoc-js/auxiliary/merged-dep.rs
Normal file
6
tests/rustdoc-js/auxiliary/merged-dep.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
//@ unique-doc-out-dir
|
||||
//@ doc-flags:--merge=none
|
||||
//@ doc-flags:--parts-out-dir=info/doc.parts/merged-dep
|
||||
//@ doc-flags:-Zunstable-options
|
||||
|
||||
pub struct Dep;
|
||||
15
tests/rustdoc-js/merged-doc.js
Normal file
15
tests/rustdoc-js/merged-doc.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const EXPECTED = [
|
||||
{
|
||||
'query': 'merged_doc::Doc',
|
||||
'others': [
|
||||
{ 'path': 'merged_doc', 'name': 'Doc' },
|
||||
],
|
||||
},
|
||||
{
|
||||
'query': 'merged_dep::Dep',
|
||||
'others': REVISION === "nomerge" ? [] :
|
||||
[
|
||||
{ 'path': 'merged_dep', 'name': 'Dep' },
|
||||
],
|
||||
},
|
||||
];
|
||||
10
tests/rustdoc-js/merged-doc.rs
Normal file
10
tests/rustdoc-js/merged-doc.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
//@ revisions: merge nomerge
|
||||
//@ aux-build:merged-dep.rs
|
||||
//@ build-aux-docs
|
||||
//@[merge] doc-flags:--merge=finalize
|
||||
//@[merge] doc-flags:--include-parts-dir=info/doc.parts/merged-dep
|
||||
//@[merge] doc-flags:-Zunstable-options
|
||||
|
||||
extern crate merged_dep;
|
||||
|
||||
pub struct Doc;
|
||||
Reference in New Issue
Block a user