<p dir="auto">The feature that captures "stdout" for tests doesn't capture all the ways that a test could print to stdout.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#[test]
fn output_capture_tests() {
    println!(&quot;This gets captured...&quot;);
    let _ = std::io::stdout().write_line(&quot;but this does not...&quot;);
    let _ = std::task::try(proc() { println!(&quot;..and neither does this...&quot;) });
    let _ = std::run::process_status(&quot;/bin/echo&quot;, [~&quot;...nor this...&quot;]);
    fail!();
}"><pre class="notranslate"><span class="pl-c1">#<span class="pl-kos">[</span>test<span class="pl-kos">]</span></span>
<span class="pl-k">fn</span> <span class="pl-en">output_capture_tests</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"This gets captured..."</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> _ = std<span class="pl-kos">::</span>io<span class="pl-kos">::</span><span class="pl-en">stdout</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">write_line</span><span class="pl-kos">(</span><span class="pl-s">"but this does not..."</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> _ = std<span class="pl-kos">::</span>task<span class="pl-kos">::</span><span class="pl-en">try</span><span class="pl-kos">(</span><span class="pl-en">proc</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"..and neither does this..."</span><span class="pl-kos">)</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> _ = std<span class="pl-kos">::</span>run<span class="pl-kos">::</span><span class="pl-en">process_status</span><span class="pl-kos">(</span><span class="pl-s">"/bin/echo"</span><span class="pl-kos">,</span> <span class="pl-kos">[</span>~"...nor this...<span class="pl-s">"</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">fail</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Only the first <code class="notranslate">println!</code> call gets captured--the rest appear intermingled with the test output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="running 1 test
but this does not...
..and neither does this...
...nor this...
test output_capture_tests ... FAILED

failures:

---- output_capture_tests stdout ----
    This gets captured...
    task 'output_capture_tests' failed at 'explicit failure', subproc-test-stdout.rs:7


failures:
    output_capture_tests

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured"><pre class="notranslate"><code class="notranslate">running 1 test
but this does not...
..and neither does this...
...nor this...
test output_capture_tests ... FAILED

failures:

---- output_capture_tests stdout ----
    This gets captured...
    task 'output_capture_tests' failed at 'explicit failure', subproc-test-stdout.rs:7


failures:
    output_capture_tests

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
</code></pre></div>
<p dir="auto">It would be nice if all of these got captured.</p>
<p dir="auto">I've filed this bug in <a href="https://github.com/rust-lang/cargo/issues/4129" data-hovercard-type="issue" data-hovercard-url="/rust-lang/cargo/issues/4129/hovercard">rust-lang/cargo</a> but I'm afraid rust-lang/rust is the correct repo for this.</p>
<p dir="auto">I ran the tests for one of my crates that uses threads in its example code. I've noticed it printed some lines to stdout, even though <code class="notranslate">--nocapture</code> wasn't set, but not all of them. It appears that text printed from new threads are not correctly captured, I think this is not intended.</p>
<h2 dir="auto">Reproduce</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#[cfg(test)]
mod tests {
    use std::thread;
    use std::time::Duration;

    #[test]
    fn it_works() {
        thread::spawn(move || {
            println!(&quot;request: {:?}&quot;, 123);
        });

        thread::sleep(Duration::from_secs(1));
        println!(&quot;response: {:?}&quot;, 456);
    }"><pre class="notranslate"><code class="notranslate">#[cfg(test)]
mod tests {
    use std::thread;
    use std::time::Duration;

    #[test]
    fn it_works() {
        thread::spawn(move || {
            println!("request: {:?}", 123);
        });

        thread::sleep(Duration::from_secs(1));
        println!("response: {:?}", 456);
    }
</code></pre></div>
<h2 dir="auto">Output</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="running 2 tests
request: 123
test tests::it_works ... ok
[...]"><pre class="notranslate"><code class="notranslate">running 2 tests
request: 123
test tests::it_works ... ok
[...]
</code></pre></div>
<h2 dir="auto">Meta</h2>
<p dir="auto"><code class="notranslate">rustc --version --verbose</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rustc 1.17.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.17.0
LLVM version: 4.0"><pre class="notranslate"><code class="notranslate">rustc 1.17.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.17.0
LLVM version: 4.0
</code></pre></div>