Rollup merge of #85833 - willcrichton:example-analyzer, r=jyn514
Scrape code examples from examples/ directory for Rustdoc Adds support for the functionality described in https://github.com/rust-lang/rfcs/pull/3123 Matching changes to Cargo are here: https://github.com/rust-lang/cargo/pull/9525 Live demo here: https://willcrichton.net/example-analyzer/warp/trait.Filter.html#method.and
This commit is contained in:
commit
dcf9242795
38 changed files with 1104 additions and 30 deletions
|
|
@ -0,0 +1,5 @@
|
|||
deps := ex ex2
|
||||
|
||||
-include ./scrape.mk
|
||||
|
||||
all: scrape
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
foobar::ok();
|
||||
foobar::ok();
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
foobar::ok();
|
||||
}
|
||||
20
src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk
Normal file
20
src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk
Normal file
|
|
@ -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
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]//*[@class="prev"]' ''
|
||||
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' ''
|
||||
|
||||
pub fn ok() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
deps := ex1 ex2
|
||||
|
||||
-include ../rustdoc-scrape-examples-multiple/scrape.mk
|
||||
|
||||
all: scrape
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fn main() {
|
||||
foobar::ok();
|
||||
|
||||
// this is a
|
||||
|
||||
// BIG
|
||||
|
||||
// item
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
foobar::ok();
|
||||
// small item
|
||||
}
|
||||
|
|
@ -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() {}
|
||||
5
src/test/run-make/rustdoc-scrape-examples-remap/Makefile
Normal file
5
src/test/run-make/rustdoc-scrape-examples-remap/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
deps := ex
|
||||
|
||||
-include ../rustdoc-scrape-examples-multiple/scrape.mk
|
||||
|
||||
all: scrape
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
foobar::b::foo();
|
||||
foobar::c::foo();
|
||||
}
|
||||
1
src/test/run-make/rustdoc-scrape-examples-remap/src/a.rs
Normal file
1
src/test/run-make/rustdoc-scrape-examples-remap/src/a.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub fn foo() {}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// @has foobar/b/fn.foo.html '//*[@class="scraped-example expanded"]' 'ex.rs'
|
||||
// @has foobar/c/fn.foo.html '//*[@class="scraped-example expanded"]' 'ex.rs'
|
||||
|
||||
#[path = "a.rs"]
|
||||
pub mod b;
|
||||
|
||||
#[path = "a.rs"]
|
||||
pub mod c;
|
||||
1
src/test/rustdoc-ui/scrape-examples-wrong-options-1.rs
Normal file
1
src/test/rustdoc-ui/scrape-examples-wrong-options-1.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
// compile-flags: -Z unstable-options --scrape-examples-target-crate foobar
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
error: must use --scrape-examples-output-path and --scrape-examples-target-crate together
|
||||
|
||||
1
src/test/rustdoc-ui/scrape-examples-wrong-options-2.rs
Normal file
1
src/test/rustdoc-ui/scrape-examples-wrong-options-2.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
// compile-flags: -Z unstable-options --scrape-examples-output-path ex.calls
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
error: must use --scrape-examples-output-path and --scrape-examples-target-crate together
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue