Skip to content

Commit

Permalink
Merge pull request #398 from trydis/opencover
Browse files Browse the repository at this point in the history
Support for OpenCover
  • Loading branch information
forki committed Apr 15, 2014
2 parents c06e627 + 098359b commit 77e09f7
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
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 =
{ /// (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 =
let taskName = "OpenCover"
let description = "Gathering coverage statistics"
traceStartTask taskName description
let param = setParams OpenCoverDefaults

let processArgs =
let args = ref (new StringBuilder())
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

0 comments on commit 77e09f7

Please sign in to comment.