Error on FsUnit example

559 Views Asked by At

I copied this example from the FsUnit project page:

open NUnit.Framework
open FsUnit
let [<Test>] trivial () = 1 |> should not (equal 2)

F# gives me the following error:

Error 2 This expression was expected to have type bool but here has type Constraints.EqualConstraint

Error 1 The type 'bool' is not compatible with the type 'Constraints.Constraint'

What am I doing wrong?

2

There are 2 best solutions below

0
On BEST ANSWER

A newer version of FsUnit includes a change that renames the FsUnit.not function to FsUnit.not'. This should eliminate the conflict with the built-in not function. You can get the latest version from NuGet Gallery. Examples of use can be found on the FsUnit GitHub site.

Let me know if you still see the issue. I'll be happy to do some more in-depth troubleshooting with you.

0
On

I think there is something wrong with the way you're referencing FsUnit. I tried to run your code (just copy FsUnit source code from CodePlex) and it worked fine. You still need to write your test as a function (as pointed out by Joel) so write something like let [<Test>] trivial () = ....

For some reason, I think your script is using the built-in not function (that operates on bool values) instead of the FsUnit.not function that operates on Constraint objects. Does it work if you use the not function from FsUnit explicitly?

let cnot = FsUnit.not
let [<Test>] trivial = 1 |> should cnot (equal 1)