]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: only filter lines starting with '# ' from the shown code.
authorHuon Wilson <dbau.pp+github@gmail.com>
Sat, 28 Dec 2013 23:54:56 +0000 (10:54 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 30 Dec 2013 05:55:49 +0000 (16:55 +1100)
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.

doc/rustdoc.md
src/librustdoc/html/markdown.rs
src/librustdoc/test.rs
src/test/run-make/rustdoc-hidden-line/Makefile [new file with mode: 0644]
src/test/run-make/rustdoc-hidden-line/foo.rs [new file with mode: 0644]
src/test/run-make/rustdoc-hidden-line/verify.sh [new file with mode: 0755]

index 39fc03bca0d1ef0e54b6be04522eae86d7674d3f..16bcf8d6dd857cdd26328fdae189f23609edd43e 100644 (file)
@@ -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
index 6fd83af3b2e760c7bac51f97b571be70a38a84aa..f445e11aa02039ac040f7635d7140c293b1ca677 100644 (file)
@@ -101,7 +101,7 @@ pub fn render(w: &mut io::Writer, s: &str) {
             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("#")
+                    !l.trim().starts_with("# ")
                 });
                 let text = lines.to_owned_vec().connect("\n");
 
@@ -169,7 +169,9 @@ 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| {
+                            if l.starts_with("# ") {l.slice_from(2)} else {l}
+                        });
                 let text = lines.to_owned_vec().connect("\n");
                 tests.add_test(text, ignore, shouldfail);
             })
index 9462f8118ba655c43ba7d5ba9cc20011c6e29081..60e4643991039a4e1cbf463d53abadad80220e15 100644 (file)
@@ -171,6 +171,7 @@ pub fn add_test(&mut self, test: &str, ignore: bool, should_fail: bool) {
         self.cnt += 1;
         let libs = (*self.libs).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 (file)
index 0000000..7e6f8fe
--- /dev/null
@@ -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 (file)
index 0000000..69c7683
--- /dev/null
@@ -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 (executable)
index 0000000..c1d817c
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+file="$1/doc/foo/fn.foo.html"
+
+grep -v 'invisible' $file &&
+grep '#\[deriving(Eq)\] // Bar' $file
+
+exit $?