Closed ymotongpoo closed 3 years ago
When creating an array/slice the implementation indeed does not keep a copy, so if the array is changed by the test-function the report will be messed up.
Since there is a lot of reflection involved at this point, this is actually no so easy to fix. I'll take a look into it.
FYI: I'm currently experimenting with creating deep clones for the function parameters: https://github.com/leanovate/gopter/tree/deep_clone
It already solves your problem, but I'm not sure about the performance impact.
Here is an alternative solution: https://github.com/leanovate/gopter/tree/serialize_early
In this case the output is:
! Non-zero length small int slice: Falsified after 1 passed tests.
ARG_0: [0 5 0]
ARG_0_ORIGINAL (1 shrinks): [0 7 5]
I.e. the shrinker still goes slightly haywire because the slice is modified by the test function, but at least the arguments are reported correctly.
I'd rather prefer this solution as it has less impact on the existing runtime. Deep cloning of arbitrary interfaces in go is pretty messy and might cause a lot of trouble.
Thank you, @untoldwind for the experiments and sharing the result from them. The latter option, i.e. serialization sounds better for me as well, especially in the case of complex data structure as you say. I look forward to having the feature earlier.
I merged the later branch to master. You can give it a try.
Awesome! Thank you!
I think it is ok to close this ...
First of all, I do appreciate all your work on this project. This library is fantastic. I was playing with gopter and found that the property doesn't seem to hold the original state of the sample for reporting, which gives confusing results.
First, I prepared a small target function named
biggest
, which is expected to return the biggest value in the given slice of int.As the PBT of this function, I wrote the following test:
The result of this test was:
But these arguments, both the original and the shrunk, should pass the test. Though I haven't dug into the implementation of the default shrinker and reporting, I assumed that the shrinker doesn't hold the original state of the sample. I changed the test code a bit to keep the original state of sample and it returned the expected report.
This test made the following report that makes sense to me: