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

rustc --test should not check linking when using --emit=metadata or -Z no-trans #39948

Open
Wilfred opened this issue Feb 19, 2017 · 6 comments
Labels
A-libtest Area: `#[test]` / the `test` library C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@Wilfred
Copy link
Contributor

Wilfred commented Feb 19, 2017

Suppose I have a library configured with panic = "abort":

$ cargo init --lib foo
$ cd foo
$ nano Cargo.toml
$ more Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = ["Wilfred Hughes <[email protected]>"]

[dependencies]

[profile.dev]
panic = "abort"

I'm unable to build with with --test:

$ cargo rustc -- --test
   Compiling foo v0.1.0 (file:///home/wilfred/tmp/foo)
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`

error: aborting due to previous error

error: Could not compile `foo`.

To learn more, run the command again with --verbose.

As discussed in rust-lang/cargo#3166 (comment) this is because the test harness needs unwinding on panic.

However, I get the same error with -Z no-trans:

$ cargo rustc -- -Z no-trans --test 
   Compiling foo v0.1.0 (file:///home/wilfred/tmp/foo)
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`

error: aborting due to previous error

error: Could not compile `foo`.

To learn more, run the command again with --verbose.

This causes problems in editor integration like flycheck/flycheck-rust#47 . We want to pass --test as otherwise we don't get syntax checking on test files. However, we get the above error for projects with abort-on-panic.

Could we teach --test to ignore the runtime when we pass -Z no-trans?

@steveklabnik
Copy link
Member

-Z no-trans is on its way out, now that we have the meatdata-only crate type, right?

@nagisa
Copy link
Member

nagisa commented Feb 19, 2017

Right; -Z no-trans will likely become an unusable actually unstable flag even before that.

@Wilfred
Copy link
Contributor Author

Wilfred commented Feb 19, 2017

Aha, great to see this stabilising. My understanding from #38666 is that --crate-type=metadata has had a short life (and had issues distinguishing between libraries and applications) and the correct version is now --emit=metadata.

We'll certainly move to --emit=metadata once it lands on stable Rust.

Note that the same problem exists with --emit=metadata though:

$ rustc --version
rustc 1.17.0-nightly (306035c21 2017-02-18)
$ cargo rustc -- --emit=metadata --test
   Compiling abortexample v0.1.0 (file:///home/wilfred/tmp/abortexample)
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`

error: aborting due to previous error

error: Could not compile `abortexample`.

To learn more, run the command again with --verbose.

@Wilfred Wilfred changed the title Support -Z no-trans with panic = "abort" and --test rustc --test should not check linking when using --emit=metadata or -Z no-trans Feb 19, 2017
@Mark-Simulacrum
Copy link
Member

As far as I can tell this works today, so I'm going to close. rustc --emit=metadata -Cpanic=abort --test test.rs works on:

#[test]
fn t() {
    panic!("oh no!");
}

@Wilfred
Copy link
Contributor Author

Wilfred commented May 23, 2017

@Mark-Simulacrum I don't think your test is equivalent. The example from the first comment still fails on current Rust. Could you please reopen?

@Mark-Simulacrum Mark-Simulacrum added the A-libtest Area: `#[test]` / the `test` library label Jun 23, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 27, 2017
@ehuss
Copy link
Contributor

ehuss commented Oct 23, 2019

The intended way to do this with cargo is to use cargo check --profile=test. That forces panic to be unwind in order to be compatible with libtest.

Additionally, once #65710 lands, there is a new flag cargo check --profile=test -Zpanic-abort-tests where it will successfully build with abort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: `#[test]` / the `test` library C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
Status: No status
Development

No branches or pull requests

5 participants