TypeUsage example from user guide fails in 1.8.x
lcahmu opened this issue · comments
The user guide contains this example (modified slightly to compile):
https://jqwik.net/docs/1.8.5/user-guide.html#provider-methods-with-parameters
class ProvidesTypeUsageTest {
@Property
void favouritePrimesAsInts(@ForAll("favouritePrimes") int aFavourite) { }
@Property
void favouritePrimesAsBigInts(@ForAll("favouritePrimes") BigInteger aFavourite) { }
@Provide
Arbitrary<?> favouritePrimes(TypeUsage targetType) {
Arbitrary<Integer> ints = Arbitraries.of(3, 5, 7, 13, 17, 23, 41);
if (targetType.getRawType().equals(BigInteger.class)) {
return ints.map(BigInteger::valueOf);
}
return ints;
}
}
However, this example fails at runtime as of 1.8.5. The same example works with 1.7.4, but fails under 1.8.0
[ERROR] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.140 s <<< FAILURE! -- in ProvidesTypeUsageTest
[ERROR] ProvidesTypeUsageTest.favouritePrimesAsBigInts -- Time elapsed: 0.097 s <<< ERROR!
net.jqwik.api.CannotFindArbitraryException: Cannot find an Arbitrary [favouritePrimes] for Parameter of type [@net.jqwik.api.ForAll(value="favouritePrimes", supplier=net.jqwik.api.ArbitrarySupplier$NONE.class) BigInteger]
at net.jqwik.engine.properties.RandomizedShrinkablesGenerator.resolveArbitraries(RandomizedShrinkablesGenerator.java:152)
at net.jqwik.engine.properties.RandomizedShrinkablesGenerator.resolveEdgeCases(RandomizedShrinkablesGenerator.java:124)
at net.jqwik.engine.properties.RandomizedShrinkablesGenerator.listOfEdgeCases(RandomizedShrinkablesGenerator.java:93)
at net.jqwik.engine.properties.RandomizedShrinkablesGenerator.forParameters(RandomizedShrinkablesGenerator.java:28)
at net.jqwik.engine.execution.CheckedProperty.createRandomizedShrinkablesGenerator(CheckedProperty.java:236)
at net.jqwik.engine.execution.CheckedProperty.createForAllParametersGenerator(CheckedProperty.java:176)
at net.jqwik.engine.execution.CheckedProperty.createGenericProperty(CheckedProperty.java:144)
at net.jqwik.engine.execution.CheckedProperty.check(CheckedProperty.java:67)
at net.jqwik.engine.execution.PropertyMethodExecutor.executeProperty(PropertyMethodExecutor.java:90)
at net.jqwik.engine.execution.PropertyMethodExecutor.executeMethod(PropertyMethodExecutor.java:69)
at net.jqwik.engine.execution.PropertyMethodExecutor.lambda$execute$0(PropertyMethodExecutor.java:49)
at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$static$0(AroundPropertyHook.java:46)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at net.jqwik.api.lifecycle.PropertyExecutor.executeAndFinally(PropertyExecutor.java:39)
at net.jqwik.engine.hooks.lifecycle.PropertyLifecycleMethodsHook.aroundProperty(PropertyLifecycleMethodsHook.java:56)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at net.jqwik.engine.hooks.statistics.StatisticsHook.aroundProperty(StatisticsHook.java:37)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at net.jqwik.engine.hooks.lifecycle.AutoCloseableHook.aroundProperty(AutoCloseableHook.java:13)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at net.jqwik.engine.execution.PropertyMethodExecutor.execute(PropertyMethodExecutor.java:47)
at net.jqwik.engine.execution.PropertyTaskCreator.executeTestMethod(PropertyTaskCreator.java:166)
at net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$1(PropertyTaskCreator.java:51)
at net.jqwik.engine.execution.lifecycle.CurrentDomainContext.runWithContext(CurrentDomainContext.java:28)
at net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$2(PropertyTaskCreator.java:50)
at net.jqwik.engine.execution.pipeline.ExecutionTask$1.lambda$execute$0(ExecutionTask.java:31)
at net.jqwik.engine.execution.lifecycle.CurrentTestDescriptor.runWithDescriptor(CurrentTestDescriptor.java:17)
at net.jqwik.engine.execution.pipeline.ExecutionTask$1.execute(ExecutionTask.java:31)
at net.jqwik.engine.execution.pipeline.ExecutionPipeline.runToTermination(ExecutionPipeline.java:82)
at net.jqwik.engine.execution.JqwikExecutor.execute(JqwikExecutor.java:46)
at net.jqwik.engine.JqwikTestEngine.executeTests(JqwikTestEngine.java:70)
at net.jqwik.engine.JqwikTestEngine.execute(JqwikTestEngine.java:53)
[ERROR] ProvidesTypeUsageTest.favouritePrimesAsInts -- Time elapsed: 0.003 s <<< ERROR!
net.jqwik.api.CannotFindArbitraryException: Cannot find an Arbitrary [favouritePrimes] for Parameter of type [@net.jqwik.api.ForAll(value="favouritePrimes", supplier=net.jqwik.api.ArbitrarySupplier$NONE.class) int]
at net.jqwik.engine.properties.RandomizedShrinkablesGenerator.resolveArbitraries(RandomizedShrinkablesGenerator.java:152)
at net.jqwik.engine.properties.RandomizedShrinkablesGenerator.resolveEdgeCases(RandomizedShrinkablesGenerator.java:124)
at net.jqwik.engine.properties.RandomizedShrinkablesGenerator.listOfEdgeCases(RandomizedShrinkablesGenerator.java:93)
at net.jqwik.engine.properties.RandomizedShrinkablesGenerator.forParameters(RandomizedShrinkablesGenerator.java:28)
at net.jqwik.engine.execution.CheckedProperty.createRandomizedShrinkablesGenerator(CheckedProperty.java:236)
at net.jqwik.engine.execution.CheckedProperty.createForAllParametersGenerator(CheckedProperty.java:176)
at net.jqwik.engine.execution.CheckedProperty.createGenericProperty(CheckedProperty.java:144)
at net.jqwik.engine.execution.CheckedProperty.check(CheckedProperty.java:67)
at net.jqwik.engine.execution.PropertyMethodExecutor.executeProperty(PropertyMethodExecutor.java:90)
at net.jqwik.engine.execution.PropertyMethodExecutor.executeMethod(PropertyMethodExecutor.java:69)
at net.jqwik.engine.execution.PropertyMethodExecutor.lambda$execute$0(PropertyMethodExecutor.java:49)
at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$static$0(AroundPropertyHook.java:46)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at net.jqwik.api.lifecycle.PropertyExecutor.executeAndFinally(PropertyExecutor.java:39)
at net.jqwik.engine.hooks.lifecycle.PropertyLifecycleMethodsHook.aroundProperty(PropertyLifecycleMethodsHook.java:56)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at net.jqwik.engine.hooks.statistics.StatisticsHook.aroundProperty(StatisticsHook.java:37)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at net.jqwik.engine.hooks.lifecycle.AutoCloseableHook.aroundProperty(AutoCloseableHook.java:13)
at net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at net.jqwik.engine.execution.PropertyMethodExecutor.execute(PropertyMethodExecutor.java:47)
at net.jqwik.engine.execution.PropertyTaskCreator.executeTestMethod(PropertyTaskCreator.java:166)
at net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$1(PropertyTaskCreator.java:51)
at net.jqwik.engine.execution.lifecycle.CurrentDomainContext.runWithContext(CurrentDomainContext.java:28)
at net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$2(PropertyTaskCreator.java:50)
at net.jqwik.engine.execution.pipeline.ExecutionTask$1.lambda$execute$0(ExecutionTask.java:31)
at net.jqwik.engine.execution.lifecycle.CurrentTestDescriptor.runWithDescriptor(CurrentTestDescriptor.java:17)
at net.jqwik.engine.execution.pipeline.ExecutionTask$1.execute(ExecutionTask.java:31)
at net.jqwik.engine.execution.pipeline.ExecutionPipeline.runToTermination(ExecutionPipeline.java:82)
at net.jqwik.engine.execution.JqwikExecutor.execute(JqwikExecutor.java:46)
at net.jqwik.engine.JqwikTestEngine.executeTests(JqwikTestEngine.java:70)
at net.jqwik.engine.JqwikTestEngine.execute(JqwikTestEngine.java:53)
I found the same example in ProvideMethodExamples.java#L39-L54.
However, that test is among those excluded from running during a build, apparently intentionally: documentation/build.gradle#L127
Temporarily removing that exclusion to force it to run shows the same error:
$ git log -1
commit ee92719696db66de6d85c4d9c4fea8a2864c9527 (HEAD, tag: 1.8.5)
Author: Johannes Link <business@johanneslink.net>
Date: Fri May 24 09:49:45 2024 +0200
Upgrade to Gradle 8.7
$ ./gradlew test --tests net.jqwik.docs.ProvideMethodExamples
> Task :documentation:test FAILED
Gradle Test Executor 23 STANDARD_ERROR
Jun 06, 2024 4:05:41 PM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
WARNING: Discovered 2 'junit-platform.properties' configuration files in the classpath; only the first will be used.
Jun 06, 2024 4:05:41 PM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
WARNING: Discovered 2 'junit-platform.properties' configuration files in the classpath; only the first will be used.
ProvideMethodExamples > favouritePrimesAsBigInts STANDARD_OUT
timestamp = 2024-06-06T16:05:41.521633100, ProvideMethodExamples:favouritePrimesAsBigInts =
net.jqwik.api.CannotFindArbitraryException:
Cannot find an Arbitrary [favouritePrimes] for Parameter of type [@net.jqwik.api.ForAll(value="favouritePrimes", supplier=net.jqwik.api.ArbitrarySupplier.NONE.class) BigInteger]
|-----------------------jqwik-----------------------
tries = 0 | # of calls to property
checks = 0 | # of not rejected calls
generation = AUTO | RANDOMIZED, EXHAUSTIVE or DATA_DRIVEN
after-failure = SAMPLE_FIRST | try previously failed sample, then previous seed
when-fixed-seed = ALLOW | fixing the random seed is allowed
edge-cases#mode = MIXIN | edge cases are mixed in
edge-cases#total = 0 | # of all combined edge cases
edge-cases#tried = 0 | # of edge cases tried in current run
seed = -6384742812105374999 | random seed to reproduce generated values
FAILURE 0.1sec, net.jqwik.docs.ProvideMethodExamples > favouritePrimesAsBigInts
net.jqwik.api.CannotFindArbitraryException: Cannot find an Arbitrary [favouritePrimes] for Parameter of type [@net.jqwik.api.ForAll(value="favouritePrimes", supplier=net.jqwik.api.ArbitrarySupplier.NONE.class) BigInteger]
at app//net.jqwik.engine.properties.RandomizedShrinkablesGenerator.resolveArbitraries(RandomizedShrinkablesGenerator.java:152)
at app//net.jqwik.engine.properties.RandomizedShrinkablesGenerator.resolveEdgeCases(RandomizedShrinkablesGenerator.java:124)
at app//net.jqwik.engine.properties.RandomizedShrinkablesGenerator.listOfEdgeCases(RandomizedShrinkablesGenerator.java:93)
at app//net.jqwik.engine.properties.RandomizedShrinkablesGenerator.forParameters(RandomizedShrinkablesGenerator.java:28)
at app//net.jqwik.engine.execution.CheckedProperty.createRandomizedShrinkablesGenerator(CheckedProperty.java:236)
at app//net.jqwik.engine.execution.CheckedProperty.createForAllParametersGenerator(CheckedProperty.java:176)
at app//net.jqwik.engine.execution.CheckedProperty.createGenericProperty(CheckedProperty.java:144)
at app//net.jqwik.engine.execution.CheckedProperty.check(CheckedProperty.java:67)
at app//net.jqwik.engine.execution.PropertyMethodExecutor.executeProperty(PropertyMethodExecutor.java:90)
at app//net.jqwik.engine.execution.PropertyMethodExecutor.executeMethod(PropertyMethodExecutor.java:69)
at app//net.jqwik.engine.execution.PropertyMethodExecutor.lambda$execute$0(PropertyMethodExecutor.java:49)
at app//net.jqwik.api.lifecycle.AroundPropertyHook.lambda$static$0(AroundPropertyHook.java:46)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at app//net.jqwik.api.lifecycle.PropertyExecutor.executeAndFinally(PropertyExecutor.java:39)
at app//net.jqwik.engine.hooks.lifecycle.PropertyLifecycleMethodsHook.aroundProperty(PropertyLifecycleMethodsHook.java:56)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at app//net.jqwik.engine.hooks.statistics.StatisticsHook.aroundProperty(StatisticsHook.java:37)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at app//net.jqwik.engine.hooks.lifecycle.AutoCloseableHook.aroundProperty(AutoCloseableHook.java:13)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at app//net.jqwik.engine.execution.PropertyMethodExecutor.execute(PropertyMethodExecutor.java:47)
at app//net.jqwik.engine.execution.PropertyTaskCreator.executeTestMethod(PropertyTaskCreator.java:166)
at app//net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$1(PropertyTaskCreator.java:51)
at app//net.jqwik.engine.execution.lifecycle.CurrentDomainContext.runWithContext(CurrentDomainContext.java:28)
at app//net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$2(PropertyTaskCreator.java:50)
at app//net.jqwik.engine.execution.pipeline.ExecutionTask$1.lambda$execute$0(ExecutionTask.java:31)
at app//net.jqwik.engine.execution.lifecycle.CurrentTestDescriptor.runWithDescriptor(CurrentTestDescriptor.java:17)
at app//net.jqwik.engine.execution.pipeline.ExecutionTask$1.execute(ExecutionTask.java:31)
at app//net.jqwik.engine.execution.pipeline.ExecutionPipeline.runToTermination(ExecutionPipeline.java:82)
at app//net.jqwik.engine.execution.JqwikExecutor.execute(JqwikExecutor.java:46)
at app//net.jqwik.engine.JqwikTestEngine.executeTests(JqwikTestEngine.java:70)
at app//net.jqwik.engine.JqwikTestEngine.execute(JqwikTestEngine.java:53)
ProvideMethodExamples > favouritePrimesAsInts STANDARD_OUT
timestamp = 2024-06-06T16:05:41.537633700, ProvideMethodExamples:favouritePrimesAsInts =
net.jqwik.api.CannotFindArbitraryException:
Cannot find an Arbitrary [favouritePrimes] for Parameter of type [@net.jqwik.api.ForAll(value="favouritePrimes", supplier=net.jqwik.api.ArbitrarySupplier.NONE.class) int]
|-----------------------jqwik-----------------------
tries = 0 | # of calls to property
checks = 0 | # of not rejected calls
generation = AUTO | RANDOMIZED, EXHAUSTIVE or DATA_DRIVEN
after-failure = SAMPLE_FIRST | try previously failed sample, then previous seed
when-fixed-seed = ALLOW | fixing the random seed is allowed
edge-cases#mode = MIXIN | edge cases are mixed in
edge-cases#total = 0 | # of all combined edge cases
edge-cases#tried = 0 | # of edge cases tried in current run
seed = 7616089908716127990 | random seed to reproduce generated values
FAILURE 0.0sec, net.jqwik.docs.ProvideMethodExamples > favouritePrimesAsInts
net.jqwik.api.CannotFindArbitraryException: Cannot find an Arbitrary [favouritePrimes] for Parameter of type [@net.jqwik.api.ForAll(value="favouritePrimes", supplier=net.jqwik.api.ArbitrarySupplier.NONE.class) int]
at app//net.jqwik.engine.properties.RandomizedShrinkablesGenerator.resolveArbitraries(RandomizedShrinkablesGenerator.java:152)
at app//net.jqwik.engine.properties.RandomizedShrinkablesGenerator.resolveEdgeCases(RandomizedShrinkablesGenerator.java:124)
at app//net.jqwik.engine.properties.RandomizedShrinkablesGenerator.listOfEdgeCases(RandomizedShrinkablesGenerator.java:93)
at app//net.jqwik.engine.properties.RandomizedShrinkablesGenerator.forParameters(RandomizedShrinkablesGenerator.java:28)
at app//net.jqwik.engine.execution.CheckedProperty.createRandomizedShrinkablesGenerator(CheckedProperty.java:236)
at app//net.jqwik.engine.execution.CheckedProperty.createForAllParametersGenerator(CheckedProperty.java:176)
at app//net.jqwik.engine.execution.CheckedProperty.createGenericProperty(CheckedProperty.java:144)
at app//net.jqwik.engine.execution.CheckedProperty.check(CheckedProperty.java:67)
at app//net.jqwik.engine.execution.PropertyMethodExecutor.executeProperty(PropertyMethodExecutor.java:90)
at app//net.jqwik.engine.execution.PropertyMethodExecutor.executeMethod(PropertyMethodExecutor.java:69)
at app//net.jqwik.engine.execution.PropertyMethodExecutor.lambda$execute$0(PropertyMethodExecutor.java:49)
at app//net.jqwik.api.lifecycle.AroundPropertyHook.lambda$static$0(AroundPropertyHook.java:46)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at app//net.jqwik.api.lifecycle.PropertyExecutor.executeAndFinally(PropertyExecutor.java:39)
at app//net.jqwik.engine.hooks.lifecycle.PropertyLifecycleMethodsHook.aroundProperty(PropertyLifecycleMethodsHook.java:56)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at app//net.jqwik.engine.hooks.statistics.StatisticsHook.aroundProperty(StatisticsHook.java:37)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$0(HookSupport.java:26)
at app//net.jqwik.engine.hooks.lifecycle.AutoCloseableHook.aroundProperty(AutoCloseableHook.java:13)
at app//net.jqwik.engine.execution.lifecycle.HookSupport.lambda$wrap$1(HookSupport.java:31)
at app//net.jqwik.engine.execution.PropertyMethodExecutor.execute(PropertyMethodExecutor.java:47)
at app//net.jqwik.engine.execution.PropertyTaskCreator.executeTestMethod(PropertyTaskCreator.java:166)
at app//net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$1(PropertyTaskCreator.java:51)
at app//net.jqwik.engine.execution.lifecycle.CurrentDomainContext.runWithContext(CurrentDomainContext.java:28)
at app//net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$2(PropertyTaskCreator.java:50)
at app//net.jqwik.engine.execution.pipeline.ExecutionTask$1.lambda$execute$0(ExecutionTask.java:31)
at app//net.jqwik.engine.execution.lifecycle.CurrentTestDescriptor.runWithDescriptor(CurrentTestDescriptor.java:17)
at app//net.jqwik.engine.execution.pipeline.ExecutionTask$1.execute(ExecutionTask.java:31)
at app//net.jqwik.engine.execution.pipeline.ExecutionPipeline.runToTermination(ExecutionPipeline.java:82)
at app//net.jqwik.engine.execution.JqwikExecutor.execute(JqwikExecutor.java:46)
at app//net.jqwik.engine.JqwikTestEngine.executeTests(JqwikTestEngine.java:70)
at app//net.jqwik.engine.JqwikTestEngine.execute(JqwikTestEngine.java:53)
ProvideMethodExamples > concatenatingStringWithInt STANDARD_OUT
timestamp = 2024-06-06T16:05:41.634640200, ProvideMethodExamples:concatenatingStringWithInt =
|-----------------------jqwik-----------------------
tries = 1000 | # of calls to property
checks = 1000 | # of not rejected calls
generation = RANDOMIZED | parameters are randomly generated
after-failure = SAMPLE_FIRST | try previously failed sample, then previous seed
when-fixed-seed = ALLOW | fixing the random seed is allowed
edge-cases#mode = MIXIN | edge cases are mixed in
edge-cases#total = 8 | # of all combined edge cases
edge-cases#tried = 8 | # of edge cases tried in current run
seed = 1948138275151491839 | random seed to reproduce generated values
ProvideMethodExamples > joiningListOfStrings STANDARD_OUT
timestamp = 2024-06-06T16:05:41.723852600, ProvideMethodExamples:joiningListOfStrings =
|-----------------------jqwik-----------------------
tries = 1000 | # of calls to property
checks = 1000 | # of not rejected calls
generation = RANDOMIZED | parameters are randomly generated
after-failure = SAMPLE_FIRST | try previously failed sample, then previous seed
when-fixed-seed = ALLOW | fixing the random seed is allowed
edge-cases#mode = MIXIN | edge cases are mixed in
edge-cases#total = 3 | # of all combined edge cases
edge-cases#tried = 3 | # of edge cases tried in current run
seed = 1515305569013631477 | random seed to reproduce generated values
ProvideMethodExamples > concatenatingStringWithInt2 STANDARD_OUT
timestamp = 2024-06-06T16:05:41.745853700, ProvideMethodExamples:concatenatingStringWithInt2 =
|-----------------------jqwik-----------------------
tries = 1000 | # of calls to property
checks = 1000 | # of not rejected calls
generation = RANDOMIZED | parameters are randomly generated
after-failure = SAMPLE_FIRST | try previously failed sample, then previous seed
when-fixed-seed = ALLOW | fixing the random seed is allowed
edge-cases#mode = MIXIN | edge cases are mixed in
edge-cases#total = 8 | # of all combined edge cases
edge-cases#tried = 8 | # of edge cases tried in current run
seed = 6160761469288057428 | random seed to reproduce generated values
FAILURE 0.5sec, 5 completed, 2 failed, 0 skipped, net.jqwik.docs.ProvideMethodExamples
FAILURE 1.1sec, 5 completed, 2 failed, 0 skipped, Gradle Test Run :documentation:test
5 tests completed, 2 failed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':documentation:test'.
> There were failing tests. See the report at: file:///C:/Users/lahmu/github/jqwik/documentation/build/reports/tests/test/index.html
* Try:
> Run with --scan to get full insights.
BUILD FAILED in 1s
38 actionable tasks: 10 executed, 28 up-to-date
At first glance, I'd consider this a bug. But I'll have to do more checking to make sure.
It seems like the change of behaviour happened with version 1.8.0
.
Now that I think about it more deeply...
The way it behaves is correct. The documentation is wrong. this should no longer work.
In the release notes for version 1.8.0:
@Provide
methods are now matched more strictly, based on assignability of returned arbitrary type. That means that potential mismatches of generated values and the corresponding@ForAll
parameters will show up already at property setup time through a CannotFindArbitraryException.
If you want something similar to the example in the user guide, you'll now have to cast explicitly, eg
class Experiments {
@Property
void favouritePrimesAsInts(@ForAll("favouritePrimesInt") int aFavourite) { }
@Property
void favouritePrimesAsBigInts(@ForAll("favouritePrimesBigInt") BigInteger aFavourite) { }
@Provide
Arbitrary<Integer> favouritePrimesInt(TypeUsage targetType) {
return (Arbitrary<Integer>) favouritePrimes(targetType);
}
@Provide
Arbitrary<BigInteger> favouritePrimesBigInt(TypeUsage targetType) {
return (Arbitrary<BigInteger>) favouritePrimes(targetType);
}
private Arbitrary<?> favouritePrimes(TypeUsage targetType) {
Arbitrary<Integer> ints = Arbitraries.of(3, 5, 7, 13, 17, 23, 41);
if (targetType.getRawType().equals(BigInteger.class)) {
return ints.map(BigInteger::valueOf);
}
return ints;
}
}
Task:
- Update documentation
The updated part of the user guide can be found here: https://jqwik.net/docs/current/user-guide.html#arbitrary-provider-methods