From b97310c4491c989e74d42b48483626b988d1f5a6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 26 Feb 2025 17:14:10 +0100 Subject: [PATCH] Add run-make test for rustdoc `--emit=dep-info` option --- .../output-default.stdout | 2 +- tests/run-make/rustdoc-dep-info/bar.rs | 1 + tests/run-make/rustdoc-dep-info/doc.md | 1 + tests/run-make/rustdoc-dep-info/foo.rs | 1 + tests/run-make/rustdoc-dep-info/lib.rs | 6 ++++++ tests/run-make/rustdoc-dep-info/rmake.rs | 21 +++++++++++++++++++ 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/run-make/rustdoc-dep-info/bar.rs create mode 100644 tests/run-make/rustdoc-dep-info/doc.md create mode 100644 tests/run-make/rustdoc-dep-info/foo.rs create mode 100644 tests/run-make/rustdoc-dep-info/lib.rs create mode 100644 tests/run-make/rustdoc-dep-info/rmake.rs diff --git a/tests/run-make/rustdoc-default-output/output-default.stdout b/tests/run-make/rustdoc-default-output/output-default.stdout index c1b246e849ce4..01f470f6e162b 100644 --- a/tests/run-make/rustdoc-default-output/output-default.stdout +++ b/tests/run-make/rustdoc-default-output/output-default.stdout @@ -153,7 +153,7 @@ Options: --generate-redirect-map Generate JSON file at the top level instead of generating HTML redirection files - --emit [unversioned-shared-resources,toolchain-shared-resources,invocation-specific] + --emit [unversioned-shared-resources,toolchain-shared-resources,invocation-specific,dep-info] Comma separated list of types of output for rustdoc to emit --no-run Compile doctests without running them diff --git a/tests/run-make/rustdoc-dep-info/bar.rs b/tests/run-make/rustdoc-dep-info/bar.rs new file mode 100644 index 0000000000000..76b8dcd05c8fc --- /dev/null +++ b/tests/run-make/rustdoc-dep-info/bar.rs @@ -0,0 +1 @@ +include!("foo.rs"); diff --git a/tests/run-make/rustdoc-dep-info/doc.md b/tests/run-make/rustdoc-dep-info/doc.md new file mode 100644 index 0000000000000..6a4238fc8b610 --- /dev/null +++ b/tests/run-make/rustdoc-dep-info/doc.md @@ -0,0 +1 @@ +blablabla diff --git a/tests/run-make/rustdoc-dep-info/foo.rs b/tests/run-make/rustdoc-dep-info/foo.rs new file mode 100644 index 0000000000000..b76b4321d62aa --- /dev/null +++ b/tests/run-make/rustdoc-dep-info/foo.rs @@ -0,0 +1 @@ +pub fn foo() {} diff --git a/tests/run-make/rustdoc-dep-info/lib.rs b/tests/run-make/rustdoc-dep-info/lib.rs new file mode 100644 index 0000000000000..1f003f79b1f44 --- /dev/null +++ b/tests/run-make/rustdoc-dep-info/lib.rs @@ -0,0 +1,6 @@ +#![crate_name = "foo"] + +#[cfg_attr(doc, doc = include_str!("doc.md"))] +pub struct Bar; + +mod bar; diff --git a/tests/run-make/rustdoc-dep-info/rmake.rs b/tests/run-make/rustdoc-dep-info/rmake.rs new file mode 100644 index 0000000000000..6902bfc21ca20 --- /dev/null +++ b/tests/run-make/rustdoc-dep-info/rmake.rs @@ -0,0 +1,21 @@ +// This is a simple smoke test for rustdoc's `--emit dep-info` feature. It prints out +// information about dependencies in a Makefile-compatible format, as a `.d` file. + +use run_make_support::assertion_helpers::assert_contains; +use run_make_support::{path, rfs, rustdoc}; + +fn main() { + // We're only emitting dep info, so we shouldn't be running static analysis to + // figure out that this program is erroneous. + rustdoc().input("lib.rs").arg("-Zunstable-options").emit("dep-info").run(); + + let content = rfs::read_to_string("foo.d"); + assert_contains(&content, "lib.rs:"); + assert_contains(&content, "foo.rs:"); + assert_contains(&content, "bar.rs:"); + assert_contains(&content, "doc.md:"); + + // Now we check that we can provide a file name to the `dep-info` argument. + rustdoc().input("lib.rs").arg("-Zunstable-options").emit("dep-info=bla.d").run(); + assert!(path("bla.d").exists()); +}