Skip to content

Cargo test fails for hello-world #585

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
Eratosthenes opened this issue Jul 22, 2018 · 11 comments
Closed

Cargo test fails for hello-world #585

Eratosthenes opened this issue Jul 22, 2018 · 11 comments

Comments

@Eratosthenes
Copy link

Can anyone help me get hello-world working? Here's what happens when I run cargo test:

$ cargo test
   Compiling hello-world v1.1.0 (file:///Users/nathanrapport/exercism/rust/hello-world)
    Finished dev [unoptimized + debuginfo] target(s) in 3.79s
     Running target/debug/deps/hello_world-3a34f9abc5fed031

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/hello_world-28c0c21555c7c134

running 1 test
error: process didn't exit successfully: `/Users/nathanrapport/exercism/rust/hello-world/target/debug/deps/hello_world-28c0c21555c7c134` (signal: 11, SIGSEGV: invalid memory reference)

I believe I'm on the latest version of rust:

$ rustc --version
rustc 1.27.2 (58cc626de 2018-07-18)

The weird thing is that I can see the executable file sitting there. When I run it, I get this output though:

$ /Users/nathanrapport/exercism/rust/hello-world/target/debug/hello_world-28c0c21555c7c134 ; exit;

running 1 test
Segmentation fault: 11
logout

[Process completed]
@coriolinus
Copy link
Member

@Eratosthenes That's a bizarre error. Would you be willing to paste in the output of cat src/lib.rs?

@Eratosthenes
Copy link
Author

Eratosthenes commented Jul 22, 2018

@coriolinus

$ cat src/lib.rs
// The &'static here means the return type has a static lifetime.
// This is a Rust feature that you don't need to worry about now.
pub fn hello() -> &'static str {
    "Hello, World!"
}

@coriolinus
Copy link
Member

Hmm. I could not replicate this:

$ rustc --version && cargo --version
Sun Jul 22 15:17:38 DST 2018
rustc 1.27.2 (58cc626de 2018-07-18)
cargo 1.27.0 (1e95190e5 2018-05-27)
$ cat src/lib.rs
Sun Jul 22 15:17:50 DST 2018
pub fn hello() -> &'static str {
    "Hello, World!"
}
$ cargo test
Sun Jul 22 15:17:56 DST 2018
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running target/debug/deps/hello_world-034f85fca78591a8

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/hello_world-3a498d4002339e15

running 1 test
test test_hello_world ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests hello-world

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Perhaps something is going on in the tests? My tests/hello-world.rs:

extern crate hello_world;

#[test]
fn test_hello_world() {
    assert_eq!("Hello, World!", hello_world::hello());
}

If that is the same on your machine, then my best bet is that something has gone wrong with your rustc or llvm installations. I'd delete it, and then use rustup to reinstall.

@coriolinus
Copy link
Member

Segmentation faults are the kind of problem that Rust was explicitly designed to prevent, after all. They shouldn't be possible in the absence of unsafe.

@Eratosthenes
Copy link
Author

@coriolinus

Ok, I ran

rustup self uninstall

And then reinstalled rust. Deleted the hello-world directory and tried again. Still getting the exact same error. Maybe the issue is with my version of exercism?

@Eratosthenes
Copy link
Author

Eratosthenes commented Jul 22, 2018

Reinstalled exercism and re-downloaded problem. Still getting the same error.

$ rustc --version && cargo --version && exercism version
rustc 1.27.2 (58cc626de 2018-07-18)
cargo 1.27.0 (1e95190e5 2018-05-27)
exercism version 3.0.5

I'm using Mac OS X 10.10.5 btw.

@coriolinus
Copy link
Member

I really don't know what's going on. Your OS is a bit old, but it's still in the tier 1 supported list. It shouldn't be an exercism issue; this is the rust compiler producing something which segfaults, which shouldn't be a thing. I'll ask you to perform one more test, and if it fails, you should create an issue in the core rust repo.

Try doing this:

$ cd
$ cargo new --bin hello
$ cd hello/

Use your editor of choice to create the following two files:

src/lib.rs:

pub fn hello() -> &'static str {
    "Hello World!"
}

src/main.rs:

extern crate hello;
use hello::hello;

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

Finally, run:

cargo run

This does almost exactly what the exercism hello world exercise does, just in a main function. If this fails with a segfault, it's time to create an issue in the rust main repo. If this succeeds, it's time to create a test file, just like exercism does:

tests/hello.rs:

extern crate hello;
use hello::hello;

#[test]
fn test_hello() {
    assert_eq!(hello(), "Hello World!");
}

Then run:

cargo test

If this succeeds, then I'll be totally stumped: that's doing exactly what exercism does, except in a different path, and we constructed it manually. If it fails, you'll have two different instances you can use to create a bug in the core rust repo.

@Eratosthenes
Copy link
Author

Eratosthenes commented Jul 22, 2018

@coriolinus

Ok, so: In the example above, cargo run works and cargo test fails with the same error:

error: process didn't exit successfully: `/Users/nathanrapport/exercism/hello/target/debug/deps/hello-3b688a67e7111a16` (signal: 11, SIGSEGV: invalid memory reference)

And when I run the executable I get a segmentation fault:

$ target/debug/deps/hello-3b688a67e7111a16

running 1 test
Segmentation fault: 11

@coriolinus
Copy link
Member

coriolinus commented Jul 22, 2018

Fascinating. This is a rust bug unrelated to exercism, and I bet they'd be interested in a bug report at their repo, listing all the steps you've taken and the results you've gotten.

Unfortunately, it also means that we've reached the limit of my own ability to help you. I can't reproduce your issue on either of the machines I have available, which suggests that whatever is going on, it is likely to be machine-specific. If you have another machine available, I suggest moving to that for the rust track exercises.

I'm sorry I couldn't resolve this positively, but there is nothing else I can do.

[edit] fixed rust repo link

@coriolinus
Copy link
Member

FWIW, this appears to be related to rust-lang/rust#52390.

@Eratosthenes
Copy link
Author

Cool... glad I'm not the only one! So, I uninstalled rust again and installed version 1.28.0-beta. Running that version works. Thanks for your help!

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