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

Support for OpenCover #398

Merged
merged 6 commits into from
Apr 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<Compile Include="FtpHelper.fs" />
<Compile Include="AppVeyor.fs" />
<Compile Include="TypeScript.fs" />
<Compile Include="OpenCoverHelper.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Expand Down
85 changes: 85 additions & 0 deletions src/app/FakeLib/OpenCoverHelper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/// Contains a task which can be used to run [OpenCover](https://github.com/sawilde/opencover) on .NET assemblies.
module Fake.OpenCoverHelper

open System
open System.Text

type RegisterType =
| Manual
| Register
| RegisterUser

/// OpenCover parameters, for more details see: https://github.com/OpenCover/opencover/wiki/Usage#console-application-usage.
type OpenCoverParams =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document every single property of this parameter - see https://github.com/fsharp/FAKE/blob/develop/src/app/FakeLib/TestFlightHelper.fs#L7

{ /// (Required) Path to the OpenCover console application
ExePath : string
/// (Required) Path to the NUnit/XUnit console runner
TestRunnerExePath : string
/// The location and name of the output xml file.
/// If no value is supplied then the current directory
/// will be used and the output filename will be results.xml.
Output : string
/// Use this to register and de-register the code coverage profiler.
Register : RegisterType
/// A list of filters to apply to selectively include or exclude assemblies and classes from coverage results.
Filter : string
/// The timeout for the OpenCover process.
TimeOut : TimeSpan
/// The directory where the OpenCover process will be started.
WorkingDir : string }

/// OpenCover default parameters
let OpenCoverDefaults =
{ ExePath = environVar "LOCALAPPDATA" @@ "Apps" @@ "OpenCover" @@ "OpenCover.Console.exe"
TestRunnerExePath = ProgramFiles @@ "NUnit" @@ "bin" @@ "nunit-console.exe"
Output = String.Empty
Register = Manual
Filter = String.Empty
TimeOut = TimeSpan.FromMinutes 5.
WorkingDir = currentDirectory }

/// Runs OpenCover on a group of assemblies.
/// ## Parameters
///
/// - `setParams` - Function used to overwrite the default OpenCover parameters.
/// - `targetArgs` - Test runner arguments.
///
/// ## Sample
///
/// OpenCover (fun p -> { p with TestRunnerExePath = "./Tools/NUnit/nunit-console.exe" })
/// "project-file.nunit /config:Release /noshadow /xml:artifacts/nunit.xml /framework:net-4.0"
let OpenCover setParams targetArgs =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let taskName = "OpenCover"
let description = "Gathering coverage statistics"
traceStartTask taskName description
let param = setParams OpenCoverDefaults

let processArgs =
let args = ref (new StringBuilder())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let append (s : string) = args := (!args).Append(s)
let appendQuoted (s : string) = args := (!args).Append("\"").Append(s).Append("\" ")
append "-target:"
param.TestRunnerExePath
|> FullName
|> appendQuoted
append "-targetargs:"
appendQuoted targetArgs
if param.Output <> String.Empty then
append "-output:"
appendQuoted param.Output
append (match param.Register with
| Manual -> String.Empty
| Register -> "-register "
| RegisterUser -> "-register:user ")
if param.Filter <> String.Empty then
append "-filter:"
appendQuoted param.Filter
(!args).ToString()
tracefn "OpenCover command\n%s %s" param.ExePath processArgs
let ok =
execProcess (fun info ->
info.FileName <- param.ExePath
if param.WorkingDir <> String.Empty then info.WorkingDirectory <- param.WorkingDir
info.Arguments <- processArgs) param.TimeOut
if not ok then failwithf "OpenCover reported errors."
traceEndTask taskName description