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

Add PathBuf Arbitrary impl with tests #368

Merged
merged 2 commits into from
Sep 18, 2023

Conversation

sunshowers
Copy link
Contributor

@sunshowers sunshowers commented Sep 1, 2023

Followup to #362. Includes documentation. I'm pretty new to this and I had to cargo-cult a bit so please point out issues!

Thanks to Michael for starting work on this!

Followup to proptest-rs#362. Includes documentation.

Thanks to Michael for starting work on this!

Co-authored-by: Michael Dougherty <maackle.d@gmail.com>
@sunshowers
Copy link
Contributor Author

sunshowers commented Sep 1, 2023

For me a number of tests failed, I'm not sure why: https://gist.github.com/sunshowers/5ad72397fe70205bbb27cae534d65443#file-gistfile0-txt-L4551-L4685

But those tests also failed for me on main.

(This is with cargo +nightly nextest run --no-fail-fast on cargo 1.74.0-nightly (2cc50bc0b 2023-08-22). I also saw cargo test fail with a similar number of tests but nextest prints out the full list of failed tests at the end)

@sunshowers
Copy link
Contributor Author

sunshowers commented Sep 11, 2023

I have a feeling this isn't quite correct. I think it might generate paths that are too long.

Going to try looking at it later this week.


fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
static_map(
(any::<bool>(), any_with::<Vec<OsString>>(args)),
Copy link
Member

Choose a reason for hiding this comment

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

i'm not familiar with the OsString arbitrary impl but I'm wondering if it can generate a string with a delimiter in it. will pull this locally and mess around more. otherwise this looks good.

Copy link
Member

Choose a reason for hiding this comment

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

OsString strategy does indeed generate strings with the delimiter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's okay, the number of delimiters is not a hard and fast rule here.

I'm more concerned about the number of components being too large by default.

I'm wondering if we should define a PathParameters struct with a custom default value for the number of delimiters.

Copy link
Member

Choose a reason for hiding this comment

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

I did notice that quite a few components were getting generated. I think a PathParameters struct with a default number and ensuring the output has that number (which may involve trimming any excess generated) could make sense. I think it'd be an un-intuitive if a user asks for n segments and we give them n + m.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. You're welcome to work on it, or I'll get around to it at some point later this week (speaking at RustConf in 3 days 😅)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@matthew-russo OK, done. Let me know if this makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry work and personal life have kept me quite busy so I missed your last message. Thanks for getting back to this and congrats on the talk!

Copy link
Member

@matthew-russo matthew-russo left a comment

Choose a reason for hiding this comment

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

lgtm. thanks for the contribution!


arbitrary!(StripPrefixError; Path::new("").strip_prefix("a").unwrap_err());

/// A private type (not actually pub) representing the output of [`PathParams`] that can't be
Copy link
Member

Choose a reason for hiding this comment

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

non-blocking: it is actually pub(?) not sure if this just means it isn't intended to be publicly used or if this is residual from previous iterations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant that even though it is pub, it is not exported as an API so that backwards compatibility is maintained. Any suggestions for better phrasing?

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 its a huge deal either way. I would probably just say something like:
"An opaque type representing the output of ...

Copy link
Collaborator

@rex-remind101 rex-remind101 left a comment

Choose a reason for hiding this comment

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

this all looks good to me 👍

@matthew-russo matthew-russo merged commit e395e8c into proptest-rs:master Sep 18, 2023
5 checks passed
@sunshowers sunshowers deleted the arbitrary-pathbuf branch September 21, 2023 05:37
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.

3 participants