rust/tests/run-make/rustdoc-test-builder/builder.rs
Osama Abdelkader 8075c98745 Add test for success path
Adds missing test coverage for rustdoc's `--test-builder` option.

The existing test only covered the error case (non-executable builder). This PR
adds:
- A custom test builder that logs arguments and forwards to rustc
- A test verifying that `--test-builder` successfully invokes the custom
builder with rustc-style arguments
- Improved comments explaining both the error and success test scenarios

The test validates that custom builders can properly intercept and handle
doctest compilation.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
2025-11-07 00:24:04 +02:00

23 lines
779 B
Rust

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));
}
}