From 667d648066821e212c74b076c9fe108745deced1 Mon Sep 17 00:00:00 2001 From: Armando Montanez Date: Wed, 28 Aug 2024 10:19:10 -0700 Subject: [PATCH] Add test for rules_rust#1952 Adds a test that reproduces the bug mentioned in rules_rust#1952. --- test/unit/rustdoc/procmacro_in_rustdoc.rs | 9 +++++++++ test/unit/rustdoc/rustdoc_unit_test.bzl | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/unit/rustdoc/procmacro_in_rustdoc.rs diff --git a/test/unit/rustdoc/procmacro_in_rustdoc.rs b/test/unit/rustdoc/procmacro_in_rustdoc.rs new file mode 100644 index 0000000000..7e77bb1164 --- /dev/null +++ b/test/unit/rustdoc/procmacro_in_rustdoc.rs @@ -0,0 +1,9 @@ +/// A different answer that only exists if using procmacros. +/// ``` +/// use rustdoc_proc_macro::make_answer; +/// make_answer!(); +/// assert_eq!(answer(), 42); +/// ``` +pub fn procmacro_answer() -> u32 { + 24 +} diff --git a/test/unit/rustdoc/rustdoc_unit_test.bzl b/test/unit/rustdoc/rustdoc_unit_test.bzl index aec30bfcd6..1afe73a52f 100644 --- a/test/unit/rustdoc/rustdoc_unit_test.bzl +++ b/test/unit/rustdoc/rustdoc_unit_test.bzl @@ -58,6 +58,14 @@ def _rustdoc_for_lib_with_proc_macro_test_impl(ctx): return analysistest.end(env) +def _rustdoc_for_lib_with_proc_macro_in_docs_test_impl(ctx): + env = analysistest.begin(ctx) + tut = analysistest.target_under_test(env) + + _common_rustdoc_checks(env, tut) + + return analysistest.end(env) + def _rustdoc_for_bin_with_transitive_proc_macro_test_impl(ctx): env = analysistest.begin(ctx) tut = analysistest.target_under_test(env) @@ -115,6 +123,7 @@ rustdoc_for_lib_test = analysistest.make(_rustdoc_for_lib_test_impl) rustdoc_for_bin_test = analysistest.make(_rustdoc_for_bin_test_impl) rustdoc_for_proc_macro_test = analysistest.make(_rustdoc_for_proc_macro_test_impl) rustdoc_for_lib_with_proc_macro_test = analysistest.make(_rustdoc_for_lib_with_proc_macro_test_impl) +rustdoc_for_lib_with_proc_macro_in_docs_test = analysistest.make(_rustdoc_for_lib_with_proc_macro_in_docs_test_impl) rustdoc_for_bin_with_transitive_proc_macro_test = analysistest.make(_rustdoc_for_bin_with_transitive_proc_macro_test_impl) rustdoc_for_lib_with_cc_lib_test = analysistest.make(_rustdoc_for_lib_with_cc_lib_test_impl) rustdoc_with_args_test = analysistest.make(_rustdoc_with_args_test_impl) @@ -185,6 +194,13 @@ def _define_targets(): crate_features = ["with_proc_macro"], ) + _target_maker( + rust_library, + name = "lib_with_proc_macro_in_docs", + srcs = ["procmacro_in_rustdoc.rs"], + proc_macro_deps = [":rustdoc_proc_macro"], + ) + _target_maker( rust_library, name = "lib_nodep_with_proc_macro", @@ -286,6 +302,11 @@ def rustdoc_test_suite(name): target_under_test = ":rustdoc_proc_macro_doc", ) + rustdoc_for_lib_with_proc_macro_in_docs_test( + name = "rustdoc_for_lib_with_proc_macro_in_docs_test", + target_under_test = ":lib_with_proc_macro_in_docs_doc", + ) + rustdoc_for_lib_with_proc_macro_test( name = "rustdoc_for_lib_with_proc_macro_test", target_under_test = ":lib_with_proc_macro_doc", @@ -322,6 +343,7 @@ def rustdoc_test_suite(name): ":rustdoc_for_lib_test", ":rustdoc_for_bin_test", ":rustdoc_for_proc_macro_test", + ":rustdoc_for_lib_with_proc_macro_in_docs_test", ":rustdoc_for_lib_with_proc_macro_test", ":rustdoc_for_lib_with_cc_lib_test", ":rustdoc_with_args_test",