about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-10-23 14:58:39 +0200
committerGitHub <noreply@github.com>2021-10-23 14:58:39 +0200
commitdcf9242795fdd0be3873492fb36f77533dbf017c (patch)
tree15474e950bd74b1db9c7cd5f62681b11fa2944ff /src/test
parent55ccbd090d96ec3bb28dbcb383e65bbfa3c293ff (diff)
parentfd5d614b7708c2bbd0a7c796af3c3b63f31a19ac (diff)
downloadrust-dcf9242795fdd0be3873492fb36f77533dbf017c.tar.gz
rust-dcf9242795fdd0be3873492fb36f77533dbf017c.zip
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
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-multiple/Makefile5
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-multiple/examples/ex.rs4
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-multiple/examples/ex2.rs3
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk20
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-multiple/src/lib.rs4
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-ordering/Makefile5
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex1.rs9
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex2.rs4
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-ordering/src/lib.rs4
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-remap/Makefile5
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-remap/examples/ex.rs4
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-remap/src/a.rs1
-rw-r--r--src/test/run-make/rustdoc-scrape-examples-remap/src/lib.rs8
-rw-r--r--src/test/rustdoc-ui/scrape-examples-wrong-options-1.rs1
-rw-r--r--src/test/rustdoc-ui/scrape-examples-wrong-options-1.stderr2
-rw-r--r--src/test/rustdoc-ui/scrape-examples-wrong-options-2.rs1
-rw-r--r--src/test/rustdoc-ui/scrape-examples-wrong-options-2.stderr2
17 files changed, 82 insertions, 0 deletions
diff --git a/src/test/run-make/rustdoc-scrape-examples-multiple/Makefile b/src/test/run-make/rustdoc-scrape-examples-multiple/Makefile
new file mode 100644
index 00000000000..897805e4405
--- /dev/null
+++ b/src/test/run-make/rustdoc-scrape-examples-multiple/Makefile
@@ -0,0 +1,5 @@
+deps := ex ex2
+
+-include ./scrape.mk
+
+all: scrape
diff --git a/src/test/run-make/rustdoc-scrape-examples-multiple/examples/ex.rs b/src/test/run-make/rustdoc-scrape-examples-multiple/examples/ex.rs
new file mode 100644
index 00000000000..01b730c6149
--- /dev/null
+++ b/src/test/run-make/rustdoc-scrape-examples-multiple/examples/ex.rs
@@ -0,0 +1,4 @@
+fn main() {
+    foobar::ok();
+    foobar::ok();
+}
diff --git a/src/test/run-make/rustdoc-scrape-examples-multiple/examples/ex2.rs b/src/test/run-make/rustdoc-scrape-examples-multiple/examples/ex2.rs
new file mode 100644
index 00000000000..f83cf2f2709
--- /dev/null
+++ b/src/test/run-make/rustdoc-scrape-examples-multiple/examples/ex2.rs
@@ -0,0 +1,3 @@
+fn main() {
+    foobar::ok();
+}
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
new file mode 100644
index 00000000000..bd59584bbbf
--- /dev/null
+++ b/src/test/run-make/rustdoc-scrape-examples-multiple/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() {}
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
new file mode 100644
index 00000000000..dce8b83eefe
--- /dev/null
+++ b/src/test/run-make/rustdoc-scrape-examples-remap/Makefile
@@ -0,0 +1,5 @@
+deps := ex
+
+-include ../rustdoc-scrape-examples-multiple/scrape.mk
+
+all: scrape
diff --git a/src/test/run-make/rustdoc-scrape-examples-remap/examples/ex.rs b/src/test/run-make/rustdoc-scrape-examples-remap/examples/ex.rs
new file mode 100644
index 00000000000..1438fdba707
--- /dev/null
+++ b/src/test/run-make/rustdoc-scrape-examples-remap/examples/ex.rs
@@ -0,0 +1,4 @@
+fn main() {
+    foobar::b::foo();
+    foobar::c::foo();
+}
diff --git a/src/test/run-make/rustdoc-scrape-examples-remap/src/a.rs b/src/test/run-make/rustdoc-scrape-examples-remap/src/a.rs
new file mode 100644
index 00000000000..b76b4321d62
--- /dev/null
+++ b/src/test/run-make/rustdoc-scrape-examples-remap/src/a.rs
@@ -0,0 +1 @@
+pub fn foo() {}
diff --git a/src/test/run-make/rustdoc-scrape-examples-remap/src/lib.rs b/src/test/run-make/rustdoc-scrape-examples-remap/src/lib.rs
new file mode 100644
index 00000000000..f525a4270dd
--- /dev/null
+++ b/src/test/run-make/rustdoc-scrape-examples-remap/src/lib.rs
@@ -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;
diff --git a/src/test/rustdoc-ui/scrape-examples-wrong-options-1.rs b/src/test/rustdoc-ui/scrape-examples-wrong-options-1.rs
new file mode 100644
index 00000000000..a1f005c32ee
--- /dev/null
+++ b/src/test/rustdoc-ui/scrape-examples-wrong-options-1.rs
@@ -0,0 +1 @@
+// compile-flags: -Z unstable-options --scrape-examples-target-crate foobar
diff --git a/src/test/rustdoc-ui/scrape-examples-wrong-options-1.stderr b/src/test/rustdoc-ui/scrape-examples-wrong-options-1.stderr
new file mode 100644
index 00000000000..eb8e9f79968
--- /dev/null
+++ b/src/test/rustdoc-ui/scrape-examples-wrong-options-1.stderr
@@ -0,0 +1,2 @@
+error: must use --scrape-examples-output-path and --scrape-examples-target-crate together
+
diff --git a/src/test/rustdoc-ui/scrape-examples-wrong-options-2.rs b/src/test/rustdoc-ui/scrape-examples-wrong-options-2.rs
new file mode 100644
index 00000000000..4aacec7f094
--- /dev/null
+++ b/src/test/rustdoc-ui/scrape-examples-wrong-options-2.rs
@@ -0,0 +1 @@
+// compile-flags: -Z unstable-options --scrape-examples-output-path ex.calls
diff --git a/src/test/rustdoc-ui/scrape-examples-wrong-options-2.stderr b/src/test/rustdoc-ui/scrape-examples-wrong-options-2.stderr
new file mode 100644
index 00000000000..eb8e9f79968
--- /dev/null
+++ b/src/test/rustdoc-ui/scrape-examples-wrong-options-2.stderr
@@ -0,0 +1,2 @@
+error: must use --scrape-examples-output-path and --scrape-examples-target-crate together
+