Bob
Bob

Reputation: 75

Can't get OpenCover to work in fake

EDITED to show the ignore return as pointed out by Fyodor and the resulting error

I have a .fsx file with several targets that work as expected, but I can't get a target for OpenCover to work. This is what I have for the Target code:

Target "Coverage" (fun _ ->
  OpenCover
    (fun p -> { p with ExePath   = "./packages/OpenCover.4.6.519/tools/OpenCover.Console.exe"
                   TestRunnerExePath = "./packages/Machine.Specifications.Runner.Console.0.10.0-Unstable0005/tools/mspec-clr4.exe"
                   Output = reportDir + "MspecOutput.xml"
                   Register = "-register:user"
          }
    )
    testDir @@ "FakeTest2UnitTesting.dll" + "--xml " + reportDir + "MspecOutput.xml"  |> ignore
)

But I now get the following build error:

build.fsx(45,3): error FS0039: The value or constructor 'OpenCover' is not defined. Maybe you want one of the following: OpenCoverHelper NCover

I don't know what I am doing wrong. Can someone show me how to use the OpenCoverHelper from the FAKE API? Thanks

Upvotes: 3

Views: 155

Answers (1)

Bob
Bob

Reputation: 75

After a lot of playing around an googling, I finally came up with the solution. The basic problem was that I didn't open the OpenCoverHelper. I made the assumption that it was included in FAKE as it is in the Api and there was no documentation saying anything else. So, here is the code I use:

// include Fake lib
#r @"packages/FAKE.4.61.2/tools/FakeLib.dll"
open Fake
open Fake.OpenCoverHelper

Target "Coverage" (fun _ ->
  OpenCover (fun p -> { p with 
                          ExePath = "./packages/OpenCover.4.6.519/tools/OpenCover.Console.exe"
                          TestRunnerExePath = "./packages/Machine.Specifications.Runner.Console.0.10.0-Unstable0005/tools/mspec-clr4.exe"
                          Output = "./report/MspecOutput.xml"
                          Register = RegisterUser
                      })
   "./test/FakeTest2UnitTesting.dll + --xml ./report/MspecOutput.xml" 

)

Hopefully this will help someone in the future.

Upvotes: 1

Related Questions