-
Notifications
You must be signed in to change notification settings - Fork 305
Enable test with --no-default-features #386
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
Conversation
33a6fb5 to
b20302e
Compare
When building with --no-default-features the compiler emits: warning: unused import: `mem` The call site is feature gated so we either need to feature gate the import or use a fully qualified path. Since 'core' is quite short elect to use the fully qualified path.
bfc5721 to
38b5128
Compare
The `Debug` implementation for secrets is feature gated on `std` because it uses a hasher from `std`. If `bitcoin_hashes` is enabled we can use it for hashing. If neither `std` nor `bitcoin_hashes` is enabled fall back to outputting: <secret requires std or bitcoin_hashes feature to display> Remove the docs conditional since we now implement `Debug` always.
f086f7d to
755bde2
Compare
The examples depend on having the "std" feature [1]. In preparation for being able to run tests with `--no-default-features` add the "std" feature as a requirement for all three examples. While we are at it use the correct rand feature requirement: `rand-std`. [1] Technically we only need "alloc" but "alloc" is not working with Rust 1.29 currently so just use "std".
Currently various features fail to build when enabled without default features. This is because many tests need feature gating. Feature gating the import statements quickly turns into spaghetti when trying to cover all combinations of two features correctly, instead just allow unused imports on `tests` modules where needed. Add correct feature requirements to the examples so they also can be run without default features. Improve the CI script by doing: - Add `std` to the feature matrix. - Add `--no-default-features` to test runs in the CI script.
Various combinations of features trigger lint warnings for unused code, all warnings are caused by incorrect feature gating. Correct feature gating to remove Clippy warnings during testing.
Seems there is a bug in cargo, the tests in `key.rs` run successfully
but AFAICT they should fail. Here is an example, running `cargo test
--features=rand` should make this test fail but it doesn't?
```
/// Secret 256-bit key used as `x` in an ECDSA signature.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1, SecretKey};
///
/// let secp = Secp256k1::new();
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
/// # }
/// ```
Anywho, use the correct feature gate: `rand-std`.
755bde2 to
f3688ec
Compare
|
Oh lordy me, it passed CI! |
|
I think |
src/schnorr.rs
Outdated
| let kp = KeyPair::from_seckey_slice(&secp, &SK_BYTES).expect("sk"); | ||
|
|
||
| // In fuzzing mode secret->public key derivation is different, so | ||
| // hard-code the epected result. |
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.
In ae3e06f:
Typo expected. (I know this is just moved code but we might as well fix it here)
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.
Ha, there were three instances of this typo. I fixed them all as an additional patch. Cheers.
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.
ACK f3688ec
Thanks for this!
Fix minor spelling mistake in code comments.
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.
ACK c30026d
…features
c30026d08b5489386af1048936d457f04785a34a Fix typo 'epected' -> 'expected' (Tobin Harding)
f3688ecf5690a3a1b3738745a1ca244f3778fc60 Use rand-std in key rustdoc examples (Tobin Harding)
ae3e06f95b7a7394c450bc8103738df9d79773f6 Fix lint warnings in test code (Tobin Harding)
c01cd8f1f34e74f2dacd2094e815486a87f6d934 Enable running tests without default features (Tobin Harding)
a79840eca202682d13555820d98d2e4e9747b5bc Be explicit about example feature requirements (Tobin Harding)
433c350424718d91037bb1a1db5ea175d70c63a8 Add multiple implementations of Debug for secrets (Tobin Harding)
632ecc4530a05baa34585fc9975a4264065735fa Use fully qualified path for mem (Tobin Harding)
Pull request description:
As indicated by the comment in `contrib/test.sh` we should be able to test with `--no-default-features`.
- Patch 1 uses fully qualified path to remove a build warning.
- Patch 2 adds additional `Debug` implementations for secrets, uses `bitcoin_hashes` if available, please review carefully.
- Patch 3 adds `std` as an explicit requirement for the three examples
- Patch 4 enables `cargo test --no-default-features, fixes all the feature gating in unit tests.
- Patch 5 fixes lint warnings generated while running the feature matrix in `contrib/test.sh`.
**Please Note**: Currently the `alloc` feature cannot be built with Rust 1.29, this made it into master because we don't build ever with the `alloc` feature enabled in CI. This PR _should_ add `alloc` to the features matrix but it does not. Adds a TODO comment to `contrib/test.sh` to add it once we bump MSRV.
ACKs for top commit:
apoelstra:
ACK c30026d08b5489386af1048936d457f04785a34a
Tree-SHA512: 3bbdda332ab1e04eaa3479d9e9c7463a54347f56019ce5366bb36eb8d5ccaced32539e2c58454a7714d76b7bab9f1ab56accb04de67c826165dd104ac0b3b893
…features
c30026d08b5489386af1048936d457f04785a34a Fix typo 'epected' -> 'expected' (Tobin Harding)
f3688ecf5690a3a1b3738745a1ca244f3778fc60 Use rand-std in key rustdoc examples (Tobin Harding)
ae3e06f95b7a7394c450bc8103738df9d79773f6 Fix lint warnings in test code (Tobin Harding)
c01cd8f1f34e74f2dacd2094e815486a87f6d934 Enable running tests without default features (Tobin Harding)
a79840eca202682d13555820d98d2e4e9747b5bc Be explicit about example feature requirements (Tobin Harding)
433c350424718d91037bb1a1db5ea175d70c63a8 Add multiple implementations of Debug for secrets (Tobin Harding)
632ecc4530a05baa34585fc9975a4264065735fa Use fully qualified path for mem (Tobin Harding)
Pull request description:
As indicated by the comment in `contrib/test.sh` we should be able to test with `--no-default-features`.
- Patch 1 uses fully qualified path to remove a build warning.
- Patch 2 adds additional `Debug` implementations for secrets, uses `bitcoin_hashes` if available, please review carefully.
- Patch 3 adds `std` as an explicit requirement for the three examples
- Patch 4 enables `cargo test --no-default-features, fixes all the feature gating in unit tests.
- Patch 5 fixes lint warnings generated while running the feature matrix in `contrib/test.sh`.
**Please Note**: Currently the `alloc` feature cannot be built with Rust 1.29, this made it into master because we don't build ever with the `alloc` feature enabled in CI. This PR _should_ add `alloc` to the features matrix but it does not. Adds a TODO comment to `contrib/test.sh` to add it once we bump MSRV.
ACKs for top commit:
apoelstra:
ACK c30026d08b5489386af1048936d457f04785a34a
Tree-SHA512: 3bbdda332ab1e04eaa3479d9e9c7463a54347f56019ce5366bb36eb8d5ccaced32539e2c58454a7714d76b7bab9f1ab56accb04de67c826165dd104ac0b3b893
As indicated by the comment in
contrib/test.shwe should be able to test with--no-default-features.Debugimplementations for secrets, usesbitcoin_hashesif available, please review carefully.stdas an explicit requirement for the three examplescontrib/test.sh.Please Note: Currently the
allocfeature cannot be built with Rust 1.29, this made it into master because we don't build ever with theallocfeature enabled in CI. This PR should addallocto the features matrix but it does not. Adds a TODO comment tocontrib/test.shto add it once we bump MSRV.