Skip to content

Commit 29fe476

Browse files
Add regression test when unable to run compiler in doctest
1 parent 2aecfd7 commit 29fe476

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/librustdoc/doctest.rs

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

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

509506
let exe = args.next().expect("unable to create rustc command");
@@ -512,7 +509,7 @@ fn wrapped_rustc_command<'a>(
512509
command.arg(arg);
513510
}
514511

515-
(command, rustc_wrappers.first().map(|p| &**p).unwrap_or(rustc_binary))
512+
command
516513
}
517514

518515
/// Information needed for running a bundle of doctests.
@@ -632,8 +629,7 @@ fn run_test(
632629
.test_builder
633630
.as_deref()
634631
.unwrap_or_else(|| rustc_interface::util::rustc_path(sysroot).expect("found rustc"));
635-
let (mut compiler, binary_path) =
636-
wrapped_rustc_command(&rustdoc_options.test_builder_wrappers, rustc_binary);
632+
let mut compiler = wrapped_rustc_command(&rustdoc_options.test_builder_wrappers, rustc_binary);
637633

638634
compiler.args(&compiler_args);
639635

@@ -677,7 +673,7 @@ fn run_test(
677673
let mut child = match compiler.spawn() {
678674
Ok(child) => child,
679675
Err(error) => {
680-
eprintln!("Failed to spawn {binary_path:?}: {error:?}");
676+
eprintln!("Failed to spawn {:?}: {error:?}", compiler.get_program());
681677
return (Duration::default(), Err(TestFailure::CompileError));
682678
}
683679
};
@@ -689,7 +685,7 @@ fn run_test(
689685
// build it now
690686
let runner_input_file = doctest.path_for_merged_doctest_runner();
691687

692-
let (mut runner_compiler, binary_path) =
688+
let mut runner_compiler =
693689
wrapped_rustc_command(&rustdoc_options.test_builder_wrappers, rustc_binary);
694690
// the test runner does not contain any user-written code, so this doesn't allow
695691
// the user to exploit nightly-only features on stable
@@ -745,7 +741,7 @@ fn run_test(
745741
let mut child_runner = match runner_compiler.spawn() {
746742
Ok(child) => child,
747743
Err(error) => {
748-
eprintln!("Failed to spawn {binary_path:?}: {error:?}");
744+
eprintln!("Failed to spawn {:?}: {error:?}", runner_compiler.get_program());
749745
return (Duration::default(), Err(TestFailure::CompileError));
750746
}
751747
};
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)