Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/run-make/rustdoc-test-builder/builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::ffi::OsString;
use std::path::PathBuf;
use std::process::{self, Command};
use std::{env, fs};

fn main() {
let args: Vec<OsString> = env::args_os().collect();
let log_path = env::var_os("BUILDER_LOG").map(PathBuf::from).expect("BUILDER_LOG must be set");
let real_rustc = env::var_os("REAL_RUSTC").expect("REAL_RUSTC must be set");

let log_contents =
args.iter().skip(1).map(|arg| arg.to_string_lossy()).collect::<Vec<_>>().join("\n");
fs::write(&log_path, log_contents).expect("failed to write builder log");

let status = Command::new(real_rustc)
.args(args.iter().skip(1))
.status()
.expect("failed to invoke real rustc");

if !status.success() {
process::exit(status.code().unwrap_or(1));
}
}
3 changes: 3 additions & 0 deletions tests/run-make/rustdoc-test-builder/doctest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! ```rust
//! assert_eq!(2 + 2, 4);
//! ```
35 changes: 32 additions & 3 deletions tests/run-make/rustdoc-test-builder/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// This test ensures that if the rustdoc test binary is not executable, it will
// gracefully fail and not panic.
// This test validates the `--test-builder` rustdoc option.
// It ensures that:
// 1. When the test-builder path points to a non-executable file, rustdoc gracefully fails
// 2. When the test-builder path points to a valid executable, it receives rustc arguments

//@ needs-target-std

use run_make_support::{path, rfs, rustdoc};
use run_make_support::{path, rfs, rustc, rustc_path, rustdoc};

fn main() {
// Test 1: Verify that a non-executable test-builder fails gracefully
let absolute_path = path("foo.rs").canonicalize().expect("failed to get absolute path");
let output = rustdoc()
.input("foo.rs")
Expand All @@ -19,4 +22,30 @@ fn main() {
output.assert_stdout_contains("Failed to spawn ");
// ... and that we didn't panic.
output.assert_not_ice();

// Test 2: Verify that a valid test-builder is invoked with correct arguments
// Build a custom test-builder that logs its arguments and forwards to rustc
let builder_bin = path("builder-bin");
rustc().input("builder.rs").output(&builder_bin).run();

let log_path = path("builder.log");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this file?

let _ = std::fs::remove_file(&log_path);

// Run rustdoc with our custom test-builder
rustdoc()
.input("doctest.rs")
.arg("--test")
.arg("-Zunstable-options")
.arg("--test-builder")
.arg(&builder_bin)
.env("REAL_RUSTC", rustc_path())
.env("BUILDER_LOG", &log_path)
.run();

// Verify the custom builder was invoked with rustc-style arguments
let log_contents = rfs::read_to_string(&log_path);
assert!(
log_contents.contains("--crate-type"),
"expected builder to receive rustc arguments, got:\n{log_contents}"
);
}
Loading