3

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?

Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
  • 2
    I don't know FsUnit, but you seemed to forget test annotation: `let [] trivial() = 1 |> should not (equal 2)`. – pad Jun 05 '12 at 18:02
  • 1
    Also, unit tests should be functions, not values. Not sure if this is the cause of your error, but you're missing a `()` that pad's example has. – Joel Mueller Jun 05 '12 at 20:23
  • yeah, I forgot both those things when I went to type up this question. Good catch. – Nick Heiner Jun 07 '12 at 22:23

2 Answers2

6

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.

2

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) 
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553