From b1616f34efc5bc0d0328c1bba94176c62be2b3d0 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Fri, 8 Oct 2021 20:49:05 -0700 Subject: [PATCH] Add test for ordering of examples, simplify with single scrape.mk file --- .../rustdoc-scrape-examples-multiple/Makefile | 22 +++--------------- .../scrape.mk | 20 ++++++++++++++++ .../src/lib.rs | 2 +- .../rustdoc-scrape-examples-ordering/Makefile | 5 ++++ .../examples/ex1.rs | 9 ++++++++ .../examples/ex2.rs | 4 ++++ .../src/lib.rs | 4 ++++ .../rustdoc-scrape-examples-remap/Makefile | 23 +++---------------- 8 files changed, 49 insertions(+), 40 deletions(-) create mode 100644 src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk create mode 100644 src/test/run-make/rustdoc-scrape-examples-ordering/Makefile create mode 100644 src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex1.rs create mode 100644 src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex2.rs create mode 100644 src/test/run-make/rustdoc-scrape-examples-ordering/src/lib.rs diff --git a/src/test/run-make/rustdoc-scrape-examples-multiple/Makefile b/src/test/run-make/rustdoc-scrape-examples-multiple/Makefile index 68d78ae3017..897805e4405 100644 --- a/src/test/run-make/rustdoc-scrape-examples-multiple/Makefile +++ b/src/test/run-make/rustdoc-scrape-examples-multiple/Makefile @@ -1,21 +1,5 @@ --include ../../run-make-fulldeps/tools.mk +deps := ex ex2 -OUTPUT_DIR := "$(TMPDIR)/rustdoc" +-include ./scrape.mk -all: $(TMPDIR)/ex.calls $(TMPDIR)/ex2.calls - $(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR) \ - -Z unstable-options \ - --with-examples $(TMPDIR)/ex.calls \ - --with-examples $(TMPDIR)/ex2.calls - - $(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs - -$(TMPDIR)/%.calls: $(TMPDIR)/libfoobar.rmeta - $(RUSTDOC) examples/$*.rs --crate-name $* --crate-type bin --output $(OUTPUT_DIR) \ - --extern foobar=$(TMPDIR)/libfoobar.rmeta \ - -Z unstable-options \ - --scrape-examples-output-path $@ \ - --scrape-examples-target-crate foobar - -$(TMPDIR)/lib%.rmeta: src/lib.rs - $(RUSTC) src/lib.rs --crate-name $* --crate-type lib --emit=metadata +all: scrape diff --git a/src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk b/src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk new file mode 100644 index 00000000000..1fa1fae1a0b --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk @@ -0,0 +1,20 @@ +-include ../../run-make-fulldeps/tools.mk + +OUTPUT_DIR := "$(TMPDIR)/rustdoc" + +$(TMPDIR)/%.calls: $(TMPDIR)/libfoobar.rmeta + $(RUSTDOC) examples/$*.rs --crate-name $* --crate-type bin --output $(OUTPUT_DIR) \ + --extern foobar=$(TMPDIR)/libfoobar.rmeta \ + -Z unstable-options \ + --scrape-examples-output-path $@ \ + --scrape-examples-target-crate foobar + +$(TMPDIR)/lib%.rmeta: src/lib.rs + $(RUSTC) src/lib.rs --crate-name $* --crate-type lib --emit=metadata + +scrape: $(foreach d,$(deps),$(TMPDIR)/$(d).calls) + $(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR) \ + -Z unstable-options \ + $(foreach d,$(deps),--with-examples $(TMPDIR)/$(d).calls) + + $(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs diff --git a/src/test/run-make/rustdoc-scrape-examples-multiple/src/lib.rs b/src/test/run-make/rustdoc-scrape-examples-multiple/src/lib.rs index b26122a37e2..bd59584bbbf 100644 --- a/src/test/run-make/rustdoc-scrape-examples-multiple/src/lib.rs +++ b/src/test/run-make/rustdoc-scrape-examples-multiple/src/lib.rs @@ -1,4 +1,4 @@ -// @has foobar/fn.ok.html '//*[@class="prev"]' '' +// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]//*[@class="prev"]' '' // @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' '' pub fn ok() {} diff --git a/src/test/run-make/rustdoc-scrape-examples-ordering/Makefile b/src/test/run-make/rustdoc-scrape-examples-ordering/Makefile new file mode 100644 index 00000000000..339d539bfd5 --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-ordering/Makefile @@ -0,0 +1,5 @@ +deps := ex1 ex2 + +-include ../rustdoc-scrape-examples-multiple/scrape.mk + +all: scrape diff --git a/src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex1.rs b/src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex1.rs new file mode 100644 index 00000000000..d6d59820876 --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex1.rs @@ -0,0 +1,9 @@ +fn main() { + foobar::ok(); + + // this is a + + // BIG + + // item +} diff --git a/src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex2.rs b/src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex2.rs new file mode 100644 index 00000000000..a1133117f86 --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex2.rs @@ -0,0 +1,4 @@ +fn main() { + foobar::ok(); + // small item +} diff --git a/src/test/run-make/rustdoc-scrape-examples-ordering/src/lib.rs b/src/test/run-make/rustdoc-scrape-examples-ordering/src/lib.rs new file mode 100644 index 00000000000..f1b7686d368 --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-ordering/src/lib.rs @@ -0,0 +1,4 @@ +// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]' 'ex2' +// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' 'ex1' + +pub fn ok() {} diff --git a/src/test/run-make/rustdoc-scrape-examples-remap/Makefile b/src/test/run-make/rustdoc-scrape-examples-remap/Makefile index 9903c87be23..dce8b83eefe 100644 --- a/src/test/run-make/rustdoc-scrape-examples-remap/Makefile +++ b/src/test/run-make/rustdoc-scrape-examples-remap/Makefile @@ -1,22 +1,5 @@ --include ../../run-make-fulldeps/tools.mk +deps := ex -OUTPUT_DIR := "$(TMPDIR)/rustdoc" +-include ../rustdoc-scrape-examples-multiple/scrape.mk -all: -# 1. compile the library crate and emit an rmeta - $(RUSTC) src/lib.rs --crate-name foobar --crate-type lib --emit=metadata - -# 2. scrape examples from the reverse-dependency into an ex.calls file - $(RUSTDOC) examples/ex.rs --crate-name ex --crate-type bin --output $(OUTPUT_DIR) \ - --extern foobar=$(TMPDIR)/libfoobar.rmeta \ - -Z unstable-options \ - --scrape-examples-output-path $(TMPDIR)/ex.calls \ - --scrape-examples-target-crate foobar - -# 3. pass those examples to rustdoc when documenting the library crate - $(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR) \ - -Z unstable-options \ - --with-examples $(TMPDIR)/ex.calls - -# 4. check that the examples were scraped successfully - $(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs +all: scrape