summaryrefslogtreecommitdiffstats
path: root/tests/rustdoc/doctest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /tests/rustdoc/doctest
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/rustdoc/doctest')
-rw-r--r--tests/rustdoc/doctest/auxiliary/empty.rs1
-rw-r--r--tests/rustdoc/doctest/doctest-cfg-feature-30252.rs9
-rw-r--r--tests/rustdoc/doctest/doctest-crate-attributes-38129.rs99
-rw-r--r--tests/rustdoc/doctest/doctest-hide-empty-line-23106.rs10
-rw-r--r--tests/rustdoc/doctest/doctest-ignore-32556.rs8
-rw-r--r--tests/rustdoc/doctest/doctest-include-43153.rs12
-rw-r--r--tests/rustdoc/doctest/doctest-macro-38219.rs10
-rw-r--r--tests/rustdoc/doctest/doctest-manual-crate-name.rs7
-rw-r--r--tests/rustdoc/doctest/doctest-markdown-inline-parse-23744.rs15
-rw-r--r--tests/rustdoc/doctest/doctest-markdown-trailing-docblock-48377.rs15
-rw-r--r--tests/rustdoc/doctest/doctest-multi-line-string-literal-25944.rs14
11 files changed, 200 insertions, 0 deletions
diff --git a/tests/rustdoc/doctest/auxiliary/empty.rs b/tests/rustdoc/doctest/auxiliary/empty.rs
new file mode 100644
index 000000000..d11c69f81
--- /dev/null
+++ b/tests/rustdoc/doctest/auxiliary/empty.rs
@@ -0,0 +1 @@
+// intentionally empty
diff --git a/tests/rustdoc/doctest/doctest-cfg-feature-30252.rs b/tests/rustdoc/doctest/doctest-cfg-feature-30252.rs
new file mode 100644
index 000000000..ceb8076fe
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-cfg-feature-30252.rs
@@ -0,0 +1,9 @@
+// compile-flags:--test --cfg feature="bar"
+
+// https://github.com/rust-lang/rust/issues/30252
+#![crate_name="issue_30252"]
+
+/// ```rust
+/// assert_eq!(cfg!(feature = "bar"), true);
+/// ```
+pub fn foo() {}
diff --git a/tests/rustdoc/doctest/doctest-crate-attributes-38129.rs b/tests/rustdoc/doctest/doctest-crate-attributes-38129.rs
new file mode 100644
index 000000000..156d50fa5
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-crate-attributes-38129.rs
@@ -0,0 +1,99 @@
+// compile-flags:--test
+
+// This file tests the source-partitioning behavior of rustdoc.
+// Each test contains some code that should be put into the generated
+// `fn main` and some attributes should be left outside (except the first
+// one, which has no attributes).
+// If the #![recursion_limit] attribute is incorrectly left inside,
+// then the tests will fail because the macro recurses 128 times.
+
+/// ```
+/// assert_eq!(1 + 1, 2);
+/// ```
+pub fn simple() {}
+
+/// ```
+/// #![recursion_limit = "1024"]
+/// macro_rules! recurse {
+/// (()) => {};
+/// (() $($rest:tt)*) => { recurse!($($rest)*); }
+/// }
+/// recurse!(() () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ());
+/// assert_eq!(1 + 1, 2);
+/// ```
+pub fn non_feature_attr() {}
+
+/// ```
+/// #![feature(core_intrinsics)]
+/// assert_eq!(1 + 1, 2);
+/// ```
+pub fn feature_attr() {}
+
+/// ```
+/// #![feature(core_intrinsics)]
+/// #![recursion_limit = "1024"]
+/// macro_rules! recurse {
+/// (()) => {};
+/// (() $($rest:tt)*) => { recurse!($($rest)*); }
+/// }
+/// recurse!(() () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ());
+/// assert_eq!(1 + 1, 2);
+/// ```
+pub fn both_attrs() {}
+
+/// ```
+/// #![recursion_limit = "1024"]
+/// #![feature(core_intrinsics)]
+/// macro_rules! recurse {
+/// (()) => {};
+/// (() $($rest:tt)*) => { recurse!($($rest)*); }
+/// }
+/// recurse!(() () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ()
+/// () () () () () () () ());
+/// assert_eq!(1 + 1, 2);
+/// ```
+pub fn both_attrs_reverse() {}
diff --git a/tests/rustdoc/doctest/doctest-hide-empty-line-23106.rs b/tests/rustdoc/doctest/doctest-hide-empty-line-23106.rs
new file mode 100644
index 000000000..8e1e2cf09
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-hide-empty-line-23106.rs
@@ -0,0 +1,10 @@
+// compile-flags:--test
+
+// https://github.com/rust-lang/rust/issues/23106
+#![crate_name="issue_23106"]
+
+/// ```
+/// #
+/// ```
+pub fn main() {
+}
diff --git a/tests/rustdoc/doctest/doctest-ignore-32556.rs b/tests/rustdoc/doctest/doctest-ignore-32556.rs
new file mode 100644
index 000000000..99da9358b
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-ignore-32556.rs
@@ -0,0 +1,8 @@
+// https://github.com/rust-lang/rust/issues/32556
+#![crate_name="issue_32556"]
+
+/// Blah blah blah
+/// ```ignore (testing rustdoc's handling of ignore)
+/// bad_assert!();
+/// ```
+pub fn foo() {}
diff --git a/tests/rustdoc/doctest/doctest-include-43153.rs b/tests/rustdoc/doctest/doctest-include-43153.rs
new file mode 100644
index 000000000..ec21a68c4
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-include-43153.rs
@@ -0,0 +1,12 @@
+// https://github.com/rust-lang/rust/issues/43153
+
+// Test that `include!` in a doc test searches relative to the directory in
+// which the test is declared.
+
+// compile-flags:--test
+
+/// ```rust
+/// include!("auxiliary/empty.rs");
+/// fn main() {}
+/// ```
+pub struct Foo;
diff --git a/tests/rustdoc/doctest/doctest-macro-38219.rs b/tests/rustdoc/doctest/doctest-macro-38219.rs
new file mode 100644
index 000000000..6c81df110
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-macro-38219.rs
@@ -0,0 +1,10 @@
+// https://github.com/rust-lang/rust/issues/38219
+
+// compile-flags:--test
+// should-fail
+
+/// ```
+/// fail
+/// ```
+#[macro_export]
+macro_rules! foo { () => {} }
diff --git a/tests/rustdoc/doctest/doctest-manual-crate-name.rs b/tests/rustdoc/doctest/doctest-manual-crate-name.rs
new file mode 100644
index 000000000..3a5e3734e
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-manual-crate-name.rs
@@ -0,0 +1,7 @@
+// compile-flags:--test
+
+//! ```
+//! #![crate_name="asdf"]
+//!
+//! println!("yo");
+//! ```
diff --git a/tests/rustdoc/doctest/doctest-markdown-inline-parse-23744.rs b/tests/rustdoc/doctest/doctest-markdown-inline-parse-23744.rs
new file mode 100644
index 000000000..128e2daba
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-markdown-inline-parse-23744.rs
@@ -0,0 +1,15 @@
+// compile-flags:--test
+
+// https://github.com/rust-lang/rust/issues/23744
+#![crate_name="issue_23744"]
+
+/// Example of rustdoc incorrectly parsing <code>```rust,should_panic</code>.
+///
+/// ```should_panic
+/// fn main() { panic!("fee"); }
+/// ```
+///
+/// ```rust,should_panic
+/// fn main() { panic!("fum"); }
+/// ```
+pub fn foo() {}
diff --git a/tests/rustdoc/doctest/doctest-markdown-trailing-docblock-48377.rs b/tests/rustdoc/doctest/doctest-markdown-trailing-docblock-48377.rs
new file mode 100644
index 000000000..d481dc0dd
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-markdown-trailing-docblock-48377.rs
@@ -0,0 +1,15 @@
+// compile-flags:--test
+
+// https://github.com/rust-lang/rust/issues/48377
+
+//! This is a doc comment
+//!
+//! ```rust
+//! fn main() {}
+//! ```
+//!
+//! With a trailing code fence
+//! ```
+
+/// Some foo function
+pub fn foo() {}
diff --git a/tests/rustdoc/doctest/doctest-multi-line-string-literal-25944.rs b/tests/rustdoc/doctest/doctest-multi-line-string-literal-25944.rs
new file mode 100644
index 000000000..eec796e4f
--- /dev/null
+++ b/tests/rustdoc/doctest/doctest-multi-line-string-literal-25944.rs
@@ -0,0 +1,14 @@
+// compile-flags:--test
+
+// https://github.com/rust-lang/rust/issues/25944
+#![crate_name="issue_25944"]
+
+/// ```
+/// let a = r#"
+/// foo
+/// bar"#;
+/// let b = "\nfoo\nbar";
+/// assert_eq!(a, b);
+/// ```
+pub fn main() {
+}