primitives: Add an API test module#4078
Conversation
70978e7 to
e576550
Compare
tcharding
left a comment
There was a problem hiding this comment.
ooph, this was pending from yesterday.
primitives/tests/api.rs
Outdated
| // If this builds then traits are dyn compatible. | ||
| struct Traits { | ||
| // a: Box<dyn block::Validation>, | ||
| } |
There was a problem hiding this comment.
Hey @Kixunil I went digging for your simplified suggestion and I couldn't find it. Flagging that I wasn't ignoring you my memory is just failing me right now.
There was a problem hiding this comment.
Just define an #[allow(unused)] function that takes _: &dyn Trait.
e576550 to
8341c3f
Compare
8341c3f to
b6bf31c
Compare
| // `Debug` representation is never empty (C-DEBUG-NONEMPTY). | ||
| #[test] | ||
| fn api_all_non_error_types_have_non_empty_debug() { | ||
| macro_rules! check_debug { |
There was a problem hiding this comment.
would not_empty be an accurate name also?
There was a problem hiding this comment.
or debug_not_empty anyway can also just ignore my comment here.
| transaction.compute_wtxid(); | ||
| transaction.version; | ||
| Witness::arbitrary(&mut u).unwrap(); | ||
| // ad: witness::Iter<'a>, |
There was a problem hiding this comment.
why the ad comment here?
There was a problem hiding this comment.
Oh this is a hangover from when there were more than 26 and I used ad as a variable name. Your comment made me remember that I forgot to fix all the local var names after removing a bunch of stuff yesterday (during rebase). Thanks
| // We abuse `Arbitrary` here to get a quick and dirty instance. | ||
| let ab: [u8; 32] = [0xab; 32]; | ||
| let mut u = arbitrary::Unstructured::new(&ab); | ||
| let transaction = Transaction::arbitrary(&mut u).unwrap(); |
There was a problem hiding this comment.
should this belong in checked_debug!? Interesting idea to abuse Arbitrary like this to create random test data, although is this just testing Arbitrary? It doesn't appear to be testing that debug is not empty.
There was a problem hiding this comment.
This variable is used below.
| //! | ||
| //! The point of these tests are to check the API surface as opposed to test the API functionality. | ||
| //! | ||
| //! ref: <https://rust-lang.github.io/api-guidelines/about.html> |
There was a problem hiding this comment.
Maybe it's more worthwhile to call out what section(s) of the api-guidelines this is addressing.
There was a problem hiding this comment.
There are comments in the code eg C-DEBUG
b6bf31c to
d845272
Compare
|
Thanks for the review. Rebased and fixed single letter variable names. |
primitives/tests/api.rs
Outdated
| a: absolute::LockTime, | ||
| b: relative::LockTime, | ||
| // block::Checked, // Empty enums are not constructable. | ||
| // block::Unchecked, |
There was a problem hiding this comment.
In d845272:
We should uncomment these. They don't need to be constructible for the API tests.
ccf93cf to
c80cff3
Compare
c80cff3 to
4759942
Compare
|
I had a few review suggestion. |
There is no obvious reason why the witness iterator cannot be cloned.
In preparation for 1.0-ing `primitives` add an `api` test module that makes an effort to verify the API surface. This is similar to what is in `units` and what is in development for `hashes` (in rust-bitcoin#4017).
4759942 to
e2d9a8a
Compare
|
Rebased and feature gated the whole test on |
|
Part of me thinks we should have non- |
In preparation for 1.0-ing
primitivesadd anapitest module that makes an effort to verify the API surface.This is similar to what is in
unitsand what is in development forhashes(in #4017).Note, there is a WIP attempt at this in #3992.
Close: #3928