diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-01-20 11:14:49 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-20 11:14:49 +0530 |
| commit | cd4652a195ff019481c719a3d66ef4938c20e3d9 (patch) | |
| tree | 50995003e8e821f4fe7dbda5ff4cae9ec0e3134c /src | |
| parent | fb86b820bbde7772477a95e36a70f06578313de2 (diff) | |
| parent | 17f4cbc3032f7e81f0ec0c7e3b4cd0c3da30c916 (diff) | |
| download | rust-cd4652a195ff019481c719a3d66ef4938c20e3d9.tar.gz rust-cd4652a195ff019481c719a3d66ef4938c20e3d9.zip | |
Rollup merge of #68357 - ollie27:rustdoc_test_errors, r=GuillaumeGomez
rustdoc: Fix handling of compile errors when running `rustdoc --test` * Call `abort_if_errors` so all errors actually stop rustdoc. * Don't panic with "compiler aborted in rustdoc!", instead just exit to avoid the ugly panic message. * Use rlib as the crate type when searching for doctests matching what is used for doc generation so `#[no_std]` crates don't create "no global memory allocator" errors. Fixes #52243 Fixes #54010 r? @GuillaumeGomez
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/test.rs | 10 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/test-compile-fail1.rs | 8 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/test-compile-fail1.stderr | 14 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/test-compile-fail2.rs | 3 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/test-compile-fail2.stderr | 8 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/test-compile-fail3.rs | 3 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/test-compile-fail3.stderr | 8 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/test-no_std.rs | 12 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/test-no_std.stdout | 6 |
9 files changed, 69 insertions, 3 deletions
diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 05d41415689..d89dc2adafe 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -43,7 +43,7 @@ pub fn run(options: Options) -> i32 { let crate_types = if options.proc_macro_crate { vec![config::CrateType::ProcMacro] } else { - vec![config::CrateType::Dylib] + vec![config::CrateType::Rlib] }; let sessopts = config::Options { @@ -117,12 +117,16 @@ pub fn run(options: Options) -> i32 { intravisit::walk_crate(this, krate); }); }); + compiler.session().abort_if_errors(); let ret: Result<_, ErrorReported> = Ok(collector.tests); ret }) - }) - .expect("compiler aborted in rustdoc!"); + }); + let tests = match tests { + Ok(tests) => tests, + Err(ErrorReported) => return 1, + }; test_args.insert(0, "rustdoctest".to_string()); diff --git a/src/test/rustdoc-ui/test-compile-fail1.rs b/src/test/rustdoc-ui/test-compile-fail1.rs new file mode 100644 index 00000000000..a0539023878 --- /dev/null +++ b/src/test/rustdoc-ui/test-compile-fail1.rs @@ -0,0 +1,8 @@ +// compile-flags:--test + +/// ``` +/// assert!(true) +/// ``` +pub fn f() {} + +pub fn f() {} diff --git a/src/test/rustdoc-ui/test-compile-fail1.stderr b/src/test/rustdoc-ui/test-compile-fail1.stderr new file mode 100644 index 00000000000..2b38ba9e973 --- /dev/null +++ b/src/test/rustdoc-ui/test-compile-fail1.stderr @@ -0,0 +1,14 @@ +error[E0428]: the name `f` is defined multiple times + --> $DIR/test-compile-fail1.rs:8:1 + | +6 | pub fn f() {} + | ---------- previous definition of the value `f` here +7 | +8 | pub fn f() {} + | ^^^^^^^^^^ `f` redefined here + | + = note: `f` must be defined only once in the value namespace of this module + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0428`. diff --git a/src/test/rustdoc-ui/test-compile-fail2.rs b/src/test/rustdoc-ui/test-compile-fail2.rs new file mode 100644 index 00000000000..651ded0a047 --- /dev/null +++ b/src/test/rustdoc-ui/test-compile-fail2.rs @@ -0,0 +1,3 @@ +// compile-flags:--test + +fail diff --git a/src/test/rustdoc-ui/test-compile-fail2.stderr b/src/test/rustdoc-ui/test-compile-fail2.stderr new file mode 100644 index 00000000000..cee5b63cf50 --- /dev/null +++ b/src/test/rustdoc-ui/test-compile-fail2.stderr @@ -0,0 +1,8 @@ +error: expected one of `!` or `::`, found `<eof>` + --> $DIR/test-compile-fail2.rs:3:1 + | +3 | fail + | ^^^^ expected one of `!` or `::` + +error: aborting due to previous error + diff --git a/src/test/rustdoc-ui/test-compile-fail3.rs b/src/test/rustdoc-ui/test-compile-fail3.rs new file mode 100644 index 00000000000..faa30ad8367 --- /dev/null +++ b/src/test/rustdoc-ui/test-compile-fail3.rs @@ -0,0 +1,3 @@ +// compile-flags:--test + +"fail diff --git a/src/test/rustdoc-ui/test-compile-fail3.stderr b/src/test/rustdoc-ui/test-compile-fail3.stderr new file mode 100644 index 00000000000..7a2f1815ed8 --- /dev/null +++ b/src/test/rustdoc-ui/test-compile-fail3.stderr @@ -0,0 +1,8 @@ +error: unterminated double quote string + --> $DIR/test-compile-fail3.rs:3:1 + | +3 | "fail + | ^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/rustdoc-ui/test-no_std.rs b/src/test/rustdoc-ui/test-no_std.rs new file mode 100644 index 00000000000..166a87382cb --- /dev/null +++ b/src/test/rustdoc-ui/test-no_std.rs @@ -0,0 +1,12 @@ +// compile-flags:--test +// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" +// build-pass + +#![no_std] + +extern crate alloc; + +/// ``` +/// assert!(true) +/// ``` +pub fn f() {} diff --git a/src/test/rustdoc-ui/test-no_std.stdout b/src/test/rustdoc-ui/test-no_std.stdout new file mode 100644 index 00000000000..9cdcac2a483 --- /dev/null +++ b/src/test/rustdoc-ui/test-no_std.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/test-no_std.rs - f (line 9) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out + |
