Add regression test for #140310

This commit is contained in:
Guillaume Gomez
2025-04-30 20:38:12 +02:00
parent b791eaa448
commit 5b86fa8282
3 changed files with 43 additions and 0 deletions
@@ -0,0 +1,22 @@
//@ check-pass
//@ compile-flags:--test --test-args --test-threads=1
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
// In case there is a `main` function in the doctest alongside expressions,
// the whole doctest will be wrapped into a function and the `main` function
// won't be called.
//! ```
//! macro_rules! bla {
//! ($($x:tt)*) => {}
//! }
//!
//! let x = 12;
//! bla!(fn main ());
//! ```
//!
//! ```
//! let x = 12;
//! fn main() {}
//! ```
@@ -0,0 +1,14 @@
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
--> $DIR/warn-main-not-called.rs:10:1
|
10 | //! ```
| ^^^^^^^
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
--> $DIR/warn-main-not-called.rs:19:1
|
19 | //! ```
| ^^^^^^^
warning: 2 warnings emitted
@@ -0,0 +1,7 @@
running 2 tests
test $DIR/warn-main-not-called.rs - (line 10) ... ok
test $DIR/warn-main-not-called.rs - (line 19) ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME