End unification of exit codes in librustdoc
This commit is contained in:
@@ -450,20 +450,29 @@ fn main_args(args: &[String]) -> i32 {
|
|||||||
rustc_interface::interface::default_thread_pool(options.edition, move || main_options(options))
|
rustc_interface::interface::default_thread_pool(options.edition, move || main_options(options))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> i32 {
|
||||||
|
match res {
|
||||||
|
Ok(()) => 0,
|
||||||
|
Err(err) => {
|
||||||
|
if !err.is_empty() {
|
||||||
|
diag.struct_err(&err).emit();
|
||||||
|
}
|
||||||
|
1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main_options(options: config::Options) -> i32 {
|
fn main_options(options: config::Options) -> i32 {
|
||||||
let diag = core::new_handler(options.error_format, None, &options.debugging_options);
|
let diag = core::new_handler(options.error_format, None, &options.debugging_options);
|
||||||
|
|
||||||
match (options.should_test, options.markdown_input()) {
|
match (options.should_test, options.markdown_input()) {
|
||||||
(true, true) => return markdown::test(options, &diag),
|
(true, true) => return wrap_return(&diag, markdown::test(options)),
|
||||||
(true, false) => return test::run(options),
|
(true, false) => return wrap_return(&diag, test::run(options)),
|
||||||
(false, true) => {
|
(false, true) => {
|
||||||
match markdown::render(&options.input, options.render_options, options.edition) {
|
return wrap_return(
|
||||||
Ok(()) => return 0,
|
&diag,
|
||||||
Err(err) => {
|
markdown::render(&options.input, options.render_options, options.edition),
|
||||||
diag.struct_err(&err).emit();
|
);
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
(false, false) => {}
|
(false, false) => {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use rustc_span::edition::Edition;
|
|||||||
use rustc_span::source_map::DUMMY_SP;
|
use rustc_span::source_map::DUMMY_SP;
|
||||||
|
|
||||||
use crate::config::{Options, RenderOptions};
|
use crate::config::{Options, RenderOptions};
|
||||||
use crate::externalfiles::{load_string, LoadStringError};
|
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::markdown;
|
use crate::html::markdown;
|
||||||
use crate::html::markdown::{find_testable_code, ErrorCodes, IdMap, Markdown, MarkdownWithToc};
|
use crate::html::markdown::{find_testable_code, ErrorCodes, IdMap, Markdown, MarkdownWithToc};
|
||||||
@@ -116,13 +115,9 @@ pub fn render<P: AsRef<Path>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Runs any tests/code examples in the markdown file `input`.
|
/// Runs any tests/code examples in the markdown file `input`.
|
||||||
pub fn test(mut options: Options, diag: &rustc_errors::Handler) -> i32 {
|
pub fn test(mut options: Options) -> Result<(), String> {
|
||||||
let input_str = match load_string(&options.input, diag) {
|
let input_str = read_to_string(&options.input)
|
||||||
Ok(s) => s,
|
.map_err(|err| format!("{}: {}", options.input.display(), err))?;
|
||||||
Err(LoadStringError::ReadFail) => return 1,
|
|
||||||
Err(LoadStringError::BadUtf8) => return 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut opts = TestOptions::default();
|
let mut opts = TestOptions::default();
|
||||||
opts.no_crate_inject = true;
|
opts.no_crate_inject = true;
|
||||||
opts.display_warnings = options.display_warnings;
|
opts.display_warnings = options.display_warnings;
|
||||||
@@ -146,5 +141,5 @@ pub fn test(mut options: Options, diag: &rustc_errors::Handler) -> i32 {
|
|||||||
collector.tests,
|
collector.tests,
|
||||||
Some(testing::Options::new().display_output(options.display_warnings)),
|
Some(testing::Options::new().display_output(options.display_warnings)),
|
||||||
);
|
);
|
||||||
0
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ pub struct TestOptions {
|
|||||||
pub attrs: Vec<String>,
|
pub attrs: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(options: Options) -> i32 {
|
pub fn run(options: Options) -> Result<(), String> {
|
||||||
let input = config::Input::File(options.input.clone());
|
let input = config::Input::File(options.input.clone());
|
||||||
|
|
||||||
let warnings_lint_name = lint::builtin::WARNINGS.name;
|
let warnings_lint_name = lint::builtin::WARNINGS.name;
|
||||||
@@ -175,7 +175,7 @@ pub fn run(options: Options) -> i32 {
|
|||||||
});
|
});
|
||||||
let tests = match tests {
|
let tests = match tests {
|
||||||
Ok(tests) => tests,
|
Ok(tests) => tests,
|
||||||
Err(ErrorReported) => return 1,
|
Err(ErrorReported) => return Err(String::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
test_args.insert(0, "rustdoctest".to_string());
|
test_args.insert(0, "rustdoctest".to_string());
|
||||||
@@ -186,7 +186,7 @@ pub fn run(options: Options) -> i32 {
|
|||||||
Some(testing::Options::new().display_output(display_warnings)),
|
Some(testing::Options::new().display_output(display_warnings)),
|
||||||
);
|
);
|
||||||
|
|
||||||
0
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
|
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
|
||||||
|
|||||||
Reference in New Issue
Block a user