Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 22 additions & 1 deletion src/doc/rustc-dev-guide/src/rustdoc-internals/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,25 @@ const EXPECTED = [
returned: [],
},
]
```
```

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
4 changes: 3 additions & 1 deletion src/tools/compiletest/src/runtest/js_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;";
Expand Down Expand Up @@ -548,13 +548,15 @@ function parseOptions(args) {
"doc_folder": "",
"test_folder": "",
"test_file": [],
"revision": "",
};
const correspondences = {
"--resource-suffix": "resource_suffix",
"--doc-folder": "doc_folder",
"--test-folder": "test_folder",
"--test-file": "test_file",
"--crate-name": "crate_name",
"--revision": "revision",
};

for (let i = 0; i < args.length; ++i) {
Expand Down Expand Up @@ -611,15 +613,15 @@ 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"])) {
if (!file.endsWith(".js")) {
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);
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/rustdoc-js/auxiliary/merged-dep.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions tests/rustdoc-js/merged-doc.js
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions tests/rustdoc-js/merged-doc.rs
Original file line number Diff line number Diff line change
@@ -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;
Loading