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

DotCoverMSTest support #972

Merged
merged 2 commits into from
Oct 9, 2015
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
47 changes: 47 additions & 0 deletions src/app/FakeLib/DotCover.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open System
open System.IO
open System.Text
open Fake.Testing.XUnit2
open Fake.MSTest

type DotCoverReportType =
| Html = 0
Expand Down Expand Up @@ -208,6 +209,52 @@ let DotCoverXUnit2 (setDotCoverParams: DotCoverParams -> DotCoverParams) (setXUn

traceEndTask "DotCoverXUnit2" details

/// Builds the command line arguments from the given parameter record and the given assemblies.
/// Runs all test assemblies in the same run for easier coverage management.
/// [omit]
let internal buildMSTestArgsForDotCover parameters assemblies =
let testcontainers = assemblies |> Array.map (fun a -> "/testcontainer:" + a) |> String.concat " "

let testResultsFile =
if parameters.ResultsDir <> null then
sprintf @"%s\%s.trx" parameters.ResultsDir (DateTime.Now.ToString("yyyyMMdd-HHmmss.ff"))
else null
new StringBuilder()
|> appendWithoutQuotesIfNotNull testcontainers ""
|> appendWithoutQuotesIfNotNull parameters.Category "/category:"
|> appendWithoutQuotesIfNotNull parameters.TestMetadataPath "/testmetadata:"
|> appendWithoutQuotesIfNotNull parameters.TestSettingsPath "/testsettings:"
|> appendWithoutQuotesIfNotNull testResultsFile "/resultsfile:"
|> appendIfTrueWithoutQuotes parameters.NoIsolation "/noisolation"
|> toText

/// Runs the dotCover "cover" command against the MSTest test runner.
/// ## Parameters
///
/// - `setDotCoverParams` - Function used to overwrite the dotCover report default parameters.
/// - `setMSTestParams` - Function used to overwrite the MSTest default parameters.
///
/// ## Sample
///
/// !! (buildDir @@ buildMode @@ "/*.Unit.Tests.dll")
/// |> MSTest
/// (fun -> dotCoverOptions )
/// (fun MSTestOptions -> MSTestOptions)
let DotCoverMSTest (setDotCoverParams: DotCoverParams -> DotCoverParams) (setMSTestParams: MSTestParams -> MSTestParams) (assemblies: string seq) =
let assemblies = assemblies |> Seq.toArray
let details = assemblies |> separated ", "
traceStartTask "DotCoverMSTest " details

let parameters = MSTestDefaults |> setMSTestParams
let args = buildMSTestArgsForDotCover parameters assemblies

DotCover (fun p ->
{p with
TargetExecutable = parameters.ToolPath
TargetArguments = args
} |> setDotCoverParams)

traceEndTask "DotCoverMSTest" details

/// Runs the dotCover "cover" command against the MSpec test runner.
/// ## Parameters
Expand Down
6 changes: 6 additions & 0 deletions src/app/FakeLib/StringHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ let inline appendIfTrueWithoutQuotes p s builder =
/// Appends a text if the predicate is false.
let inline appendIfFalse p = appendIfTrue (not p)

/// Appends a text without quoting if the value is not null.
let inline appendWithoutQuotesIfNotNull (value : Object) s =
appendIfTrueWithoutQuotes (value <> null) (match value with
| :? String as sv -> (sprintf "%s%s" s sv)
| _ -> (sprintf "%s%A" s value))

/// Appends a text if the value is not null.
let inline appendIfNotNull (value : Object) s =
appendIfTrue (value <> null) (match value with
Expand Down