Bindings don't work with fast-check 3.x
ornamentist opened this issue · comments
I've started learning rescript-fast-check
with the bundled example program test/ExampleTest.res
code:
open RescriptMocha
open Mocha
open FastCheck;
open Arbitrary
open Property.Sync
// Code under test
let contains = (text, pattern) => text->Js.String2.indexOf(pattern) >= 0
// Properties
describe("properties", () => {
// string text always contains itself
it("should always contain itself", () =>
assert_(property1(string(), text => contains(text, text)))
)
// string a + b + c always contains b, whatever the values of a, b and c
it("should always contain its substrings", () =>
assert_(property3(string(), string(), string(), (a, b, c) => contains(a ++ (b ++ c), b)))
)
})
// Recommended alternative: use a convenience method to avoid the weird `assert_` name
describe("properties using rescript-fast-check shorthand", () => {
it("should always contain itself", () => assertProperty1(string(), text => contains(text, text)))
it("should always contain its substrings", () =>
assertProperty3(string(), string(), string(), (a, b, c) => contains(a ++ (b ++ c), b))
)
})
This compiles successfully, but gives these run-time errors:
~> node_modules/mocha/bin/mocha examples/example.mjs
properties
✔ should always contain itself
✔ should always contain its substrings
properties using rescript-fast-check shorthand
1) should always contain itself
2) should always contain its substrings
2 passing (10ms)
2 failing
1) properties using rescript-fast-check shorthand
should always contain itself:
TypeError: this.arb.withBias is not a function
at ConverterToNext.generate (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/check/arbitrary/definition/ConverterToNext.js:29:55)
at AlwaysShrinkableArbitrary.generate (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/arbitrary/_internals/AlwaysShrinkableArbitrary.js:10:32)
at file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/arbitrary/_internals/TupleArbitrary.js:43:62
at Array.map (<anonymous>)
at TupleArbitrary.generate (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/arbitrary/_internals/TupleArbitrary.js:43:49)
at Property.generate (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/check/property/Property.generic.js:25:32)
at Object.value (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/check/runner/Tosser.js:6:28)
at SourceValuesIterator.next (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/check/runner/SourceValuesIterator.js:14:35)
at RunnerIterator.next (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/check/runner/RunnerIterator.js:14:43)
at runIt (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/check/runner/Runner.js:12:16)
at check (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/check/runner/Runner.js:60:11)
at Module.assert (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/node_modules/fast-check/lib/esm/check/runner/Runner.js:63:17)
at Object.assertProperty1 (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-fast-check/src/Property.mjs:19:13)
at file:///Users/stu/projects/mathe/rescript/examples/example.mjs:26:41
at Module._1 (file:///Users/stu/projects/mathe/rescript/node_modules/rescript/lib/es6/curry.js:32:12)
at Context.<anonymous> (file:///Users/stu/projects/mathe/rescript/node_modules/rescript-mocha/src/Internal.mjs:28:24)
at process.processImmediate (node:internal/timers:475:21)
<snipped>
It's likely that I've misunderstood something about using this library.
Hmm. I have been meaning to see what changed recently in fast-check, but I thought it was only adding features. I’ll look into this, thanks for the report!
And thanks for creating this project--generative/property testing is so nice to have available.
I agree 😁
Looks like I didn't read the 3.x migration guide closely enough. This has been broken for a while; 3.x was released mid last year. I saw some things had been removed but didn't realise I was using them in the bindings.
I have been putting it off because the update to 3.x will require bumping the major version of these bindings. I suggest downgrading your fast-check to 2.x for now; I'll keep this open and see if I can get to it soon.
Sounds good--many thanks.