From 1318e53ea8a8ed6da271d6130dab71131542ab98 Mon Sep 17 00:00:00 2001 From: Wesley Norris Date: Sat, 8 Dec 2018 14:17:50 -0500 Subject: [PATCH 1/6] Persist doc test executables to given path. --- src/librustdoc/config.rs | 4 ++++ src/librustdoc/lib.rs | 5 +++++ src/librustdoc/markdown.rs | 2 +- src/librustdoc/test.rs | 42 +++++++++++++++++++++++++++++++++----- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index d99136802514d..279d3b921345a 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -68,6 +68,8 @@ pub struct Options { pub should_test: bool, /// List of arguments to pass to the test harness, if running tests. pub test_args: Vec, + /// Whether to persist the doctest executables. + pub persist_doctests: Option, // Options that affect the documentation process @@ -431,6 +433,7 @@ impl Options { let enable_index_page = matches.opt_present("enable-index-page") || index_page.is_some(); let static_root_path = matches.opt_str("static-root-path"); let generate_search_filter = !matches.opt_present("disable-per-crate-search"); + let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from); let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); @@ -456,6 +459,7 @@ impl Options { manual_passes, display_warnings, crate_version, + persist_doctests, render_options: RenderOptions { output, external_html, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 1b6d7e87192d6..7fe0999bdca50 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -340,6 +340,11 @@ fn opts() -> Vec { o.optflag("", "disable-per-crate-search", "disables generating the crate selector on the search box") + unstable("persist-doctests", |o| { + o.optopt("", + "persist-doctests", + "Persists the rustdoc test executables", + "PATH") }), ] } diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index da56194c27c2c..65a96e9001b26 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -142,7 +142,7 @@ pub fn test(mut options: Options, diag: &errors::Handler) -> isize { options.libs, options.codegen_options, options.externs, true, opts, options.maybe_sysroot, None, Some(options.input), - options.linker, options.edition); + options.linker, options.edition, options.persist_doctests); collector.set_position(DUMMY_SP); let codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build()); let res = find_testable_code(&input_str, &mut collector, codes); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index af47c7d5e8bfa..03b66759d40e1 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -120,7 +120,8 @@ pub fn run(mut options: Options) -> isize { Some(source_map), None, options.linker, - options.edition + options.edition, + options.persist_doctests, ); { @@ -184,7 +185,8 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize, cg: CodegenOptions, externs: Externs, should_panic: bool, no_run: bool, as_test_harness: bool, compile_fail: bool, mut error_codes: Vec, opts: &TestOptions, - maybe_sysroot: Option, linker: Option, edition: Edition) { + maybe_sysroot: Option, linker: Option, edition: Edition, + persist_doctests: Option) { // The test harness wants its own `main` and top-level functions, so // never wrap the test in `fn main() { ... }`. let (test, line_offset) = make_test(test, Some(cratename), as_test_harness, opts); @@ -249,6 +251,20 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize, let old = io::set_panic(Some(box Sink(data.clone()))); let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout())); + enum DirState { + Temp(tempfile::TempDir), + Perm(PathBuf), + } + + impl DirState { + fn path(&self) -> &std::path::Path { + match self { + DirState::Temp(t) => t.path(), + DirState::Perm(p) => p.as_path(), + } + } + } + let (libdir, outdir, compile_result) = driver::spawn_thread_pool(sessopts, |sessopts| { let source_map = Lrc::new(SourceMap::new(sessopts.file_path_mapping())); let emitter = errors::emitter::EmitterWriter::new(box Sink(data.clone()), @@ -267,7 +283,17 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize, rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let outdir = Mutex::new( - TempFileBuilder::new().prefix("rustdoctest").tempdir().expect("rustdoc needs a tempdir") + if let Some(mut path) = persist_doctests { + path.push(format!("{}_{}", filename.to_string().rsplit('/').next().unwrap().replace(".", "_"), line)); + std::fs::create_dir_all(&path).expect("Couldn't create directory for doctest executables"); + + DirState::Perm(path) + } else { + DirState::Temp(TempFileBuilder::new() + .prefix("rustdoctest") + .tempdir() + .expect("rustdoc needs a tempdir")) + } ); let libdir = sess.target_filesearch(PathKind::All).get_lib_path(); let mut control = driver::CompileController::basic(); @@ -629,13 +655,15 @@ pub struct Collector { filename: Option, linker: Option, edition: Edition, + persist_doctests: Option, } impl Collector { pub fn new(cratename: String, cfgs: Vec, libs: Vec, cg: CodegenOptions, externs: Externs, use_headers: bool, opts: TestOptions, maybe_sysroot: Option, source_map: Option>, - filename: Option, linker: Option, edition: Edition) -> Collector { + filename: Option, linker: Option, edition: Edition, + persist_doctests: Option) -> Collector { Collector { tests: Vec::new(), names: Vec::new(), @@ -652,6 +680,7 @@ impl Collector { filename, linker, edition, + persist_doctests, } } @@ -695,6 +724,8 @@ impl Tester for Collector { let maybe_sysroot = self.maybe_sysroot.clone(); let linker = self.linker.clone(); let edition = config.edition.unwrap_or(self.edition); + let persist_doctests = self.persist_doctests.clone(); + debug!("Creating test {}: {}", name, test); self.tests.push(testing::TestDescAndFn { desc: testing::TestDesc { @@ -727,7 +758,8 @@ impl Tester for Collector { &opts, maybe_sysroot, linker, - edition) + edition, + persist_doctests) })) } { Ok(()) => (), From a3f7f97205dc158875228f607effc4f5e35438f8 Mon Sep 17 00:00:00 2001 From: Wesley Norris Date: Sat, 8 Dec 2018 14:22:08 -0500 Subject: [PATCH 2/6] Fix tidy error. --- src/librustdoc/test.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 03b66759d40e1..725d686153156 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -284,8 +284,16 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize, let outdir = Mutex::new( if let Some(mut path) = persist_doctests { - path.push(format!("{}_{}", filename.to_string().rsplit('/').next().unwrap().replace(".", "_"), line)); - std::fs::create_dir_all(&path).expect("Couldn't create directory for doctest executables"); + path.push(format!("{}_{}", + filename + .to_string() + .rsplit('/') + .next() + .unwrap() + .replace(".", "_"), line) + ); + std::fs::create_dir_all(&path) + .expect("Couldn't create directory for doctest executables"); DirState::Perm(path) } else { From 22e97da30ab0d7cf41ec5adb63285ec887e601c3 Mon Sep 17 00:00:00 2001 From: Wesley Norris Date: Sat, 8 Dec 2018 15:50:03 -0500 Subject: [PATCH 3/6] Bless test. --- src/test/rustdoc-ui/failed-doctest-output.stdout | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index d584845e1f2ed..ad3458c8173b2 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -12,7 +12,8 @@ error[E0425]: cannot find value `no` in this scope 3 | no | ^^ not found in this scope -thread '$DIR/failed-doctest-output.rs - OtherStruct (line 17)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:319:13 + +thread '$DIR/failed-doctest-output.rs - OtherStruct (line 27)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:326:13 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. ---- $DIR/failed-doctest-output.rs - SomeStruct (line 11) stdout ---- @@ -21,7 +22,7 @@ thread '$DIR/failed-doctest-output.rs - SomeStruct (line 11)' panicked at 'test thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:3:1 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. -', src/librustdoc/test.rs:354:17 +', src/librustdoc/test.rs:395:17 failures: From 80ee94c1f8640e866840dbcafe76ccdcbfe20fd8 Mon Sep 17 00:00:00 2001 From: Wesley Norris Date: Sun, 16 Dec 2018 17:31:36 -0500 Subject: [PATCH 4/6] Minor changes to wording and formatting. --- src/dlmalloc | 1 + src/libcompiler_builtins | 1 + src/liblibc | 1 + src/librustdoc/config.rs | 3 ++- src/librustdoc/lib.rs | 2 +- src/librustdoc/test.rs | 3 ++- src/test/rustdoc-ui/failed-doctest-output.stdout | 5 ++--- 7 files changed, 10 insertions(+), 6 deletions(-) create mode 160000 src/dlmalloc create mode 160000 src/libcompiler_builtins create mode 160000 src/liblibc diff --git a/src/dlmalloc b/src/dlmalloc new file mode 160000 index 0000000000000..c99638dc2ecfc --- /dev/null +++ b/src/dlmalloc @@ -0,0 +1 @@ +Subproject commit c99638dc2ecfc750cc1656f6edb2bd062c1e0981 diff --git a/src/libcompiler_builtins b/src/libcompiler_builtins new file mode 160000 index 0000000000000..fe74674f6e4be --- /dev/null +++ b/src/libcompiler_builtins @@ -0,0 +1 @@ +Subproject commit fe74674f6e4be76d47b66f67d529ebf4186f4eb1 diff --git a/src/liblibc b/src/liblibc new file mode 160000 index 0000000000000..c75ca6465a139 --- /dev/null +++ b/src/liblibc @@ -0,0 +1 @@ +Subproject commit c75ca6465a139704e00295be355b1f067af2f535 diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 279d3b921345a..1c14dbf1cef8b 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -68,7 +68,7 @@ pub struct Options { pub should_test: bool, /// List of arguments to pass to the test harness, if running tests. pub test_args: Vec, - /// Whether to persist the doctest executables. + /// Otional path to persist the doctest executables to. pub persist_doctests: Option, // Options that affect the documentation process @@ -123,6 +123,7 @@ impl fmt::Debug for Options { .field("lint_cap", &self.lint_cap) .field("should_test", &self.should_test) .field("test_args", &self.test_args) + .field("persist_doctests", &self.persist_doctests) .field("default_passes", &self.default_passes) .field("manual_passes", &self.manual_passes) .field("display_warnings", &self.display_warnings) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 7fe0999bdca50..08bbc95ad6524 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -343,7 +343,7 @@ fn opts() -> Vec { unstable("persist-doctests", |o| { o.optopt("", "persist-doctests", - "Persists the rustdoc test executables", + "Directory to persist doctest executables into", "PATH") }), ] diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 725d686153156..0b9fbc81da626 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -290,7 +290,8 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize, .rsplit('/') .next() .unwrap() - .replace(".", "_"), line) + .replace(".", "_"), + line) ); std::fs::create_dir_all(&path) .expect("Couldn't create directory for doctest executables"); diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index ad3458c8173b2..c54e7be46bb8d 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -12,8 +12,7 @@ error[E0425]: cannot find value `no` in this scope 3 | no | ^^ not found in this scope - -thread '$DIR/failed-doctest-output.rs - OtherStruct (line 27)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:326:13 +thread '$DIR/failed-doctest-output.rs - OtherStruct (line 27)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:361:13 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. ---- $DIR/failed-doctest-output.rs - SomeStruct (line 11) stdout ---- @@ -22,7 +21,7 @@ thread '$DIR/failed-doctest-output.rs - SomeStruct (line 11)' panicked at 'test thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:3:1 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. -', src/librustdoc/test.rs:395:17 +', src/librustdoc/test.rs:396:17 failures: From 09cad1b8a56adce59df92a588e43552dc2f832f0 Mon Sep 17 00:00:00 2001 From: Wesley Norris Date: Mon, 31 Dec 2018 18:05:57 -0500 Subject: [PATCH 5/6] Add book section and fix typo. --- src/dlmalloc | 1 - src/doc/rustdoc/src/unstable-features.md | 4 ++++ src/libcompiler_builtins | 1 - src/liblibc | 1 - src/librustdoc/config.rs | 3 ++- src/librustdoc/lib.rs | 1 + 6 files changed, 7 insertions(+), 4 deletions(-) delete mode 160000 src/dlmalloc delete mode 160000 src/libcompiler_builtins delete mode 160000 src/liblibc diff --git a/src/dlmalloc b/src/dlmalloc deleted file mode 160000 index c99638dc2ecfc..0000000000000 --- a/src/dlmalloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c99638dc2ecfc750cc1656f6edb2bd062c1e0981 diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index 905b06465340a..92ea366686cc8 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -417,3 +417,7 @@ JavaScript, and font files in a single location, rather than duplicating it once (grouping of crate docs generated into the same output directory, like with `cargo doc`). Per-crate files like the search index will still load from the documentation root, but anything that gets renamed with `--resource-suffix` will load from the given path. + +### `--persist-doctests`: persist doctest executables after running + +This feature allows the persistence of the doctest executables to the specified path. \ No newline at end of file diff --git a/src/libcompiler_builtins b/src/libcompiler_builtins deleted file mode 160000 index fe74674f6e4be..0000000000000 --- a/src/libcompiler_builtins +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fe74674f6e4be76d47b66f67d529ebf4186f4eb1 diff --git a/src/liblibc b/src/liblibc deleted file mode 160000 index c75ca6465a139..0000000000000 --- a/src/liblibc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c75ca6465a139704e00295be355b1f067af2f535 diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 1c14dbf1cef8b..635d071b8e061 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -68,7 +68,8 @@ pub struct Options { pub should_test: bool, /// List of arguments to pass to the test harness, if running tests. pub test_args: Vec, - /// Otional path to persist the doctest executables to. + /// Optional path to persist the doctest executables to, defaults to a + /// temporary directory if not set. pub persist_doctests: Option, // Options that affect the documentation process diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 08bbc95ad6524..4bbc01d32de3a 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -340,6 +340,7 @@ fn opts() -> Vec { o.optflag("", "disable-per-crate-search", "disables generating the crate selector on the search box") + }), unstable("persist-doctests", |o| { o.optopt("", "persist-doctests", From f5413cd1e232837775bd8dfc803af4429e8c89c4 Mon Sep 17 00:00:00 2001 From: Wesley Norris Date: Mon, 31 Dec 2018 20:03:33 -0500 Subject: [PATCH 6/6] Bless test. Bless test, remove submodule, and fix book entry. bless test again? maybe it'll work this time... --- src/doc/rustdoc/src/unstable-features.md | 10 +++++++++- src/test/rustdoc-ui/failed-doctest-output.stdout | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index 92ea366686cc8..d3eb8cb3d3b8a 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -420,4 +420,12 @@ renamed with `--resource-suffix` will load from the given path. ### `--persist-doctests`: persist doctest executables after running -This feature allows the persistence of the doctest executables to the specified path. \ No newline at end of file +Using this flag looks like this: + +```bash +$ rustdoc src/lib.rs --test -Z unstable-options --persist-doctests target/rustdoctest +``` + +This flag allows you to keep doctest executables around after they're compiled or run. +Usually, rustdoc will immediately discard a compiled doctest after it's been tested, but +with this option, you can keep those binaries around for farther testing. \ No newline at end of file diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index c54e7be46bb8d..8af05e9ca97b1 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -12,7 +12,7 @@ error[E0425]: cannot find value `no` in this scope 3 | no | ^^ not found in this scope -thread '$DIR/failed-doctest-output.rs - OtherStruct (line 27)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:361:13 +thread '$DIR/failed-doctest-output.rs - OtherStruct (line 17)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:354:13 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. ---- $DIR/failed-doctest-output.rs - SomeStruct (line 11) stdout ---- @@ -21,7 +21,7 @@ thread '$DIR/failed-doctest-output.rs - SomeStruct (line 11)' panicked at 'test thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:3:1 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. -', src/librustdoc/test.rs:396:17 +', src/librustdoc/test.rs:389:17 failures: