invariants such as unused bits being unset is not checked very well. Important functions are tested pretty well as a side effect of testing their overflowing counterparts, but I would like to have a concise way to test invariants at every unwrap in fuzz.rs.
unwraps use up a lot of space. Replacing them all with ? makes fuzz.rs much cleaner, but the problem is that I do not know what line errors come from. There is a backtrace function planned for Error, but there may be several months yet before it arrives in nightly.
This is not urgent, but I would prefer to fix the invariant problem at least before a new release of apint.
I am thinking about making a free function that checks all invariants and unwraps the results at the same time. As an example, it would change this:
Not much of an improvement, but at least invariants are checked. The only way I can think of which improves it more is doing evil stuff with feature flags, such as changing the Result type in the crate into something else which implements the Try trait. Maybe we could have a the feature flag change have #[cfg(feature_flag)] on the mod fuzz; (removing fuzz.rs entirely during any other compilation, so that users of the crate do not experience weird stuff when running with test).
The less weird stuff we are doing with feature flags though, the better. fuzz.rs is not intended to be very friendly to the eyes anyway, so I believe the free function approach is best.
There are two problems I have right now:
unwrap
infuzz.rs
.unwrap
s use up a lot of space. Replacing them all with?
makesfuzz.rs
much cleaner, but the problem is that I do not know what line errors come from. There is abacktrace
function planned forError
, but there may be several months yet before it arrives in nightly.This is not urgent, but I would prefer to fix the invariant problem at least before a new release of
apint
.I am thinking about making a free function that checks all invariants and unwraps the results at the same time. As an example, it would change this:
into this:
Not much of an improvement, but at least invariants are checked. The only way I can think of which improves it more is doing evil stuff with feature flags, such as changing the
Result
type in the crate into something else which implements theTry
trait. Maybe we could have a the feature flag change have#[cfg(feature_flag)]
on themod fuzz;
(removingfuzz.rs
entirely during any other compilation, so that users of the crate do not experience weird stuff when running withtest
).The less weird stuff we are doing with feature flags though, the better.
fuzz.rs
is not intended to be very friendly to the eyes anyway, so I believe the free function approach is best.