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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Examples and fc.context() are incompatible 馃悰 #3459

Closed
tskj opened this issue Dec 8, 2022 · 2 comments
Closed

Custom Examples and fc.context() are incompatible 馃悰 #3459

tskj opened this issue Dec 8, 2022 · 2 comments

Comments

@tskj
Copy link
Contributor

tskj commented Dec 8, 2022

馃悰 Bug Report

Like this issue describes, it is currently not possible to use fc.context() (in my usecase for logging) with custom examples. Both custom examples and logging are extremely useful and good features, and as a user I would expect them to either be compatible, or for the docs to clearly warn about their incompatibility.

To Reproduce

Like the code in the aforementioned issue describes, attempt to use custom examples in a property that uses fc.context():

fc.assert(
  fc.property(fc.string(), fc.context(), (str, ctx) => /* ... */),
  { examples: [["x", /* what here? */]] }
);

Expected behavior

Ideally it would always be possible to copy-paste the counter examples that fast-check outputs when finding a failing test case into your test code.

That is the behavior that new users expect, and would be a very good user experience. Not being able to do that feels broken and seems like a bug in the library.

Suggestions

There are many ways to square these incompatibilities, one very crude way to fix this would be to use the suggested code from the other issue:

const buildContext = () => fc.sample(fc.context(), {numRuns:1})[0];

and simply output this along with the counter examples when fast-check sees that one of the example values is a Context. Kind of like the following:

...
Property failed after 1 test:
{ seed: ...
Counterexample: [ '', () => fc.sample(fc.context(), {numRuns:1})[0] ]
Shrunk 0 time(s)
...

I'm sure there also are better technical solutions, but which presumably require more work. Either way, I think a prinicple to strive for is for the counter examples that are outputted by fast-check itself to not be broken.

If we don't want to fix the library itself, I think at least there should be added to the docs an explanation of how the user can fix it themselves. I have created a PR for this here, using the buildContext function.

As an alternative if we don't want the buildContext implementation to be an "official" suggestion, I have also created a different PR here, which at the very least explains the incompatibility and warns the user.

@stale
Copy link

stale bot commented Mar 12, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 12, 2023
@dubzzz dubzzz removed the stale label Mar 12, 2023
@dubzzz
Copy link
Owner

dubzzz commented Mar 12, 2023

Let's close it for now. The documentation has been adapted for future users

@dubzzz dubzzz closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants