about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-12-30 05:51:51 -0800
committerbors <bors@rust-lang.org>2013-12-30 05:51:51 -0800
commita4f30bf0c001034b855e79b72676667deb6db463 (patch)
tree755c3cc3c99094c3482b9d1853372e254eaf7da3
parentf37b746699c377bce4a983834efe5162081a61dd (diff)
parentdedc29f128e2c87237ba4dea2dd0337e00f1320c (diff)
downloadrust-a4f30bf0c001034b855e79b72676667deb6db463.tar.gz
rust-a4f30bf0c001034b855e79b72676667deb6db463.zip
auto merge of #11185 : huonw/rust/doc-ignore, r=cmr
Currently any line starting with `#` is filtered from the output,
including line like `#[deriving]`; this patch makes it so lines are only
filtered when followed by a space similar to the current behaviour of
the tutorial/manual tester.
-rw-r--r--doc/rustdoc.md7
-rw-r--r--src/librustdoc/html/markdown.rs19
-rw-r--r--src/librustdoc/test.rs1
-rw-r--r--src/test/run-make/rustdoc-hidden-line/Makefile7
-rw-r--r--src/test/run-make/rustdoc-hidden-line/foo.rs22
-rwxr-xr-xsrc/test/run-make/rustdoc-hidden-line/verify.sh8
6 files changed, 57 insertions, 7 deletions
diff --git a/doc/rustdoc.md b/doc/rustdoc.md
index 684c1040535..ea87077b119 100644
--- a/doc/rustdoc.md
+++ b/doc/rustdoc.md
@@ -132,9 +132,10 @@ specifiers that can be used to dictate how a code block is tested:
 ~~~
 
 Rustdoc also supplies some extra sugar for helping with some tedious
-documentation examples. If a line is prefixed with a `#` character, then the
-line will not show up in the HTML documentation, but it will be used when
-testing the code block.
+documentation examples. If a line is prefixed with `# `, then the line
+will not show up in the HTML documentation, but it will be used when
+testing the code block (NB. the space after the `#` is required, so
+that one can still write things like `#[deriving(Eq)]`).
 
 ~~~
 ```rust
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 6fd83af3b2e..5da087eedbd 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -94,15 +94,26 @@ extern {
 
 }
 
+/// Returns Some(code) if `s` is a line that should be stripped from
+/// documentation but used in example code. `code` is the portion of
+/// `s` that should be used in tests. (None for lines that should be
+/// left as-is.)
+fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> {
+    let trimmed = s.trim();
+    if trimmed.starts_with("# ") {
+        Some(trimmed.slice_from(2))
+    } else {
+        None
+    }
+}
+
 pub fn render(w: &mut io::Writer, s: &str) {
     extern fn block(ob: *buf, text: *buf, lang: *buf, opaque: *libc::c_void) {
         unsafe {
             let my_opaque: &my_opaque = cast::transmute(opaque);
             vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
                 let text = str::from_utf8(text);
-                let mut lines = text.lines().filter(|l| {
-                    !l.trim().starts_with("#")
-                });
+                let mut lines = text.lines().filter(|l| stripped_filtered_line(*l).is_none());
                 let text = lines.to_owned_vec().connect("\n");
 
                 let buf = buf {
@@ -169,7 +180,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
             vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
                 let tests: &mut ::test::Collector = intrinsics::transmute(opaque);
                 let text = str::from_utf8(text);
-                let mut lines = text.lines().map(|l| l.trim_chars(&'#'));
+                let mut lines = text.lines().map(|l| stripped_filtered_line(l).unwrap_or(l));
                 let text = lines.to_owned_vec().connect("\n");
                 tests.add_test(text, ignore, shouldfail);
             })
diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs
index 7450abf3415..e5ec3661b61 100644
--- a/src/librustdoc/test.rs
+++ b/src/librustdoc/test.rs
@@ -173,6 +173,7 @@ impl Collector {
         let libs = self.libs.borrow();
         let libs = (*libs.get()).clone();
         let cratename = self.cratename.to_owned();
+        debug!("Creating test {}: {}", name, test);
         self.tests.push(test::TestDescAndFn {
             desc: test::TestDesc {
                 name: test::DynTestName(name),
diff --git a/src/test/run-make/rustdoc-hidden-line/Makefile b/src/test/run-make/rustdoc-hidden-line/Makefile
new file mode 100644
index 00000000000..7e6f8fe105e
--- /dev/null
+++ b/src/test/run-make/rustdoc-hidden-line/Makefile
@@ -0,0 +1,7 @@
+-include ../tools.mk
+
+all:
+	$(RUSTDOC) --test foo.rs
+	$(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
+	cp verify.sh $(TMPDIR)
+	$(call RUN,verify.sh) $(TMPDIR)
diff --git a/src/test/run-make/rustdoc-hidden-line/foo.rs b/src/test/run-make/rustdoc-hidden-line/foo.rs
new file mode 100644
index 00000000000..69c7683780b
--- /dev/null
+++ b/src/test/run-make/rustdoc-hidden-line/foo.rs
@@ -0,0 +1,22 @@
+#[crate_id="foo#0.1"];
+
+/// The '# ' lines should be removed from the output, but the #[deriving] should be
+/// retained.
+///
+/// ```rust
+/// mod to_make_deriving_work { // FIXME #4913
+///
+/// # #[deriving(Eq)] // invisible
+/// # struct Foo; // invisible
+///
+/// #[deriving(Eq)] // Bar
+/// struct Bar(Foo);
+///
+/// fn test() {
+///     let x = Bar(Foo);
+///     assert!(x == x); // check that the derivings worked
+/// }
+///
+/// }
+/// ```
+pub fn foo() {}
diff --git a/src/test/run-make/rustdoc-hidden-line/verify.sh b/src/test/run-make/rustdoc-hidden-line/verify.sh
new file mode 100755
index 00000000000..c1d817c998d
--- /dev/null
+++ b/src/test/run-make/rustdoc-hidden-line/verify.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+file="$1/doc/foo/fn.foo.html"
+
+grep -v 'invisible' $file &&
+grep '#\[deriving(Eq)\] // Bar' $file
+
+exit $?