Skip to content
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

Test runner interacts badly with redirected child process #2936

Closed
BartMassey opened this issue Jul 31, 2016 · 3 comments
Closed

Test runner interacts badly with redirected child process #2936

BartMassey opened this issue Jul 31, 2016 · 3 comments

Comments

@BartMassey
Copy link
Contributor

Consider the code at https://gitlab.com/BartMassey/ptyknot/tree/pipes-direct/misc/piperef-rs . The relevant portion is in piperef.rs:

        ...
       // Write "hello world" to stdout.                                       
        match write_mode {
            WriteMode::Macro => {println!("hello world");},
            WriteMode::C => {
                let buf = "hello world".as_bytes();
                let hello = std::ffi::CString::new(buf).unwrap();
                let bufptr = hello.as_ptr() as *const libc::c_void;
                check_cint!(libc::write(1, bufptr, buf.len()));
            }
        }
         ....

This code is run in a child process. When it is invoked by running it after cargo build, it works fine regardless of whether Macro or C mode is used. When it is invoked by cargo test, C mode works but Macro mode fails with an empty string. When it is invoked by cargo test -- --nocapture, both modes work again. Here's a transcript:

$ cargo build
   Compiling libc v0.2.14
   Compiling piperef v0.1.0 (file:///usr/local/src/ptyknot/misc/piperef-rs)
$ target/debug/piperef 
$ cargo test
   Compiling piperef v0.1.0 (file:///usr/local/src/ptyknot/misc/piperef-rs)
     Running target/debug/piperef-80efeb997239b2ac

running 2 tests
test write_macro_test ... FAILED$<2>
test write_c_test ... ok$<2>

failures:

---- write_macro_test stdout ----
    thread 'write_macro_test' panicked at 'assertion failed: `(left == right)` (left: `""`, right: `"hello world"`)', piperef.rs:60
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    write_macro_test

test result: FAILED$<2>. 1 passed; 1 failed; 0 ignored; 0 measured

error: test failed
$ cargo test -- --nocapture
     Running target/debug/piperef-80efeb997239b2ac

running 2 tests
test write_macro_test ... ok
test write_c_test ... ok

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

$ 

It looks like the test runner is fouling up the environment somehow, but I can't figure out how by looking at stuff.

@alexcrichton
Copy link
Member

Thanks for the report! I think that this actually has to do with the test harness in the standard library rather than Cargo itself, could you open up a bug against rust-lang/rust with these contents?

@BartMassey
Copy link
Contributor Author

BartMassey commented Jul 31, 2016

Now filed as rust-lang/rust#35136 . Thanks!

@alexcrichton
Copy link
Member

Ok, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants