3

When I add the example xUnit2 target to my FAKE build file, I'm getting this error:

error FS0001: This expression was expected to have type string option but here has type string

Target Example from FAKE xunit2 documentation

Target "Test" (fun _ ->
    !! (testDir @@ "xUnit.Test.*.dll")
      |> xUnit2 (fun p -> {p with HtmlOutputPath = (testDir @@ "xunit.html")})
)

The Visual Studio is highlighting the (testDir @@ "xunit.html") section of the code.

I understand that it's expecting two parameters, but I don't know enough F# yet to figure out how to fix the problem:

Prior to including the xUnit target, my FAKE build was working fine. I've added open Fake.Testing.XUnit2 to the build file and I get no error with the xUnit2 reference.

Any help would be appreciated.

ptilton
  • 142
  • 3
  • 13

1 Answers1

3

So the error is that the type of HtmlOutputPath is

HtmlOutputPath : string option

In Fake I believe that @@ does Path.Combine so testDir @@ "xunit.html should have type string.

To get the types to match, you can use

HtmlOutputPath = Some(testDir @@ "xunit.html")

This suggests that the documentation for FAKE is incorrect.

John Palmer
  • 25,356
  • 3
  • 48
  • 67
  • I think you're on the right track, but isn't the problem exactly that `testDir @@ "xunit.html"` is `string`, but should be `string option`? – Mark Seemann Sep 24 '15 at 06:36
  • yep, but apparently some magic happens when you do the `open` on the namespace - that part I can't figure out (since OP states that it works after an `open` – John Palmer Sep 24 '15 at 06:39
  • Actually, I just want to make it clear that I added the `open` to the top of the FAKE file. So I have a valid reference to the xUnit2 code. – ptilton Sep 24 '15 at 06:47
  • 1
    Oh, in that case `HtmlOutputPath = Some(testDir @@ "xunit.html")` should work, but maybe the documentation needs an update – John Palmer Sep 24 '15 at 06:48
  • `Some(...)` was the answer! If you update the answer, I'll accept it. – ptilton Sep 24 '15 at 06:52
  • Thanks for opening the FAKE ticket! – ptilton Sep 24 '15 at 06:58