From 9d56ab908acaea79e8a7edcbe4b9bba738e688e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Einar?= Date: Fri, 9 Oct 2015 09:54:22 +0200 Subject: [PATCH 1/2] Support for DotCoverMSTest --- src/app/FakeLib/DotCover.fs | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/app/FakeLib/DotCover.fs b/src/app/FakeLib/DotCover.fs index ab547955366..1fd5e4055a0 100644 --- a/src/app/FakeLib/DotCover.fs +++ b/src/app/FakeLib/DotCover.fs @@ -6,6 +6,7 @@ open System open System.IO open System.Text open Fake.Testing.XUnit2 +open Fake.MSTest type DotCoverReportType = | Html = 0 @@ -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() + |> appendIfNotNull testcontainers "" + |> appendIfNotNull parameters.Category "/category:" + |> appendIfNotNull parameters.TestMetadataPath "/testmetadata:" + |> appendIfNotNull parameters.TestSettingsPath "/testsettings:" + |> appendIfNotNull testResultsFile "/resultsfile:" + |> appendIfTrue 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 From 83f707440c179a239cd5e8eea8978988e094e5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Einar?= Date: Fri, 9 Oct 2015 12:12:43 +0200 Subject: [PATCH 2/2] Fix issues with two many quotes in DotCoverMSTest TargetArguments --- src/app/FakeLib/DotCover.fs | 12 ++++++------ src/app/FakeLib/StringHelper.fs | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/app/FakeLib/DotCover.fs b/src/app/FakeLib/DotCover.fs index 1fd5e4055a0..1fa7885991d 100644 --- a/src/app/FakeLib/DotCover.fs +++ b/src/app/FakeLib/DotCover.fs @@ -220,12 +220,12 @@ let internal buildMSTestArgsForDotCover parameters assemblies = sprintf @"%s\%s.trx" parameters.ResultsDir (DateTime.Now.ToString("yyyyMMdd-HHmmss.ff")) else null new StringBuilder() - |> appendIfNotNull testcontainers "" - |> appendIfNotNull parameters.Category "/category:" - |> appendIfNotNull parameters.TestMetadataPath "/testmetadata:" - |> appendIfNotNull parameters.TestSettingsPath "/testsettings:" - |> appendIfNotNull testResultsFile "/resultsfile:" - |> appendIfTrue parameters.NoIsolation "/noisolation" + |> 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. diff --git a/src/app/FakeLib/StringHelper.fs b/src/app/FakeLib/StringHelper.fs index 8d86258b75b..2d06a6bd638 100644 --- a/src/app/FakeLib/StringHelper.fs +++ b/src/app/FakeLib/StringHelper.fs @@ -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