Skip to content

Commit ad3407f

Browse files
committed
Auto merge of #88269 - prconrad:doctest-persist-binaries, r=jyn514
Doctest persist full binaries when persisting Tested by adding an extra debug to echo the whole compiler line. Trimmed significantly: Persisted but not running -> full compile so we get binaries (new behavior). ``` $ rustdoc -Zunstable-options --test --persist-doctests doctests --no-run --extern t=libt.rlib t.rs DEBUG rustdoc::doctest run_test compiler "rustc" "--crate-type" "bin" "--edition" "2015" "-o" "doctests/t_rs_8_0/rust_out" "--extern" "t=libt.rlib" "-Ccodegen-units=1" "-Z" "unstable-options" "--target" "x86_64-unknown-linux-gnu" "--color" "always" DEBUG rustdoc::doctest run_test compiler "rustc" "--crate-type" "bin" "--edition" "2015" "-o" "doctests/t_rs_2_0/rust_out" "--extern" "t=libt.rlib" "-Ccodegen-units=1" "-Z" "unstable-options" "--target" "x86_64-unknown-linux-gnu" "--color" "always" test t.rs - foople (line 2) - compile ... ok test t.rs - florp (line 8) - compile ... ok ``` Persisted and running -> full compile. ``` $ rustdoc -Zunstable-options --test --persist-doctests doctests --extern t=libt.rlib t.rs DEBUG rustdoc::doctest run_test compiler "rustc" "--crate-type" "bin" "--edition" "2015" "-o" "doctests/t_rs_8_0/rust_out" "--extern" "t=libt.rlib" "-Ccodegen-units=1" "-Z" "unstable-options" "--target" "x86_64-unknown-linux-gnu" "--color" "always" DEBUG rustdoc::doctest run_test compiler "rustc" "--crate-type" "bin" "--edition" "2015" "-o" "doctests/t_rs_2_0/rust_out" "--extern" "t=libt.rlib" "-Ccodegen-units=1" "-Z" "unstable-options" "--target" "x86_64-unknown-linux-gnu" "--color" "always" ``` Running but not persisted -> full compile only ``` $ rustdoc --test --extern t=libt.rlib t.rs DEBUG rustdoc::doctest run_test compiler "rustc" "--crate-type" "bin" "--edition" "2015" "-o" "/tmp/rustdoctestixWAUI/rust_out" "--extern" "t=libt.rlib" "-Ccodegen-units=1" "--target" "x86_64-unknown-linux-gnu" "--color" "always" DEBUG rustdoc::doctest run_test compiler "rustc" "--crate-type" "bin" "--edition" "2015" "-o" "/tmp/rustdoctestKEaJQu/rust_out" "--extern" "t=libt.rlib" "-Ccodegen-units=1" "--target" "x86_64-unknown-linux-gnu" "--color" "always" ``` Not running and not persisting -> save time and only run metadata. ``` RUSTDOC_LOG=rustdoc=debug,std::test=debug rustdoc -Zunstable-options --no-run --test --extern t=libt.rlib t.rs DEBUG rustdoc::doctest run_test compiler "rustc" "--crate-type" "bin" "--edition" "2015" "-o" "/tmp/rustdoctest8twt2c/rust_out" "--extern" "t=libt.rlib" "-Ccodegen-units=1" "-Z" "unstable-options" "--emit=metadata" "--target" "x86_64-unknown-linux-gnu" "--color" "always" DEBUG rustdoc::doctest run_test compiler "rustc" "--crate-type" "bin" "--edition" "2015" "-o" "/tmp/rustdoctest3miSqv/rust_out" "--extern" "t=libt.rlib" "-Ccodegen-units=1" "-Z" "unstable-options" "--emit=metadata" "--target" "x86_64-unknown-linux-gnu" "--color" "always" ``` I can't see any infrastructure for automating this sort of test. Am I missing it?
2 parents 00ce166 + cfe2d30 commit ad3407f

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn run_test(
361361
for debugging_option_str in &options.debugging_opts_strs {
362362
compiler.arg("-Z").arg(&debugging_option_str);
363363
}
364-
if no_run && !compile_fail {
364+
if no_run && !compile_fail && options.persist_doctests.is_none() {
365365
compiler.arg("--emit=metadata");
366366
}
367367
compiler.arg("--target").arg(match target {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
include ../../run-make-fulldeps/tools.mk
2+
3+
# Check that valid binaries are persisted by running them, regardless of whether the --run or --no-run option is used.
4+
5+
all: run no_run
6+
7+
run:
8+
mkdir -p $(TMPDIR)/doctests
9+
$(RUSTC) --crate-type rlib t.rs
10+
$(RUSTDOC) -Zunstable-options --test --persist-doctests $(TMPDIR)/doctests --extern t=$(TMPDIR)/libt.rlib t.rs
11+
$(TMPDIR)/doctests/t_rs_2_0/rust_out
12+
$(TMPDIR)/doctests/t_rs_8_0/rust_out
13+
rm -rf $(TMPDIR)/doctests
14+
15+
no_run:
16+
mkdir -p $(TMPDIR)/doctests
17+
$(RUSTC) --crate-type rlib t.rs
18+
$(RUSTDOC) -Zunstable-options --test --persist-doctests $(TMPDIR)/doctests --extern t=$(TMPDIR)/libt.rlib t.rs --no-run
19+
$(TMPDIR)/doctests/t_rs_2_0/rust_out
20+
$(TMPDIR)/doctests/t_rs_8_0/rust_out
21+
rm -rf $(TMPDIR)/doctests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// Fungle the foople.
2+
/// ```
3+
/// t::foople();
4+
/// ```
5+
pub fn foople() {}
6+
7+
/// Flomble the florp
8+
/// ```
9+
/// t::florp();
10+
/// ```
11+
pub fn florp() {}

0 commit comments

Comments
 (0)