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

Bindings don't work with fast-check 3.x #9

Open
ornamentist opened this issue Mar 15, 2023 · 5 comments
Open

Bindings don't work with fast-check 3.x #9

ornamentist opened this issue Mar 15, 2023 · 5 comments

Comments

@ornamentist
Copy link

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.

@TheSpyder
Copy link
Owner

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!

@ornamentist
Copy link
Author

And thanks for creating this project--generative/property testing is so nice to have available.

@TheSpyder
Copy link
Owner

I agree 😁

@TheSpyder
Copy link
Owner

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.

@TheSpyder TheSpyder changed the title Is example program test/ExampleTest.res still current? Bindings don't work with fast-check 3.x Mar 16, 2023
@ornamentist
Copy link
Author

Sounds good--many thanks.

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

No branches or pull requests

2 participants