|
| 1 | +//! Since PR <https://github.com/rust-lang/rust/pull/137899>, merged doctests reside in so-called |
| 2 | +//! "bundle" crates which are separate from the actual "runner" crates that contain the necessary |
| 3 | +//! scaffolding / infrastructure for executing the tests by utilizing the unstable crate `test` |
| 4 | +//! and the internal lang feature `rustc_attrs`. |
| 5 | +//! |
| 6 | +//! In the light of this two-crate setup (per edition), this test ensures that rustdoc can handle |
| 7 | +//! mergeable doctests with direct and transitive dependencies (which would become ("first-degree") |
| 8 | +//! transitive and "second-degree" transitive dependencies of the runner crates, respectively). |
| 9 | +//! |
| 10 | +//! While this is about doctest merging which is only available in Rust 2024 and beyond, |
| 11 | +//! we also test Rust 2021 here to ensure that in this specific scenario rustdoc doesn't |
| 12 | +//! grossly diverge in observable behavior. |
| 13 | +
|
| 14 | +use run_make_support::{bare_rustc, rustdoc}; |
| 15 | + |
| 16 | +fn main() { |
| 17 | + // Re. `bare_rustc` over `rustc` (which would implicitly add `-L.`): |
| 18 | + // This test is all about verifying that rustdoc is able to find dependencies |
| 19 | + // and properly propagates library search paths etc. |
| 20 | + // Anything implicit like that would only obfuscate this test or even |
| 21 | + // accidentally break it. |
| 22 | + |
| 23 | + // |
| 24 | + // Build crate `a_a` and its dependent `a` which is the direct dependency of |
| 25 | + // the doctests inside `doctest.rs` *and* of crate `doctest` itself! |
| 26 | + // |
| 27 | + |
| 28 | + bare_rustc().current_dir("deps").input("dep_a_a.rs").crate_type("lib").run(); |
| 29 | + |
| 30 | + bare_rustc().input("dep_a.rs").crate_type("lib").args(["--extern=dep_a_a", "-Ldeps"]).run(); |
| 31 | + |
| 32 | + // |
| 33 | + // Build crate `b_b` and its dependent `b` which is the direct dependency of |
| 34 | + // the first doctest in `doctest.rs` *but not* of crate `doctest` itself! |
| 35 | + // |
| 36 | + |
| 37 | + bare_rustc().current_dir("deps").input("dep_b_b.rs").crate_type("lib").run(); |
| 38 | + |
| 39 | + bare_rustc().input("dep_b.rs").crate_type("lib").args(["--extern=dep_b_b", "-Ldeps"]).run(); |
| 40 | + |
| 41 | + // |
| 42 | + // Collect and run the doctests inside `doctest.rs`. |
| 43 | + // |
| 44 | + |
| 45 | + for edition in ["2021", "2024"] { |
| 46 | + // NB: `-Ldependency=<path>` only adds *transitive* dependencies to |
| 47 | + // the search path contrary to `-L<path>`. |
| 48 | + |
| 49 | + rustdoc() |
| 50 | + .input("doctest.rs") |
| 51 | + .crate_type("lib") |
| 52 | + .edition(edition) |
| 53 | + // Adds crate `a` as a dep of `doctest` *and* its contained doctests. |
| 54 | + // Also registers transitive dependencies. |
| 55 | + .extern_("dep_a", "libdep_a.rlib") |
| 56 | + .arg("-Ldependency=deps") |
| 57 | + // Adds crate `b` as a dep of `doctest`'s contained doctests. |
| 58 | + // Also registers transitive dependencies. |
| 59 | + .args([ |
| 60 | + "-Zunstable-options", |
| 61 | + "--doctest-compilation-args", |
| 62 | + "--extern=dep_b=libdep_b.rlib -Ldependency=deps", |
| 63 | + ]) |
| 64 | + .arg("--test") |
| 65 | + .arg("--test-args=--test-threads=1") |
| 66 | + .run(); |
| 67 | + } |
| 68 | +} |
0 commit comments