Skip to content

Commit aa3ca32

Browse files
Rename rustdoc js test suites
1 parent 834347d commit aa3ca32

27 files changed

+93
-100
lines changed

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'a> Builder<'a> {
405405
test::Miri,
406406
test::Clippy,
407407
test::CompiletestTest,
408-
test::RustdocJS,
408+
test::RustdocJSStd,
409409
test::RustdocJSNotStd,
410410
test::RustdocTheme,
411411
// Run bootstrap close to the end as it's unlikely to fail

src/bootstrap/test.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -574,22 +574,22 @@ impl Step for RustdocTheme {
574574
}
575575

576576
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
577-
pub struct RustdocJS {
577+
pub struct RustdocJSStd {
578578
pub host: Interned<String>,
579579
pub target: Interned<String>,
580580
}
581581

582-
impl Step for RustdocJS {
582+
impl Step for RustdocJSStd {
583583
type Output = ();
584584
const DEFAULT: bool = true;
585585
const ONLY_HOSTS: bool = true;
586586

587587
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
588-
run.path("src/test/rustdoc-js")
588+
run.path("src/test/rustdoc-js-std")
589589
}
590590

591591
fn make_run(run: RunConfig<'_>) {
592-
run.builder.ensure(RustdocJS {
592+
run.builder.ensure(RustdocJSStd {
593593
host: run.host,
594594
target: run.target,
595595
});
@@ -598,15 +598,15 @@ impl Step for RustdocJS {
598598
fn run(self, builder: &Builder<'_>) {
599599
if let Some(ref nodejs) = builder.config.nodejs {
600600
let mut command = Command::new(nodejs);
601-
command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
601+
command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]);
602602
builder.ensure(crate::doc::Std {
603603
target: self.target,
604604
stage: builder.top_stage,
605605
});
606606
builder.run(&mut command);
607607
} else {
608608
builder.info(
609-
"No nodejs found, skipping \"src/test/rustdoc-js\" tests"
609+
"No nodejs found, skipping \"src/test/rustdoc-js-std\" tests"
610610
);
611611
}
612612
}
@@ -625,7 +625,7 @@ impl Step for RustdocJSNotStd {
625625
const ONLY_HOSTS: bool = true;
626626

627627
fn should_run(run: ShouldRun) -> ShouldRun {
628-
run.path("src/test/rustdoc-js-not-std")
628+
run.path("src/test/rustdoc-js")
629629
}
630630

631631
fn make_run(run: RunConfig) {
@@ -640,7 +640,7 @@ impl Step for RustdocJSNotStd {
640640
fn run(self, builder: &Builder) {
641641
if let Some(ref nodejs) = builder.config.nodejs {
642642
let mut command = Command::new(nodejs);
643-
command.args(&["src/tools/rustdoc-js-not-std/tester.js",
643+
command.args(&["src/tools/rustdoc-js/tester.js",
644644
&*self.host,
645645
builder.top_stage.to_string().as_str()]);
646646
builder.ensure(crate::doc::Std {
@@ -650,7 +650,7 @@ impl Step for RustdocJSNotStd {
650650
builder.run(&mut command);
651651
} else {
652652
builder.info(
653-
"No nodejs found, skipping \"src/test/rustdoc-js-not-std\" tests"
653+
"No nodejs found, skipping \"src/test/rustdoc-js\" tests"
654654
);
655655
}
656656
}

src/test/rustdoc-js-not-std/basic.js

-7
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/test/rustdoc-js-std/basic.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const QUERY = 'String';
2+
3+
const EXPECTED = {
4+
'others': [
5+
{ 'path': 'std::string', 'name': 'String' },
6+
{ 'path': 'std::ffi', 'name': 'CString' },
7+
{ 'path': 'std::ffi', 'name': 'OsString' },
8+
],
9+
'in_args': [
10+
{ 'path': 'std::str', 'name': 'eq' },
11+
],
12+
'returned': [
13+
{ 'path': 'std::string::String', 'name': 'add' },
14+
],
15+
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/test/rustdoc-js/basic.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
const QUERY = 'String';
1+
const QUERY = 'Fo';
22

33
const EXPECTED = {
44
'others': [
5-
{ 'path': 'std::string', 'name': 'String' },
6-
{ 'path': 'std::ffi', 'name': 'CString' },
7-
{ 'path': 'std::ffi', 'name': 'OsString' },
8-
],
9-
'in_args': [
10-
{ 'path': 'std::str', 'name': 'eq' },
11-
],
12-
'returned': [
13-
{ 'path': 'std::string::String', 'name': 'add' },
5+
{ 'path': 'basic', 'name': 'Foo' },
146
],
157
};
File renamed without changes.

src/tools/rustdoc-js-not-std/tester.js renamed to src/tools/rustdoc-js-std/tester.js

+13-61
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require('fs');
2-
const { spawnSync } = require('child_process');
32

4-
const TEST_FOLDER = 'src/test/rustdoc-js-not-std/';
3+
const TEST_FOLDER = 'src/test/rustdoc-js-std/';
54

65
function getNextStep(content, pos, stop) {
76
while (pos < content.length && content[pos] !== stop &&
@@ -220,27 +219,17 @@ function lookForEntry(entry, data) {
220219
return null;
221220
}
222221

223-
function remove_docs(out_dir) {
224-
spawnSync('rm', ['-rf', out_dir]);
225-
}
226-
227-
function build_docs(out_dir, rustdoc_path, file_to_document) {
228-
remove_docs(out_dir);
229-
var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]);
230-
var s = '';
231-
if (c.error || c.stderr.length > 0) {
232-
if (c.stderr.length > 0) {
233-
s += '==> STDERR: ' + c.stderr + '\n';
234-
}
235-
s += '==> ERROR: ' + c.error;
222+
function main(argv) {
223+
if (argv.length !== 3) {
224+
console.error("Expected toolchain to check as argument (for example \
225+
'x86_64-apple-darwin')");
226+
return 1;
236227
}
237-
return s;
238-
}
228+
var toolchain = argv[2];
239229

240-
function load_files(out_folder, crate) {
241-
var mainJs = readFile(out_folder + "/main.js");
242-
var ALIASES = readFile(out_folder + "/aliases.js");
243-
var searchIndex = readFile(out_folder + "/search-index.js").split("\n");
230+
var mainJs = readFile("build/" + toolchain + "/doc/main.js");
231+
var ALIASES = readFile("build/" + toolchain + "/doc/aliases.js");
232+
var searchIndex = readFile("build/" + toolchain + "/doc/search-index.js").split("\n");
244233
if (searchIndex[searchIndex.length - 1].length === 0) {
245234
searchIndex.pop();
246235
}
@@ -259,55 +248,19 @@ function load_files(out_folder, crate) {
259248
var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult",
260249
"getQuery", "buildIndex", "execQuery", "execSearch"];
261250

262-
finalJS += 'window = { "currentCrate": "' + crate + '" };\n';
251+
finalJS += 'window = { "currentCrate": "std" };\n';
263252
finalJS += 'var rootPath = "../";\n';
264253
finalJS += ALIASES;
265254
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs);
266255
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs);
267256
finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs);
268257

269258
var loaded = loadContent(finalJS);
270-
return [loaded, loaded.buildIndex(searchIndex.searchIndex)];
271-
}
272-
273-
function main(argv) {
274-
if (argv.length !== 4) {
275-
console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]");
276-
return 1;
277-
}
278-
const toolchain = argv[2];
279-
const stage = argv[3];
280-
const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc';
259+
var index = loaded.buildIndex(searchIndex.searchIndex);
281260

282261
var errors = 0;
283262

284263
fs.readdirSync(TEST_FOLDER).forEach(function(file) {
285-
if (!file.endsWith('.js')) {
286-
return;
287-
}
288-
var test_name = file.substring(0, file.length - 3);
289-
process.stdout.write('Checking "' + test_name + '" ... ');
290-
var rust_file = TEST_FOLDER + test_name + '.rs';
291-
292-
if (!fs.existsSync(rust_file)) {
293-
console.error("FAILED");
294-
console.error("==> Missing '" + test_name + ".rs' file...");
295-
errors += 1;
296-
return;
297-
}
298-
299-
var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js-not-std/" +
300-
test_name;
301-
302-
var ret = build_docs(out_folder, rustdoc_path, rust_file);
303-
if (ret.length > 0) {
304-
console.error("FAILED");
305-
console.error(ret);
306-
errors += 1;
307-
return;
308-
}
309-
310-
var [loaded, index] = load_files(out_folder, test_name);
311264
var loadedFile = loadContent(readFile(TEST_FOLDER + file) +
312265
'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');
313266
const expected = loadedFile.EXPECTED;
@@ -317,6 +270,7 @@ function main(argv) {
317270
const exact_check = loadedFile.exact_check;
318271
const should_fail = loadedFile.should_fail;
319272
var results = loaded.execSearch(loaded.getQuery(query), index);
273+
process.stdout.write('Checking "' + file + '" ... ');
320274
var error_text = [];
321275
for (var key in expected) {
322276
if (!expected.hasOwnProperty(key)) {
@@ -354,8 +308,6 @@ function main(argv) {
354308
console.error("FAILED");
355309
console.error(error_text.join("\n"));
356310
} else {
357-
// In this case, we remove the docs, no need to keep them around.
358-
remove_docs(out_folder);
359311
console.log("OK");
360312
}
361313
});

src/tools/rustdoc-js/tester.js

+53-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require('fs');
2+
const { spawnSync } = require('child_process');
23

34
const TEST_FOLDER = 'src/test/rustdoc-js/';
45

@@ -219,17 +220,22 @@ function lookForEntry(entry, data) {
219220
return null;
220221
}
221222

222-
function main(argv) {
223-
if (argv.length !== 3) {
224-
console.error("Expected toolchain to check as argument (for example \
225-
'x86_64-apple-darwin')");
226-
return 1;
223+
function build_docs(out_dir, rustdoc_path, file_to_document) {
224+
var c = spawnSync(rustdoc_path, [file_to_document, '-o', out_dir]);
225+
var s = '';
226+
if (c.error || c.stderr.length > 0) {
227+
if (c.stderr.length > 0) {
228+
s += '==> STDERR: ' + c.stderr + '\n';
229+
}
230+
s += '==> ERROR: ' + c.error;
227231
}
228-
var toolchain = argv[2];
232+
return s;
233+
}
229234

230-
var mainJs = readFile("build/" + toolchain + "/doc/main.js");
231-
var ALIASES = readFile("build/" + toolchain + "/doc/aliases.js");
232-
var searchIndex = readFile("build/" + toolchain + "/doc/search-index.js").split("\n");
235+
function load_files(out_folder, crate) {
236+
var mainJs = readFile(out_folder + "/main.js");
237+
var ALIASES = readFile(out_folder + "/aliases.js");
238+
var searchIndex = readFile(out_folder + "/search-index.js").split("\n");
233239
if (searchIndex[searchIndex.length - 1].length === 0) {
234240
searchIndex.pop();
235241
}
@@ -248,19 +254,55 @@ function main(argv) {
248254
var functionsToLoad = ["buildHrefAndPath", "pathSplitter", "levenshtein", "validateResult",
249255
"getQuery", "buildIndex", "execQuery", "execSearch"];
250256

251-
finalJS += 'window = { "currentCrate": "std" };\n';
257+
finalJS += 'window = { "currentCrate": "' + crate + '" };\n';
252258
finalJS += 'var rootPath = "../";\n';
253259
finalJS += ALIASES;
254260
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs);
255261
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs);
256262
finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs);
257263

258264
var loaded = loadContent(finalJS);
259-
var index = loaded.buildIndex(searchIndex.searchIndex);
265+
return [loaded, loaded.buildIndex(searchIndex.searchIndex)];
266+
}
267+
268+
function main(argv) {
269+
if (argv.length !== 4) {
270+
console.error("USAGE: node tester.js [TOOLCHAIN] [STAGE]");
271+
return 1;
272+
}
273+
const toolchain = argv[2];
274+
const stage = argv[3];
275+
const rustdoc_path = './build/' + toolchain + '/stage' + stage + '/bin/rustdoc';
260276

261277
var errors = 0;
262278

263279
fs.readdirSync(TEST_FOLDER).forEach(function(file) {
280+
if (!file.endsWith('.js')) {
281+
return;
282+
}
283+
var test_name = file.substring(0, file.length - 3);
284+
process.stdout.write('Checking "' + test_name + '" ... ');
285+
var rust_file = TEST_FOLDER + test_name + '.rs';
286+
287+
if (!fs.existsSync(rust_file)) {
288+
console.error("FAILED");
289+
console.error("==> Missing '" + test_name + ".rs' file...");
290+
errors += 1;
291+
return;
292+
}
293+
294+
var out_folder = "build/" + toolchain + "/stage" + stage + "/tests/rustdoc-js/" +
295+
test_name;
296+
297+
var ret = build_docs(out_folder, rustdoc_path, rust_file);
298+
if (ret.length > 0) {
299+
console.error("FAILED");
300+
console.error(ret);
301+
errors += 1;
302+
return;
303+
}
304+
305+
var [loaded, index] = load_files(out_folder, test_name);
264306
var loadedFile = loadContent(readFile(TEST_FOLDER + file) +
265307
'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');
266308
const expected = loadedFile.EXPECTED;
@@ -270,7 +312,6 @@ function main(argv) {
270312
const exact_check = loadedFile.exact_check;
271313
const should_fail = loadedFile.should_fail;
272314
var results = loaded.execSearch(loaded.getQuery(query), index);
273-
process.stdout.write('Checking "' + file + '" ... ');
274315
var error_text = [];
275316
for (var key in expected) {
276317
if (!expected.hasOwnProperty(key)) {

0 commit comments

Comments
 (0)