Skip to content

Commit e914a1a

Browse files
committed
Respect --error-format in rustdoc --test
1 parent 3d5f54a commit e914a1a

15 files changed

+52
-28
lines changed

src/librustdoc/doctest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
174174
crate_name: options.crate_name.clone(),
175175
remap_path_prefix: options.remap_path_prefix.clone(),
176176
unstable_opts: options.unstable_opts.clone(),
177+
error_format: options.error_format.clone(),
177178
..config::Options::default()
178179
};
179180

tests/rustdoc-ui/doctest/check-attr-test.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,39 @@
22

33
#![deny(rustdoc::invalid_codeblock_attributes)]
44

5+
//~vvv ERROR unknown attribute `compile-fail`
6+
//~| ERROR unknown attribute `compilefail`
7+
//~| ERROR unknown attribute `comPile_fail`
58
/// foo
69
///
710
/// ```compile-fail,compilefail,comPile_fail
811
/// boo
912
/// ```
1013
pub fn foo() {}
1114

15+
//~vvv ERROR unknown attribute `should-panic`
16+
//~| ERROR unknown attribute `shouldpanic`
17+
//~| ERROR unknown attribute `shOuld_panic`
1218
/// bar
1319
///
1420
/// ```should-panic,shouldpanic,shOuld_panic
1521
/// boo
1622
/// ```
1723
pub fn bar() {}
1824

25+
//~vvv ERROR unknown attribute `no-run`
26+
//~| ERROR unknown attribute `norun`
27+
//~| ERROR unknown attribute `nO_run`
1928
/// foobar
2029
///
2130
/// ```no-run,norun,nO_run
2231
/// boo
2332
/// ```
2433
pub fn foobar() {}
2534

35+
//~vvv ERROR unknown attribute `test-harness`
36+
//~| ERROR unknown attribute `testharness`
37+
//~| ERROR unknown attribute `tesT_harness`
2638
/// b
2739
///
2840
/// ```test-harness,testharness,tesT_harness

tests/rustdoc-ui/doctest/check-attr-test.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unknown attribute `compile-fail`
2-
--> $DIR/check-attr-test.rs:5:1
2+
--> $DIR/check-attr-test.rs:8:1
33
|
44
LL | / /// foo
55
LL | | ///
@@ -17,7 +17,7 @@ LL | #![deny(rustdoc::invalid_codeblock_attributes)]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

1919
error: unknown attribute `compilefail`
20-
--> $DIR/check-attr-test.rs:5:1
20+
--> $DIR/check-attr-test.rs:8:1
2121
|
2222
LL | / /// foo
2323
LL | | ///
@@ -30,7 +30,7 @@ LL | | /// ```
3030
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
3131

3232
error: unknown attribute `comPile_fail`
33-
--> $DIR/check-attr-test.rs:5:1
33+
--> $DIR/check-attr-test.rs:8:1
3434
|
3535
LL | / /// foo
3636
LL | | ///
@@ -43,7 +43,7 @@ LL | | /// ```
4343
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
4444

4545
error: unknown attribute `should-panic`
46-
--> $DIR/check-attr-test.rs:12:1
46+
--> $DIR/check-attr-test.rs:18:1
4747
|
4848
LL | / /// bar
4949
LL | | ///
@@ -56,7 +56,7 @@ LL | | /// ```
5656
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
5757

5858
error: unknown attribute `shouldpanic`
59-
--> $DIR/check-attr-test.rs:12:1
59+
--> $DIR/check-attr-test.rs:18:1
6060
|
6161
LL | / /// bar
6262
LL | | ///
@@ -69,7 +69,7 @@ LL | | /// ```
6969
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
7070

7171
error: unknown attribute `shOuld_panic`
72-
--> $DIR/check-attr-test.rs:12:1
72+
--> $DIR/check-attr-test.rs:18:1
7373
|
7474
LL | / /// bar
7575
LL | | ///
@@ -82,7 +82,7 @@ LL | | /// ```
8282
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
8383

8484
error: unknown attribute `no-run`
85-
--> $DIR/check-attr-test.rs:19:1
85+
--> $DIR/check-attr-test.rs:28:1
8686
|
8787
LL | / /// foobar
8888
LL | | ///
@@ -95,7 +95,7 @@ LL | | /// ```
9595
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
9696

9797
error: unknown attribute `norun`
98-
--> $DIR/check-attr-test.rs:19:1
98+
--> $DIR/check-attr-test.rs:28:1
9999
|
100100
LL | / /// foobar
101101
LL | | ///
@@ -108,7 +108,7 @@ LL | | /// ```
108108
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
109109

110110
error: unknown attribute `nO_run`
111-
--> $DIR/check-attr-test.rs:19:1
111+
--> $DIR/check-attr-test.rs:28:1
112112
|
113113
LL | / /// foobar
114114
LL | | ///
@@ -121,7 +121,7 @@ LL | | /// ```
121121
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
122122

123123
error: unknown attribute `test-harness`
124-
--> $DIR/check-attr-test.rs:26:1
124+
--> $DIR/check-attr-test.rs:38:1
125125
|
126126
LL | / /// b
127127
LL | | ///
@@ -134,7 +134,7 @@ LL | | /// ```
134134
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
135135

136136
error: unknown attribute `testharness`
137-
--> $DIR/check-attr-test.rs:26:1
137+
--> $DIR/check-attr-test.rs:38:1
138138
|
139139
LL | / /// b
140140
LL | | ///
@@ -147,7 +147,7 @@ LL | | /// ```
147147
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
148148

149149
error: unknown attribute `tesT_harness`
150-
--> $DIR/check-attr-test.rs:26:1
150+
--> $DIR/check-attr-test.rs:38:1
151151
|
152152
LL | / /// b
153153
LL | | ///

tests/rustdoc-ui/doctest/failed-doctest-extra-semicolon-on-item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/// <https://github.com/rust-lang/rust/issues/91014>
1010
///
1111
/// ```rust
12+
//~^ WARN the `main` function of this doctest won't be run
1213
/// struct S {};
1314
///
1415
/// fn main() {

tests/rustdoc-ui/doctest/main-alongside-stmts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
1515
//@ check-pass
1616

17+
//~v WARN the `main` function of this doctest won't be run
1718
//! ```
1819
//! # if cfg!(miri) { return; }
1920
//! use std::ops::Deref;
@@ -22,6 +23,7 @@
2223
//! assert!(false);
2324
//! }
2425
//! ```
26+
//~v WARN the `main` function of this doctest won't be run
2527
//!
2628
//! ```
2729
//! let x = 2;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function
2-
--> $DIR/main-alongside-stmts.rs:17:1
2+
--> $DIR/main-alongside-stmts.rs:18:1
33
|
44
LL | //! ```
55
| ^^^^^^^
66

77
warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function
8-
--> $DIR/main-alongside-stmts.rs:26:1
8+
--> $DIR/main-alongside-stmts.rs:27:1
99
|
10-
LL | //! ```
11-
| ^^^^^^^
10+
LL | //!
11+
| ^^^
1212

1313
warning: 2 warnings emitted
1414

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
running 2 tests
3-
test $DIR/main-alongside-stmts.rs - (line 17) ... ok
4-
test $DIR/main-alongside-stmts.rs - (line 26) ... ok
3+
test $DIR/main-alongside-stmts.rs - (line 18) ... ok
4+
test $DIR/main-alongside-stmts.rs - (line 27) ... ok
55

66
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
77

tests/rustdoc-ui/doctest/standalone-warning-2024.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#![deny(warnings)]
1010

1111
//! ```standalone
12+
//~^ ERROR unknown attribute `standalone`
13+
//~| ERROR unknown attribute `standalone-crate`
1214
//! bla
1315
//! ```
1416
//!

tests/rustdoc-ui/doctest/standalone-warning-2024.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ error: unknown attribute `standalone`
22
--> $DIR/standalone-warning-2024.rs:11:1
33
|
44
LL | / //! ```standalone
5+
LL | |
6+
LL | |
57
LL | | //! bla
6-
LL | | //! ```
7-
LL | | //!
8-
LL | | //! ```standalone-crate
8+
... |
99
LL | | //! bla
1010
LL | | //! ```
1111
| |_______^
@@ -23,10 +23,10 @@ error: unknown attribute `standalone-crate`
2323
--> $DIR/standalone-warning-2024.rs:11:1
2424
|
2525
LL | / //! ```standalone
26+
LL | |
27+
LL | |
2628
LL | | //! bla
27-
LL | | //! ```
28-
LL | | //!
29-
LL | | //! ```standalone-crate
29+
... |
3030
LL | | //! bla
3131
LL | | //! ```
3232
| |_______^

tests/rustdoc-ui/doctest/test-compile-fail1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
pub fn f() {}
77

88
pub fn f() {}
9+
//~^ ERROR the name `f` is defined multiple times

0 commit comments

Comments
 (0)