Skip to content

Commit 1fcce48

Browse files
Add rustdoc-js tester should-fail option
1 parent e28502e commit 1fcce48

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/test/rustdoc-js/keyword.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-order
12+
13+
const QUERY = 'fn';
14+
15+
const EXPECTED = {
16+
'others': [
17+
{ 'path': 'std', 'name': 'fn', ty: 15 }, // 15 is for primitive types
18+
{ 'path': 'std', 'name': 'fn', ty: 21 }, // 21 is for keywords
19+
],
20+
};

src/test/rustdoc-js/should-fail.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// should-fail
12+
13+
const QUERY = 'fn';
14+
15+
const EXPECTED = {
16+
'others': [
17+
{ 'path': 'std', 'name': 'fn', ty: 14 },
18+
],
19+
};

src/tools/rustdoc-js/tester.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ function loadContent(content) {
164164
m._compile(content, "tmp.js");
165165
m.exports.ignore_order = content.indexOf("\n// ignore-order\n") !== -1;
166166
m.exports.exact_check = content.indexOf("\n// exact-check\n") !== -1;
167+
m.exports.should_fail = content.indexOf("\n// should-fail\n") !== -1;
167168
return m.exports;
168169
}
169170

@@ -259,6 +260,7 @@ function main(argv) {
259260
const query = loadedFile.QUERY;
260261
const ignore_order = loadedFile.ignore_order;
261262
const exact_check = loadedFile.exact_check;
263+
const should_fail = loadedFile.should_fail;
262264
var results = loaded.execSearch(loaded.getQuery(query), index);
263265
process.stdout.write('Checking "' + file + '" ... ');
264266
var error_text = [];
@@ -289,7 +291,11 @@ function main(argv) {
289291
}
290292
}
291293
}
292-
if (error_text.length !== 0) {
294+
if (error_text.length === 0 && should_fail === true) {
295+
errors += 1;
296+
console.error("FAILED");
297+
console.error("==> Test was supposed to fail but all items were found...");
298+
} else if (error_text.length !== 0 && should_fail === false) {
293299
errors += 1;
294300
console.error("FAILED");
295301
console.error(error_text.join("\n"));

0 commit comments

Comments
 (0)