Skip to content
Merged
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
16 changes: 14 additions & 2 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,13 @@ fn run_test(

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

let mut child = compiler.spawn().expect("Failed to spawn rustc process");
let mut child = match compiler.spawn() {
Ok(child) => child,
Err(error) => {
eprintln!("Failed to spawn {:?}: {error:?}", compiler.get_program());
return (Duration::default(), Err(TestFailure::CompileError));
}
};
let output = if let Some(merged_test_code) = &doctest.merged_test_code {
// compile-fail tests never get merged, so this should always pass
let status = child.wait().expect("Failed to wait");
Expand Down Expand Up @@ -732,7 +738,13 @@ fn run_test(
let status = if !status.success() {
status
} else {
let mut child_runner = runner_compiler.spawn().expect("Failed to spawn rustc process");
let mut child_runner = match runner_compiler.spawn() {
Ok(child) => child,
Err(error) => {
eprintln!("Failed to spawn {:?}: {error:?}", runner_compiler.get_program());
return (Duration::default(), Err(TestFailure::CompileError));
}
};
child_runner.wait().expect("Failed to wait")
};

Expand Down
7 changes: 7 additions & 0 deletions src/tools/run-make-support/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ impl CompletedProcess {
self
}

/// Checks that `stderr` doesn't contain the Internal Compiler Error message.
#[track_caller]
pub fn assert_not_ice(&self) -> &Self {
self.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug");
self
}

/// Checks that `stderr` does not contain the regex pattern `unexpected`.
#[track_caller]
pub fn assert_stderr_not_contains_regex<S: AsRef<str>>(&self, unexpected: S) -> &Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ fn main() {
.extern_("minibevy", "libminibevy-b.rmeta")
.extern_("minirapier", "libminirapier.rmeta")
.run_fail()
.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug");
.assert_not_ice();
}
2 changes: 1 addition & 1 deletion tests/run-make/rustdoc-merge-no-input-finalize/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ fn main() {
.arg(format!("--include-parts-dir={}", parts_out_dir.display()))
.arg("--merge=finalize")
.run();
output.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug.");
output.assert_not_ice();
}
3 changes: 3 additions & 0 deletions tests/run-make/rustdoc-test-builder/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! ```
//! let x = 12;
//! ```
22 changes: 22 additions & 0 deletions tests/run-make/rustdoc-test-builder/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This test ensures that if the rustdoc test binary is not executable, it will
// gracefully fail and not panic.

//@ needs-target-std

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

fn main() {
let absolute_path = path("foo.rs").canonicalize().expect("failed to get absolute path");
let output = rustdoc()
.input("foo.rs")
.arg("--test")
.arg("-Zunstable-options")
.arg("--test-builder")
.arg(&absolute_path)
.run_fail();

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets also assert that the exit code is 1 (ICE gives 101, like other panics), seems more robust than string comparisons.

Copy link
Member Author

Choose a reason for hiding this comment

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

panic! isn't always 101 as exit code (depends on the target). So we can't really check for that. ^^'

Discovered that while reading https://github.com/rust-lang/rust/blob/master/library/test/src/test_result.rs#L107.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, you can just stick it behind a cfg(unix) or something, it would still me more reliable than only looking at the strings.

Is normal error exit always 1? Because that's what I was reccomending we actually put in the assertion.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case should be enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hum, when we fail doctests, we exit with 101. ^^'

// We check that rustdoc outputs the error correctly...
output.assert_stdout_contains("Failed to spawn ");
// ... and that we didn't panic.
output.assert_not_ice();
}
Loading