about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-04-30 20:38:12 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-05-02 13:57:53 +0200
commit5b86fa8282c6dc9d61c7f358f8cc2ea9c3a93330 (patch)
treedfe2a652d09bf3ae450718962c7165592e316fd9
parentb791eaa4480a8e3acffe3faad4de0462b8476aca (diff)
downloadrust-5b86fa8282c6dc9d61c7f358f8cc2ea9c3a93330.tar.gz
rust-5b86fa8282c6dc9d61c7f358f8cc2ea9c3a93330.zip
Add regression test for #140310
-rw-r--r--tests/rustdoc-ui/doctest/warn-main-not-called.rs22
-rw-r--r--tests/rustdoc-ui/doctest/warn-main-not-called.stderr14
-rw-r--r--tests/rustdoc-ui/doctest/warn-main-not-called.stdout7
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/rustdoc-ui/doctest/warn-main-not-called.rs b/tests/rustdoc-ui/doctest/warn-main-not-called.rs
new file mode 100644
index 00000000000..25d92e9cee9
--- /dev/null
+++ b/tests/rustdoc-ui/doctest/warn-main-not-called.rs
@@ -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() {}
+//! ```
diff --git a/tests/rustdoc-ui/doctest/warn-main-not-called.stderr b/tests/rustdoc-ui/doctest/warn-main-not-called.stderr
new file mode 100644
index 00000000000..3a079f47555
--- /dev/null
+++ b/tests/rustdoc-ui/doctest/warn-main-not-called.stderr
@@ -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
+
diff --git a/tests/rustdoc-ui/doctest/warn-main-not-called.stdout b/tests/rustdoc-ui/doctest/warn-main-not-called.stdout
new file mode 100644
index 00000000000..07cdddc7b94
--- /dev/null
+++ b/tests/rustdoc-ui/doctest/warn-main-not-called.stdout
@@ -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
+