-
Notifications
You must be signed in to change notification settings - Fork 585
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
Changes from all commits
f61a88b
0e653a0
4255ee5
ce8ad48
411cf69
098359b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a sample to the docs - see https://github.com/fsharp/FAKE/blob/develop/src/app/FakeLib/DotCover.fs#L148 |
||
let taskName = "OpenCover" | ||
let description = "Gathering coverage statistics" | ||
traceStartTask taskName description | ||
let param = setParams OpenCoverDefaults | ||
|
||
let processArgs = | ||
let args = ref (new StringBuilder()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add traceStartTask and traceEndTask - see https://github.com/fsharp/FAKE/blob/develop/src/app/FakeLib/DotCover.fs#L159 |
||
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 |
There was a problem hiding this comment.
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