Skip to content

Commit 21a1573

Browse files
authored
Rollup merge of #148186 - notriddle:test-cci, r=GuillaumeGomez,jieyouxu
rustdoc-search: add an integration test for CCI Part of #130676
2 parents ff7909b + 978fd43 commit 21a1573

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

src/doc/rustc-dev-guide/src/rustdoc-internals/search.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,25 @@ const EXPECTED = [
521521
returned: [],
522522
},
523523
]
524-
```
524+
```
525+
526+
If the [`//@ revisions`] directive is used, the JS file will
527+
have access to a variable called `REVISION`.
528+
529+
```js
530+
const EXPECTED = [
531+
// This first test targets name-based search.
532+
{
533+
query: "constructor",
534+
others: REVISION === "has_constructor" ?
535+
[
536+
{ path: "constructor_search", name: "constructor" },
537+
] :
538+
[],
539+
in_args: [],
540+
returned: [],
541+
},
542+
];
543+
```
544+
545+
[`//@ revisions`]: ../tests/compiletest.md#revisions

src/tools/compiletest/src/runtest/js_doc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ impl TestCx<'_> {
1818
.arg("--crate-name")
1919
.arg(file_stem.replace("-", "_"))
2020
.arg("--test-file")
21-
.arg(self.testpaths.file.with_extension("js")),
21+
.arg(self.testpaths.file.with_extension("js"))
22+
.arg("--revision")
23+
.arg(self.revision.unwrap_or_default()),
2224
);
2325
if !res.status.success() {
2426
self.fatal_proc_rec("rustdoc-js test failed!", &res);

src/tools/rustdoc-js/tester.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ function hasCheck(content, checkName) {
364364
return content.startsWith(`const ${checkName}`) || content.includes(`\nconst ${checkName}`);
365365
}
366366

367-
async function runChecks(testFile, doSearch, parseQuery) {
367+
async function runChecks(testFile, doSearch, parseQuery, revision) {
368368
let checkExpected = false;
369369
let checkParsed = false;
370-
let testFileContent = readFile(testFile);
370+
let testFileContent = `const REVISION = "${revision}";\n${readFile(testFile)}`;
371371

372372
if (testFileContent.indexOf("FILTER_CRATE") !== -1) {
373373
testFileContent += "exports.FILTER_CRATE = FILTER_CRATE;";
@@ -548,13 +548,15 @@ function parseOptions(args) {
548548
"doc_folder": "",
549549
"test_folder": "",
550550
"test_file": [],
551+
"revision": "",
551552
};
552553
const correspondences = {
553554
"--resource-suffix": "resource_suffix",
554555
"--doc-folder": "doc_folder",
555556
"--test-folder": "test_folder",
556557
"--test-file": "test_file",
557558
"--crate-name": "crate_name",
559+
"--revision": "revision",
558560
};
559561

560562
for (let i = 0; i < args.length; ++i) {
@@ -611,15 +613,15 @@ async function main(argv) {
611613
if (opts["test_file"].length !== 0) {
612614
for (const file of opts["test_file"]) {
613615
process.stdout.write(`Testing ${file} ... `);
614-
errors += await runChecks(file, doSearch, parseAndSearch.parseQuery);
616+
errors += await runChecks(file, doSearch, parseAndSearch.parseQuery, opts.revision);
615617
}
616618
} else if (opts["test_folder"].length !== 0) {
617619
for (const file of fs.readdirSync(opts["test_folder"])) {
618620
if (!file.endsWith(".js")) {
619621
continue;
620622
}
621623
process.stdout.write(`Testing ${file} ... `);
622-
errors += await runChecks(path.join(opts["test_folder"], file), doSearch,
624+
errors += await runChecks(path.join(opts["test_folder"], file, ""), doSearch,
623625
parseAndSearch.parseQuery);
624626
}
625627
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ unique-doc-out-dir
2+
//@ doc-flags:--merge=none
3+
//@ doc-flags:--parts-out-dir=info/doc.parts/merged-dep
4+
//@ doc-flags:-Zunstable-options
5+
6+
pub struct Dep;

tests/rustdoc-js/merged-doc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const EXPECTED = [
2+
{
3+
'query': 'merged_doc::Doc',
4+
'others': [
5+
{ 'path': 'merged_doc', 'name': 'Doc' },
6+
],
7+
},
8+
{
9+
'query': 'merged_dep::Dep',
10+
'others': REVISION === "nomerge" ? [] :
11+
[
12+
{ 'path': 'merged_dep', 'name': 'Dep' },
13+
],
14+
},
15+
];

tests/rustdoc-js/merged-doc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ revisions: merge nomerge
2+
//@ aux-build:merged-dep.rs
3+
//@ build-aux-docs
4+
//@[merge] doc-flags:--merge=finalize
5+
//@[merge] doc-flags:--include-parts-dir=info/doc.parts/merged-dep
6+
//@[merge] doc-flags:-Zunstable-options
7+
8+
extern crate merged_dep;
9+
10+
pub struct Doc;

0 commit comments

Comments
 (0)