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

Fix harness in lib section #2469

Closed

Conversation

TheNeikos
Copy link
Contributor

closes #2305

@TheNeikos TheNeikos force-pushed the fix-harness_in_lib_section branch from fdb213a to ca3bbd2 Compare March 11, 2016 17:45
@TheNeikos
Copy link
Contributor Author

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.

@alexcrichton
Copy link
Member

Thanks! You should be able to add a test with a harness = false and then something like:

#[cfg(test)]
fn main() {
}

(that'll fail to compile if #[cfg(test)] isn't passed)

match self.kind {
TargetKind::Lib(_) => (),
_ => self.harness = harness,
}
Copy link
Member

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?

Copy link
Contributor Author

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() {}");
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@alexcrichton
Copy link
Member

Perhaps --lib is still getting passes somewhere? It may need to be dropped in the case that a test profile is in play

@bors
Copy link
Contributor

bors commented Mar 18, 2016

☔ 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'.
Copy link
Contributor

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.

@alexcrichton
Copy link
Member

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!

@TheNeikos TheNeikos deleted the fix-harness_in_lib_section branch May 16, 2016 18:28
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

Successfully merging this pull request may close these issues.

"Could not execute process (never executed)" with [lib] harness = false
4 participants