fix(identity): fix test when no features are enabled
Description
On master branch the test for identity when they are no features enabled are currently broken. See
cargo test --package libp2p-identity
# or
cd identity/
cargo test
This PR add the required #[cfg()] to make the test pass.
Change checklist
Not sure if we need a changelog entry for something this small
- [x] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] A changelog entry has been made in the appropriate crates
The danger here is that you are accidentally excluding tests with bad feature flags so the never actually run despite being there in the code.
So those test should be fixed if they have bad features flags? I can do so in this PR if you want. If in the future somebody add a test with bad features flags, it will quickly see if it's not running
The silver bullet here will be to go with a tool like cargo hack to test the combination of features, but while that's happening, the proposed solution + a pass to ensure tests have not bad feature flags, should do the job, in my opinion.
If in the future somebody add a test with bad features flags, it will quickly see if it's not running
How? I can write a test that is feature-gated on #[cfg(feature = "ed2519")] (notice the typo?) and the test will never run if the crate doesn't provide an ed2519 feature.
Cargo does not warn about the use of features which are not defined in the manifest because they are just passed down to rustc and rustc has no knowledge of Cargo.toml files.
To be on the safe side, we shouldn't feature flag tests I think.
How? I can write a test that is feature-gated on #[cfg(feature = "ed2519")] (notice the typo?) and the test will never run if the crate doesn't provide an ed2519 feature.
Intuitively I would have said that the next thing people do when writing a test is to run it, so they will detect the typo.
Anyway, maybe we should wait for https://github.com/rust-lang/rfcs/pull/3013 to be stabilized then?