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

cfg!(test) doesn't seem to work for build.rs #2549

Closed
azerupi opened this issue Apr 7, 2016 · 1 comment
Closed

cfg!(test) doesn't seem to work for build.rs #2549

azerupi opened this issue Apr 7, 2016 · 1 comment

Comments

@azerupi
Copy link
Contributor

azerupi commented Apr 7, 2016

When using a build.rs file, cargo doesn't seem to pass the test flag when cargo test is used.

fn main() {
    if cfg!(test) { ... }
}

Does not work. As a workaround you can use features:

fn main() {
    if cfg!(feature="test") { ... }
}

But it requires you to use cargo test --features=test

@alexcrichton
Copy link
Member

Yeah today build scripts aren't re-run for tests (only for libraries), but I think this is covered by #1581 so closing in favor of that. Thanks for the report though!

dancrossnyc pushed a commit to dancrossnyc/r9 that referenced this issue Feb 10, 2023
there is no way for the build script to know that we are testing,
cfg(test) isn't propagated to the script, so we use the feature "test".

rust-lang/cargo#2549
Signed-off-by: Stefan Hertenberger <[email protected]>
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