Skip to content

rustdoc pads spaces in doctest multiline string literals #25944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sru opened this issue Jun 1, 2015 · 2 comments
Closed

rustdoc pads spaces in doctest multiline string literals #25944

sru opened this issue Jun 1, 2015 · 2 comments
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@sru
Copy link

sru commented Jun 1, 2015

When using multiline string literal in doctest, rustdoc pads spaces after the newline. The doc renders perfectly fine:

screen shot 2015-06-01 at 12 15 37 pm

I tried this code:

//! Hello world.
//!
//! # Examples
//!
//! ```rust
//! let s = "
//! Hello
//! World";
//! assert_eq!("\nHello\nWorld", s);
//! ```
//!
//! ```rust
//! let s = r#"
//! Hello
//! World"#;
//! assert_eq!("\nHello\nWorld", s);
//! ```

fn main() {
    println!("hello world!");
}

I expected to see this happen: The test should pass.

Instead, this happened: The test failed.

running 2 tests
test _0 ... FAILED
test _1 ... FAILED

failures:

---- _0 stdout ----
    thread '_0' panicked at 'test executable failed:

thread '<main>' panicked at 'assertion failed: `(left == right)` (left: `"\nHello\nWorld"`, right: `"\n    Hello\n    World"`)', <anon>:5
', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustdoc/test.rs:255


---- _1 stdout ----
    thread '_1' panicked at 'test executable failed:

thread '<main>' panicked at 'assertion failed: `(left == right)` (left: `"\nHello\nWorld"`, right: `"\n    Hello\n    World"`)', <anon>:5
', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustdoc/test.rs:255



failures:
    _0
    _1

test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured
"\n    Hello\n    World"

Did you notice it?

Meta

rustc --version --verbose:

rustc 1.2.0-nightly (9cb7b3ffb 2015-06-01) (built 2015-05-31)
binary: rustc
commit-hash: 9cb7b3ffb6522a5fa4d3666b5859d4122c918e44
commit-date: 2015-06-01
build-date: 2015-05-31
host: x86_64-apple-darwin
release: 1.2.0-nightly

rustdoc --version --verbose:

rustdoc 1.2.0-nightly (9cb7b3ffb 2015-06-01) (built 2015-05-31)
binary: rustdoc
commit-hash: 9cb7b3ffb6522a5fa4d3666b5859d4122c918e44
commit-date: 2015-06-01
build-date: 2015-05-31
host: x86_64-apple-darwin
release: 1.2.0-nightly

Backtrace (I don't know if it'd be useful, but):

running 2 tests
test _1 ... FAILED
test _0 ... FAILED

failures:

---- _1 stdout ----
    thread '_1' panicked at 'test executable failed:

thread '<main>' panicked at 'assertion failed: `(left == right)` (left: `"\nHello\nWorld"`, right: `"\n    Hello\n    World"`)', <anon>:5
stack backtrace:
   1:        0x100d057b5 - sys::backtrace::write::h6ede916059f8deceM9r
   2:        0x100d0e754 - panicking::on_panic::ha49f13d0ffb0f10e2uw
   3:        0x100cc8948 - rt::unwind::begin_unwind_inner::hf0bdcaef6fa2453akdw
   4:        0x100cc974c - rt::unwind::begin_unwind_fmt::h040c464af8329e70qcw
   5:        0x100cba5b1 - main::hfc3806f6c4ab636deaa
   6:        0x100d96bf8 - rust_try_inner
   7:        0x100d96be5 - rust_try
   8:        0x100d0f1d0 - rt::lang_start::h5cc5e69c1f0d126e6pw
   9:        0x100cbac2e - main
', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustdoc/test.rs:255

stack backtrace:
   1:        0x109c997b5 - sys::backtrace::write::h6ede916059f8deceM9r
   2:        0x109ca23f0 - panicking::on_panic::ha49f13d0ffb0f10e2uw
   3:        0x109c5c948 - rt::unwind::begin_unwind_inner::hf0bdcaef6fa2453akdw
   4:        0x109c5d74c - rt::unwind::begin_unwind_fmt::h040c464af8329e70qcw
   5:        0x105fd28ee - test::runtest::h7eeaa468bba23544cJt
   6:        0x105fd7633 - boxed::F.FnBox<A>::call_box::h15201770880915052160
   7:        0x1062c52ff - boxed::F.FnBox<A>::call_box::h12651187332831451207
   8:        0x1062c2af7 - rt::unwind::try::try_fn::h7876007015214846326
   9:        0x109d2abf8 - rust_try_inner
  10:        0x109d2abe5 - rust_try
  11:        0x109c8c315 - rt::unwind::try::inner_try::hc500934c7d7e0757d9v
  12:        0x1062c2d52 - boxed::F.FnBox<A>::call_box::h17944427202448439759
  13:        0x109ca0eed - sys::thread::Thread::new::thread_start::h5ee5677e14d769eaMxv
  14:     0x7fff870cc898 - _pthread_body
  15:     0x7fff870cc729 - _pthread_start

---- _0 stdout ----
    thread '_0' panicked at 'test executable failed:

thread '<main>' panicked at 'assertion failed: `(left == right)` (left: `"\nHello\nWorld"`, right: `"\n    Hello\n    World"`)', <anon>:5
stack backtrace:
   1:        0x1057357b5 - sys::backtrace::write::h6ede916059f8deceM9r
   2:        0x10573e754 - panicking::on_panic::ha49f13d0ffb0f10e2uw
   3:        0x1056f8948 - rt::unwind::begin_unwind_inner::hf0bdcaef6fa2453akdw
   4:        0x1056f974c - rt::unwind::begin_unwind_fmt::h040c464af8329e70qcw
   5:        0x1056e85b1 - main::h3811a6db7063b18feaa
   6:        0x1057c6bf8 - rust_try_inner
   7:        0x1057c6be5 - rust_try
   8:        0x10573f1d0 - rt::lang_start::h5cc5e69c1f0d126e6pw
   9:        0x1056e8c2e - main
', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustdoc/test.rs:255

stack backtrace:
   1:        0x109c997b5 - sys::backtrace::write::h6ede916059f8deceM9r
   2:        0x109ca23f0 - panicking::on_panic::ha49f13d0ffb0f10e2uw
   3:        0x109c5c948 - rt::unwind::begin_unwind_inner::hf0bdcaef6fa2453akdw
   4:        0x109c5d74c - rt::unwind::begin_unwind_fmt::h040c464af8329e70qcw
   5:        0x105fd28ee - test::runtest::h7eeaa468bba23544cJt
   6:        0x105fd7633 - boxed::F.FnBox<A>::call_box::h15201770880915052160
   7:        0x1062c52ff - boxed::F.FnBox<A>::call_box::h12651187332831451207
   8:        0x1062c2af7 - rt::unwind::try::try_fn::h7876007015214846326
   9:        0x109d2abf8 - rust_try_inner
  10:        0x109d2abe5 - rust_try
  11:        0x109c8c315 - rt::unwind::try::inner_try::hc500934c7d7e0757d9v
  12:        0x1062c2d52 - boxed::F.FnBox<A>::call_box::h17944427202448439759
  13:        0x109ca0eed - sys::thread::Thread::new::thread_start::h5ee5677e14d769eaMxv
  14:     0x7fff870cc898 - _pthread_body
  15:     0x7fff870cc729 - _pthread_start


failures:
    _0
    _1

test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured

thread '<unnamed>' panicked at 'Some tests failed', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libtest/lib.rs:255
stack backtrace:
   1:        0x109c997b5 - sys::backtrace::write::h6ede916059f8deceM9r
   2:        0x109ca2754 - panicking::on_panic::ha49f13d0ffb0f10e2uw
   3:        0x109c5c948 - rt::unwind::begin_unwind_inner::hf0bdcaef6fa2453akdw
   4:        0x10629d43f - rt::unwind::begin_unwind::h16661391803926304236
   5:        0x1062a088e - test_main::h4adc4874d4cee238R0a
   6:        0x105fc9890 - test::run::ha93ed6fea45d1225kCt
   7:        0x105fdd955 - main_args::hfa89131528ad43189fu
   8:        0x105fda0f5 - boxed::F.FnBox<A>::call_box::h543229893963805859
   9:        0x105fd9257 - rt::unwind::try::try_fn::h8218846930259623130
  10:        0x109d2abf8 - rust_try_inner
  11:        0x109d2abe5 - rust_try
  12:        0x109c8c315 - rt::unwind::try::inner_try::hc500934c7d7e0757d9v
  13:        0x105fd94d7 - boxed::F.FnBox<A>::call_box::h132574837825853843
  14:        0x109ca0eed - sys::thread::Thread::new::thread_start::h5ee5677e14d769eaMxv
  15:     0x7fff870cc898 - _pthread_body
  16:     0x7fff870cc729 - _pthread_start
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: Any', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libcore/result.rs:729
stack backtrace:
   1:        0x109c997b5 - sys::backtrace::write::h6ede916059f8deceM9r
   2:        0x109ca2754 - panicking::on_panic::ha49f13d0ffb0f10e2uw
   3:        0x109c5c948 - rt::unwind::begin_unwind_inner::hf0bdcaef6fa2453akdw
   4:        0x109c5d74c - rt::unwind::begin_unwind_fmt::h040c464af8329e70qcw
   5:        0x109ca1f4c - rust_begin_unwind
   6:        0x109cf6cb5 - panicking::panic_fmt::he351326af800e539i5B
   7:        0x105fd8e1c - main::h7b823c409ceca183Wbu
   8:        0x109d2abf8 - rust_try_inner
   9:        0x109d2abe5 - rust_try
  10:        0x109ca31d0 - rt::lang_start::h5cc5e69c1f0d126e6pw
@aochagavia
Copy link
Contributor

I hit this issue today as well with a similar case

@steveklabnik steveklabnik added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jun 8, 2015
@bltavares
Copy link
Contributor

Triaging: This is still happening on rustdoc 1.9.0-nightly (5ab11d72c 2016-04-02)

birkenfeld added a commit to birkenfeld/rust that referenced this issue May 9, 2016
This makes the examples look nicer when printed (when is this
done?), but breaks tests using multi-line string literals.

Fixes: rust-lang#25944
bors added a commit that referenced this issue May 11, 2016
rustdoc: remove artificial indentation of doctest code

The indentation makes the examples look nicer when printed (when is this done?), but breaks tests using multi-line string literals.

Fixes: #25944
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants