-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix harness in lib section #2469
Conversation
fdb213a
to
ca3bbd2
Compare
I have to admit I made this somewhat 'blindly' as I did not find a way to correctly test the part where I pass the cfg. If someone can point me to a way to do it. I will try to think of something nonetheless. |
Thanks! You should be able to add a test with a #[cfg(test)]
fn main() {
} (that'll fail to compile if |
match self.kind { | ||
TargetKind::Lib(_) => (), | ||
_ => self.harness = harness, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I may be forgetting now, but this should be ok, right? If we pass --cfg test
then a library can have its own custom test harness/main function, so it seems legitimate that harness = false
could work for a library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If harness == false
then there is no binary produced. I have not been able to find out why that is, but the error goes similar to the linked issue.
name = "foo" | ||
harness = false | ||
"#) | ||
.file("src/lib.rs", "#[cfg(test)] fn main() {}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexcrichton Is this how you meant it? I understood it as being the entrypoint of the test harness in this case.
However #[cfg(foo)]
also passes. So I am a bit confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah you'll want to remove the hardcoded check I commented on above, then it should fail for #[cfg(foo)]
and this should pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restoring the old functionality of the function you commented about still makes it pass with #[cfg(foo)]
I have pushed some changes to see if I modified it how wanted it to.
Perhaps |
☔ The latest upstream changes (presumably #2493) made this pull request unmergeable. Please resolve the merge conflicts. |
# If set to false, `cargo test` will omit the --test flag to rustc, which stops | ||
# it from generating a test harness. This is useful when the binary being built | ||
# manages the test runner itself. | ||
# manages the test runner itself. It will still pass the cfg feature 'test'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, please change the straight quotes around test to backticks.
I did some investigation to try to land this, but it's unfortunately blocked by rust-lang/rust#33670, so I'm going to close this for now. Thanks though for the PR @TheNeikos! |
closes #2305