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

tests: add nightly test for Protocol Arbitrary impl to assert it covers all the Protocol variants. #76

Merged
merged 4 commits into from
Jan 4, 2023

Conversation

jxs
Copy link
Contributor

@jxs jxs commented Dec 20, 2022

This PR follows both @mxinden and @thomaseizinger on #65.
Tried to add multiple toolchains in a single step but apparently it's not possible.

Test running here

Closes #65

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Very nicely done, I am surprised how clean this came out!


// Assert all `Protocol` variants are covered
// in its `Arbitrary` impl.
#[cfg(nightly)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nicely done! At first I thought that we'd need the rust-version proc macro here but cfgs also work very well!

tests/lib.rs Outdated
@@ -12,6 +12,8 @@ use std::{
str::FromStr,
};

const IMPL_VARIANT_COUNT: u8 = 32;
Copy link
Contributor

Choose a reason for hiding this comment

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

We could make this a const on the type :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ehe I wasn't even aware of that feature, thanks Thomas! ❤️

with:
toolchain: nightly
command: test
args: nightly
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean the nightly args? It's just so we filter and only run the tests with nightly on the name. I tried to think of a way to use the #[cfg(nightly)] but couldn't come with a way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right. Can't we just run all tests? What is the issue with that? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just redundancy, do you suggest then that we only run tests once and with nightly?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think CI time matters much in this repository. In other words, I would assume running tests twice is not an issue.

- name: Nightly Test
uses: actions-rs/cargo@v1
env:
RUSTFLAGS: '--cfg nightly -Zcrate-attr=feature(variant_count)'
Copy link
Contributor

Choose a reason for hiding this comment

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

I forgot that we need to activate features, this is 🔥🔥🔥

via associated constant.
@@ -85,10 +85,14 @@ impl Arbitrary for Ma {
#[derive(PartialEq, Eq, Clone, Debug)]
struct Proto(Protocol<'static>);

impl Proto {
const IMPL_VARIANT_COUNT: u8 = 32;
Copy link
Contributor

Choose a reason for hiding this comment

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

I was actually thinking of directly on the enum as Protocol::VARIANT_COUNT.

I am sure there are also proc-macros for this that we could enable only during testing if this nightly stuff is too fancy 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but Protocol lives in the crate, the VARIANT_COUNT refers to Proto's arbitrary implementation count. Protocol's count is what we get with mem::variant_count you mean implementing it on Protocol in the tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, that would unnecessarily increase the public API. Leave it as is! :)

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Direction looks good to me. Thanks for removing the footgun.

with:
toolchain: nightly
command: test
args: nightly
Copy link
Member

Choose a reason for hiding this comment

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

I don't think CI time matters much in this repository. In other words, I would assume running tests twice is not an issue.

and remove it from the test name
@jxs
Copy link
Contributor Author

jxs commented Jan 3, 2023

Direction looks good to me. Thanks for removing the footgun.

ok thanks, updated!

@mxinden mxinden merged commit 76bcb76 into multiformats:master Jan 4, 2023
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.

tests/lib: Update impl Arbitrary for Proto
3 participants