about summary refs log tree commit diff
diff options
context:
space:
mode:
-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
+