1- // This test ensures that if the rustdoc test binary is not executable, it will
2- // gracefully fail and not panic.
1+ // This test validates the `--test-builder` rustdoc option.
2+ // It ensures that:
3+ // 1. When the test-builder path points to a non-executable file, rustdoc gracefully fails
4+ // 2. When the test-builder path points to a valid executable, it receives rustc arguments
35
46//@ needs-target-std
57
6- use run_make_support::{path, rfs, rustdoc};
8+ use run_make_support::{bare_rustc, path, rfs, rustc_path, rustdoc, target };
79
810fn main() {
11+ // Test 1: Verify that a non-executable test-builder fails gracefully
912 let absolute_path = path("foo.rs").canonicalize().expect("failed to get absolute path");
1013 let output = rustdoc()
1114 .input("foo.rs")
@@ -19,4 +22,37 @@ fn main() {
1922 output.assert_stdout_contains("Failed to spawn ");
2023 // ... and that we didn't panic.
2124 output.assert_not_ice();
25+
26+ // Some targets (for example wasm) cannot execute doctests directly even with a runner,
27+ // so only exercise the success path when the target can run on the host.
28+ if target().contains("wasm") || std::env::var_os("REMOTE_TEST_CLIENT").is_some() {
29+ return;
30+ }
31+
32+ // Test 2: Verify that a valid test-builder is invoked with correct arguments
33+ // Build a custom test-builder that logs its arguments and forwards to rustc.
34+ // Use `bare_rustc` so we compile for the host architecture even in cross builds.
35+ let builder_bin = path("builder-bin");
36+ bare_rustc().input("builder.rs").output(&builder_bin).run();
37+
38+ let log_path = path("builder.log");
39+ let _ = std::fs::remove_file(&log_path);
40+
41+ // Run rustdoc with our custom test-builder
42+ rustdoc()
43+ .input("doctest.rs")
44+ .arg("--test")
45+ .arg("-Zunstable-options")
46+ .arg("--test-builder")
47+ .arg(&builder_bin)
48+ .env("REAL_RUSTC", rustc_path())
49+ .env("BUILDER_LOG", &log_path)
50+ .run();
51+
52+ // Verify the custom builder was invoked with rustc-style arguments
53+ let log_contents = rfs::read_to_string(&log_path);
54+ assert!(
55+ log_contents.contains("--crate-type"),
56+ "expected builder to receive rustc arguments, got:\n{log_contents}"
57+ );
2258}
0 commit comments