summaryrefslogtreecommitdiffstats
path: root/src/tools/cargo/tests/testsuite/doc.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /src/tools/cargo/tests/testsuite/doc.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/cargo/tests/testsuite/doc.rs')
-rw-r--r--src/tools/cargo/tests/testsuite/doc.rs98
1 files changed, 94 insertions, 4 deletions
diff --git a/src/tools/cargo/tests/testsuite/doc.rs b/src/tools/cargo/tests/testsuite/doc.rs
index 739bcf376..481df8590 100644
--- a/src/tools/cargo/tests/testsuite/doc.rs
+++ b/src/tools/cargo/tests/testsuite/doc.rs
@@ -756,6 +756,7 @@ fn doc_target() {
.file(
"src/lib.rs",
r#"
+ #![allow(internal_features)]
#![feature(no_core, lang_items)]
#![no_core]
@@ -2041,7 +2042,7 @@ fn crate_versions_flag_is_overridden() {
asserts(output_documentation());
}
-#[cargo_test(nightly, reason = "-Zdoctest-in-workspace is unstable")]
+#[cargo_test]
fn doc_test_in_workspace() {
let p = project()
.file(
@@ -2087,8 +2088,7 @@ fn doc_test_in_workspace() {
",
)
.build();
- p.cargo("test -Zdoctest-in-workspace --doc -vv")
- .masquerade_as_nightly_cargo(&["doctest-in-workspace"])
+ p.cargo("test --doc -vv")
.with_stderr_contains("[DOCTEST] crate-a")
.with_stdout_contains(
"
@@ -2096,7 +2096,6 @@ running 1 test
test crate-a/src/lib.rs - (line 1) ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
-
",
)
.with_stderr_contains("[DOCTEST] crate-b")
@@ -2106,7 +2105,98 @@ running 1 test
test crate-b/src/lib.rs - (line 1) ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
+",
+ )
+ .run();
+}
+
+/// This is a test for <https://github.com/rust-lang/rust/issues/46372>.
+/// The `file!()` macro inside of an `include!()` should output
+/// workspace-relative paths, just like it does in other cases.
+#[cargo_test]
+fn doc_test_include_file() {
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [workspace]
+ members = [
+ "child",
+ ]
+ [package]
+ name = "root"
+ version = "0.1.0"
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ r#"
+ /// ```
+ /// assert_eq!("src/lib.rs", file!().replace("\\", "/"))
+ /// ```
+ pub mod included {
+ include!(concat!("../", file!(), ".included.rs"));
+ }
+ "#,
+ )
+ .file(
+ "src/lib.rs.included.rs",
+ r#"
+ /// ```
+ /// assert_eq!(1, 1)
+ /// ```
+ pub fn foo() {}
+ "#,
+ )
+ .file(
+ "child/Cargo.toml",
+ r#"
+ [package]
+ name = "child"
+ version = "0.1.0"
+ "#,
+ )
+ .file(
+ "child/src/lib.rs",
+ r#"
+ /// ```
+ /// assert_eq!("child/src/lib.rs", file!().replace("\\", "/"))
+ /// ```
+ pub mod included {
+ include!(concat!("../../", file!(), ".included.rs"));
+ }
+ "#,
+ )
+ .file(
+ "child/src/lib.rs.included.rs",
+ r#"
+ /// ```
+ /// assert_eq!(1, 1)
+ /// ```
+ pub fn foo() {}
+ "#,
+ )
+ .build();
+
+ p.cargo("test --workspace --doc -vv -- --test-threads=1")
+ .with_stderr_contains("[DOCTEST] child")
+ .with_stdout_contains(
+ "
+running 2 tests
+test child/src/../../child/src/lib.rs.included.rs - included::foo (line 2) ... ok
+test child/src/lib.rs - included (line 2) ... ok
+
+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
+",
+ )
+ .with_stderr_contains("[DOCTEST] root")
+ .with_stdout_contains(
+ "
+running 2 tests
+test src/../src/lib.rs.included.rs - included::foo (line 2) ... ok
+test src/lib.rs - included (line 2) ... ok
+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
",
)
.run();