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

chore: make all tests annotated with #[cfg(test)] #9347

Merged
merged 1 commit into from
Feb 1, 2021

Conversation

magurotuna
Copy link
Member

@magurotuna magurotuna commented Jan 31, 2021

This PR annotates the tests that are not annotated currently with #[cfg(test)].

Tests in Rust work fine so long as they are annotated with #[test], but adding #[cfg(test)] attributes to them is more desirable for the reasons described here.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@caspervonb caspervonb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ry
Copy link
Member

ry commented Feb 1, 2021

Thanks for the patch but this is just moving code around without any benefit. There’s nothing wrong with a standalone unit test.

Unless I’m missing something?

closing without merge

@ry ry closed this Feb 1, 2021
@magurotuna
Copy link
Member Author

@ry
In general, adding #[cfg(test)] would lead to faster compile time and less size of resulting artifact. Although this patch is so small that it will make a trivial improvement, I'm sure that small things add up to make a big difference. I'd be grateful if you could reconsider.

@ry
Copy link
Member

ry commented Feb 1, 2021

@magurotuna #[test] are only compiled under the test feature, right?

@ry ry reopened this Feb 1, 2021
@magurotuna
Copy link
Member Author

@ry No, #[test] just tells cargo to run these functions when running cargo test command. With #[test] only, those functions would also be compiled even when not compiled under test feature.

The following paragraph quoted from the book provides clear explanation:

The #[cfg(test)] annotation on the tests module tells Rust to compile and run the test code only when you run cargo test, not when you run cargo build. This saves compile time when you only want to build the library and saves space in the resulting compiled artifact because the tests are not included. You’ll see that because integration tests go in a different directory, they don’t need the #[cfg(test)] annotation. However, because unit tests go in the same files as the code, you’ll use #[cfg(test)] to specify that they shouldn’t be included in the compiled result.

@ry ry merged commit 84f8b87 into denoland:master Feb 1, 2021
@ry
Copy link
Member

ry commented Feb 1, 2021

@magurotuna Ok - I remain skeptical but I can't figure out where the test attribute is implemented and can't prove otherwise. It's an innocent change regardless.

@magurotuna magurotuna deleted the cfg-test branch February 2, 2021 04:04
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.

None yet

4 participants