Skip to content

Commit ce42e06

Browse files
Add regression test when unable to run compiler in doctest
1 parent 64d9631 commit ce42e06

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/librustdoc/doctest.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,7 @@ fn add_exe_suffix(input: String, target: &TargetTuple) -> String {
501501
input + &exe_suffix
502502
}
503503

504-
fn wrapped_rustc_command<'a>(
505-
rustc_wrappers: &'a [PathBuf],
506-
rustc_binary: &'a Path,
507-
) -> (Command, &'a Path) {
504+
fn wrapped_rustc_command<'a>(rustc_wrappers: &'a [PathBuf], rustc_binary: &'a Path) -> Command {
508505
let mut args = rustc_wrappers.iter().map(PathBuf::as_path).chain([rustc_binary]);
509506

510507
let exe = args.next().expect("unable to create rustc command");
@@ -513,7 +510,7 @@ fn wrapped_rustc_command<'a>(
513510
command.arg(arg);
514511
}
515512

516-
(command, rustc_wrappers.first().map(|p| &**p).unwrap_or(rustc_binary))
513+
command
517514
}
518515

519516
/// Information needed for running a bundle of doctests.
@@ -633,8 +630,7 @@ fn run_test(
633630
.test_builder
634631
.as_deref()
635632
.unwrap_or_else(|| rustc_interface::util::rustc_path(sysroot).expect("found rustc"));
636-
let (mut compiler, binary_path) =
637-
wrapped_rustc_command(&rustdoc_options.test_builder_wrappers, rustc_binary);
633+
let mut compiler = wrapped_rustc_command(&rustdoc_options.test_builder_wrappers, rustc_binary);
638634

639635
compiler.args(&compiler_args);
640636

@@ -675,6 +671,7 @@ fn run_test(
675671

676672
debug!("compiler invocation for doctest: {compiler:?}");
677673

674+
let binary_path = compiler.get_program().to_os_string();
678675
let mut child = match compiler.spawn() {
679676
Ok(child) => child,
680677
Err(error) => {
@@ -690,7 +687,7 @@ fn run_test(
690687
// build it now
691688
let runner_input_file = doctest.path_for_merged_doctest_runner();
692689

693-
let (mut runner_compiler, binary_path) =
690+
let mut runner_compiler =
694691
wrapped_rustc_command(&rustdoc_options.test_builder_wrappers, rustc_binary);
695692
// the test runner does not contain any user-written code, so this doesn't allow
696693
// the user to exploit nightly-only features on stable
@@ -743,6 +740,7 @@ fn run_test(
743740
let status = if !status.success() {
744741
status
745742
} else {
743+
let binary_path = runner_compiler.get_program().to_os_string();
746744
let mut child_runner = match runner_compiler.spawn() {
747745
Ok(child) => child,
748746
Err(error) => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! ```
2+
//! let x = 12;
3+
//! ```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This test ensures that if the rustdoc test binary is not executable, it will
2+
// gracefully fail and not panic.
3+
4+
//@ needs-target-std
5+
6+
use run_make_support::{path, rfs, rustdoc};
7+
8+
fn main() {
9+
let absolute_path = path("foo.rs").canonicalize().expect("failed to get absolute path");
10+
let output = rustdoc()
11+
.input("foo.rs")
12+
.arg("--test")
13+
.arg("-Zunstable-options")
14+
.arg("--test-builder")
15+
.arg(&absolute_path)
16+
.run_fail();
17+
18+
output.assert_stdout_contains("Failed to spawn ");
19+
output.assert_stderr_not_contains("the compiler unexpectedly panicked. this is a bug.");
20+
// Just in case...
21+
output.assert_stdout_not_contains("the compiler unexpectedly panicked. this is a bug.");
22+
}

0 commit comments

Comments
 (0)