From fd78339a57e1b295cfe0ad6cc68a07255ae10554 Mon Sep 17 00:00:00 2001 From: Dany Fabian Date: Wed, 27 Jun 2018 16:08:53 +0100 Subject: [PATCH 1/7] Copy MSTest and add VSTest package. --- Fake.sln | 15 +++ build.fsx | 1 + .../AssemblyInfo.fs | 17 +++ .../Fake.DotNet.Testing.VSTest.fsproj | 26 ++++ src/app/Fake.DotNet.Testing.VSTest/VSTest.fs | 121 ++++++++++++++++++ .../paket.references | 4 + 6 files changed, 184 insertions(+) create mode 100644 src/app/Fake.DotNet.Testing.VSTest/AssemblyInfo.fs create mode 100644 src/app/Fake.DotNet.Testing.VSTest/Fake.DotNet.Testing.VSTest.fsproj create mode 100644 src/app/Fake.DotNet.Testing.VSTest/VSTest.fs create mode 100644 src/app/Fake.DotNet.Testing.VSTest/paket.references diff --git a/Fake.sln b/Fake.sln index 5d5de8a67c8..76b079c05b1 100644 --- a/Fake.sln +++ b/Fake.sln @@ -158,6 +158,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.DotNet.Cli.Integration EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Core.UserInput", "src\app\Fake.Core.UserInput\Fake.Core.UserInput.fsproj", "{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}" EndProject +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.DotNet.Testing.VSTest", "src\app\Fake.DotNet.Testing.VSTest\Fake.DotNet.Testing.VSTest.fsproj", "{C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -972,6 +974,18 @@ Global {3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Release|x64.Build.0 = Release|Any CPU {3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Release|x86.ActiveCfg = Release|Any CPU {3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Release|x86.Build.0 = Release|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Debug|x64.ActiveCfg = Debug|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Debug|x64.Build.0 = Debug|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Debug|x86.ActiveCfg = Debug|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Debug|x86.Build.0 = Debug|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Release|Any CPU.Build.0 = Release|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Release|x64.ActiveCfg = Release|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Release|x64.Build.0 = Release|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Release|x86.ActiveCfg = Release|Any CPU + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1046,6 +1060,7 @@ Global {29B66A06-1A45-4D65-AC31-7D746449E5D6} = {872B282D-8A3E-459A-B63D-C43C5D73506D} {48ECC58D-468C-4D44-98B3-854C21EB0D40} = {E09B72E4-D890-46A8-8D14-7367C2E23E9D} {3B0A5EE3-6696-4EBA-BCF9-8136C7F17040} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A} + {C4C9D7EE-6A52-42F1-9E04-7C44F0EA8922} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {058A0C5E-2216-4306-8AFB-0AE28320C26A} diff --git a/build.fsx b/build.fsx index 824aff04f14..c84337474d2 100644 --- a/build.fsx +++ b/build.fsx @@ -361,6 +361,7 @@ let dotnetAssemblyInfos = "Fake.DotNet.Testing.Expecto", "Running expecto test runner" "Fake.DotNet.Testing.MSpec", "Running mspec test runner" "Fake.DotNet.Testing.MSTest", "Running mstest test runner" + "Fake.DotNet.Testing.VSTest", "Running vstest test runner" "Fake.DotNet.Testing.NUnit", "Running nunit test runner" "Fake.DotNet.Testing.OpenCover", "Code coverage with OpenCover" "Fake.DotNet.Testing.SpecFlow", "BDD with Gherkin and SpecFlow" diff --git a/src/app/Fake.DotNet.Testing.VSTest/AssemblyInfo.fs b/src/app/Fake.DotNet.Testing.VSTest/AssemblyInfo.fs new file mode 100644 index 00000000000..1dade38e2a2 --- /dev/null +++ b/src/app/Fake.DotNet.Testing.VSTest/AssemblyInfo.fs @@ -0,0 +1,17 @@ +// Auto-Generated by FAKE; do not edit +namespace System +open System.Reflection + +[] +[] +[] +[] +[] +do () + +module internal AssemblyVersionInformation = + let [] AssemblyTitle = "FAKE - F# Make Running VSTest test runner" + let [] AssemblyProduct = "FAKE - F# Make" + let [] AssemblyVersion = "5.1.0" + let [] AssemblyInformationalVersion = "5.1.0" + let [] AssemblyFileVersion = "5.1.0" diff --git a/src/app/Fake.DotNet.Testing.VSTest/Fake.DotNet.Testing.VSTest.fsproj b/src/app/Fake.DotNet.Testing.VSTest/Fake.DotNet.Testing.VSTest.fsproj new file mode 100644 index 00000000000..a9d168222c2 --- /dev/null +++ b/src/app/Fake.DotNet.Testing.VSTest/Fake.DotNet.Testing.VSTest.fsproj @@ -0,0 +1,26 @@ + + + net46;netstandard1.6;netstandard2.0 + $(DefineConstants);NO_DOTNETCORE_BOOTSTRAP + Fake.DotNet.Testing.MSTest + Library + + + $(DefineConstants);NETSTANDARD;USE_HTTPCLIENT + + + $(DefineConstants);RELEASE + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs b/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs new file mode 100644 index 00000000000..5ad9e26ed1d --- /dev/null +++ b/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs @@ -0,0 +1,121 @@ +/// Contains tasks to run [MSTest](http://en.wikipedia.org/wiki/Visual_Studio_Unit_Testing_Framework/) unit tests. +module Fake.DotNet.Testing.MSTest + +open System +open System.Text +open Fake.Core +open Fake.Testing.Common + +/// [omit] +let mstestPaths = + [| @"[ProgramFilesX86]\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\"; + @"[ProgramFilesX86]\Microsoft Visual Studio\2017\Professional\Common7\IDE\"; + @"[ProgramFilesX86]\Microsoft Visual Studio\2017\Community\Common7\IDE\"; + @"[ProgramFilesX86]\Microsoft Visual Studio 14.0\Common7\IDE"; + @"[ProgramFilesX86]\Microsoft Visual Studio 12.0\Common7\IDE"; + @"[ProgramFilesX86]\Microsoft Visual Studio 11.0\Common7\IDE"; + @"[ProgramFilesX86]\Microsoft Visual Studio 10.0\Common7\IDE" |] + +/// [omit] +let mstestexe = + if Environment.isWindows then "mstest.exe" + else failwith "MSTest is only supported on Windows platform" + +// TODO: try to use VSTest.Console.exe as well (VS2012 and up only) +/// Option which allow to specify if a MSTest error should break the build. +type ErrorLevel = TestRunnerErrorLevel + +/// Parameter type to configure the MSTest.exe. +[] +type MSTestParams = + { /// Test category filter (optional). The test category filter consists of one or more test category names separated by the logical operators '&', '|', '!', '&!'. The logical operators '&' and '|' cannot be used together to create a test category filter. + Category : string + /// Test results directory (optional) + ResultsDir : string + /// Path to the Test Metadata file (.vsmdi) (optional) + TestMetadataPath : string + /// Path to the Test Settings file (.testsettings) (optional) + TestSettingsPath : string + /// Working directory (optional) + WorkingDir : string + /// List of tests be run (optional) + Tests : string list + /// A timeout for the test runner (optional) + TimeOut : TimeSpan + /// Path to MSTest.exe + ToolPath : string + /// List of additional test case properties to display, if they exist (optional) + Details : string list + /// Option which allow to specify if a MSTest error should break the build. + ErrorLevel : ErrorLevel + /// Run tests in isolation (optional). + NoIsolation : bool } + +/// MSTest default parameters. +let MSTestDefaults = + { Category = null + ResultsDir = null + TestMetadataPath = null + TestSettingsPath = null + WorkingDir = null + Tests = [] + TimeOut = TimeSpan.FromMinutes 5. + ToolPath = + match Process.tryFindFile mstestPaths mstestexe with + | Some path -> path + | None -> "" + Details = [] + ErrorLevel = ErrorLevel.Error + NoIsolation = true } + +/// Builds the command line arguments from the given parameter record and the given assemblies. +/// [omit] +let internal buildMSTestArgs parameters assembly = + let testResultsFile = + if parameters.ResultsDir <> null then + sprintf @"%s\%s.trx" parameters.ResultsDir (DateTime.Now.ToString("yyyyMMdd-HHmmss.ff")) + else null + + new StringBuilder() + |> StringBuilder.appendIfNotNull assembly "/testcontainer:" + |> StringBuilder.appendIfNotNull parameters.Category "/category:" + |> StringBuilder.appendIfNotNull parameters.TestMetadataPath "/testmetadata:" + |> StringBuilder.appendIfNotNull parameters.TestSettingsPath "/testsettings:" + |> StringBuilder.appendIfNotNull testResultsFile "/resultsfile:" + |> StringBuilder.appendIfTrue parameters.NoIsolation "/noisolation" + |> StringBuilder.forEach parameters.Tests StringBuilder.appendIfNotNullOrEmpty "/test:" + |> StringBuilder.forEach parameters.Details StringBuilder.appendIfNotNullOrEmpty "/detail:" + |> StringBuilder.toText + +/// Runs MSTest command line tool on a group of assemblies. +/// ## Parameters +/// +/// - `setParams` - Function used to manipulate the default MSTestParams value. +/// - `assemblies` - Sequence of one or more assemblies containing Microsoft Visual Studio Unit Test Framework unit tests. +/// +/// ## Sample usage +/// +/// Target "Test" (fun _ -> +/// !! (testDir + @"\*.Tests.dll") +/// |> MSTest (fun p -> { p with Category = "group1" }) +/// ) +let exec (setParams : MSTestParams -> MSTestParams) (assemblies : string seq) = + let details = assemblies |> String.separated ", " + use __ = Trace.traceTask "MSTest" details + let parameters = MSTestDefaults |> setParams + let assemblies = assemblies |> Seq.toArray + if Array.isEmpty assemblies then failwith "MSTest: cannot run tests (the assembly list is empty)." + let failIfError assembly exitCode = + if exitCode > 0 && parameters.ErrorLevel <> ErrorLevel.DontFailBuild then + let message = sprintf "%sMSTest test run failed for %s" Environment.NewLine assembly + Trace.traceError message + failwith message + for assembly in assemblies do + let args = buildMSTestArgs parameters assembly + Process.execSimple ((fun info -> + { info with + FileName = parameters.ToolPath + WorkingDirectory = parameters.WorkingDir + Arguments = args }) >> Process.withFramework) parameters.TimeOut + |> failIfError assembly + __.MarkSuccess() diff --git a/src/app/Fake.DotNet.Testing.VSTest/paket.references b/src/app/Fake.DotNet.Testing.VSTest/paket.references new file mode 100644 index 00000000000..2c8a7ddfd73 --- /dev/null +++ b/src/app/Fake.DotNet.Testing.VSTest/paket.references @@ -0,0 +1,4 @@ +group netcore + +FSharp.Core +NETStandard.Library \ No newline at end of file From 575e15fe41e85d331e768d79652b4cff21880290 Mon Sep 17 00:00:00 2001 From: Dany Fabian Date: Wed, 27 Jun 2018 16:33:09 +0100 Subject: [PATCH 2/7] Port VSTest to FAKE 5. --- src/app/Fake.DotNet.Testing.VSTest/VSTest.fs | 187 +++++++++++-------- 1 file changed, 108 insertions(+), 79 deletions(-) diff --git a/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs b/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs index 5ad9e26ed1d..e4558a0efce 100644 --- a/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs +++ b/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs @@ -1,121 +1,150 @@ -/// Contains tasks to run [MSTest](http://en.wikipedia.org/wiki/Visual_Studio_Unit_Testing_Framework/) unit tests. -module Fake.DotNet.Testing.MSTest +/// Contains tasks to run [VSTest](https://msdn.microsoft.com/en-us/library/ms182486.aspx) unit tests. +module Fake.DotNet.Testing.VSTest -open System -open System.Text open Fake.Core open Fake.Testing.Common +open System +open System.Text /// [omit] -let mstestPaths = - [| @"[ProgramFilesX86]\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\"; - @"[ProgramFilesX86]\Microsoft Visual Studio\2017\Professional\Common7\IDE\"; - @"[ProgramFilesX86]\Microsoft Visual Studio\2017\Community\Common7\IDE\"; - @"[ProgramFilesX86]\Microsoft Visual Studio 14.0\Common7\IDE"; - @"[ProgramFilesX86]\Microsoft Visual Studio 12.0\Common7\IDE"; - @"[ProgramFilesX86]\Microsoft Visual Studio 11.0\Common7\IDE"; - @"[ProgramFilesX86]\Microsoft Visual Studio 10.0\Common7\IDE" |] +let vsTestPaths = + [| + @"[ProgramFilesX86]\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow" + @"[ProgramFilesX86]\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow" + @"[ProgramFilesX86]\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow" + @"[ProgramFilesX86]\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow" + |] /// [omit] -let mstestexe = - if Environment.isWindows then "mstest.exe" - else failwith "MSTest is only supported on Windows platform" +let vsTestExe = + if Environment.isMono then failwith "VSTest is not supported on the mono platform" + else "vstest.console.exe" -// TODO: try to use VSTest.Console.exe as well (VS2012 and up only) -/// Option which allow to specify if a MSTest error should break the build. +/// Option which allow to specify if a VSTest error should break the build. type ErrorLevel = TestRunnerErrorLevel -/// Parameter type to configure the MSTest.exe. +/// Parameter type to configure [VSTest.Console.exe](https://msdn.microsoft.com/en-us/library/jj155800.aspx) [] -type MSTestParams = - { /// Test category filter (optional). The test category filter consists of one or more test category names separated by the logical operators '&', '|', '!', '&!'. The logical operators '&' and '|' cannot be used together to create a test category filter. - Category : string - /// Test results directory (optional) - ResultsDir : string - /// Path to the Test Metadata file (.vsmdi) (optional) - TestMetadataPath : string - /// Path to the Test Settings file (.testsettings) (optional) - TestSettingsPath : string - /// Working directory (optional) +type VSTestParams = + { /// Path to the run settings file to run tests with additional settings such as data collectors (optional). + SettingsPath : string + /// Names of the tests that should be run (optional). + Tests : seq + /// Enables code coverage collection (optional). + EnableCodeCoverage : bool + /// Run the tests in an isolated process (optional). + InIsolation : bool + /// Use installed VSIX extensions in VSTest (optional). + UseVsixExtensions : bool + /// Target platform architecture for test execution (optional). Valid options include "x86", "x64" and "ARM". + Platform : string + /// Target .NET framework version to use for test execution (optional). + Framework : string + /// Run tests that match the given expression (optional). Cannot be used with the Tests argument + TestCaseFilter : string + /// The logger to use for test results (optional). + Logger : string + /// List discovered tests from the given container path (optional). + ListTestsPath : string + /// List installed test discoverers (optional). + ListDiscoverers : bool + /// List installed test executors (optional). + ListExecutors : bool + /// List installed loggers (optional). + ListLoggers : bool + /// List installed settings providers (optional). + ListSettingsProviders : bool + /// Path to VSTest.Console.exe (optional). By default the default install location is searched. + ToolPath : string + /// Working directory (optional). WorkingDir : string - /// List of tests be run (optional) - Tests : string list - /// A timeout for the test runner (optional) + /// A timeout for the test runner (optional). TimeOut : TimeSpan - /// Path to MSTest.exe - ToolPath : string - /// List of additional test case properties to display, if they exist (optional) - Details : string list - /// Option which allow to specify if a MSTest error should break the build. - ErrorLevel : ErrorLevel - /// Run tests in isolation (optional). - NoIsolation : bool } + /// Error level for controlling how VSTest failures should break the build (optional). + ErrorLevel : ErrorLevel + /// Path to test adapter e.g. xUnit (optional) + TestAdapterPath: string} -/// MSTest default parameters. -let MSTestDefaults = - { Category = null - ResultsDir = null - TestMetadataPath = null - TestSettingsPath = null - WorkingDir = null +/// VSTest default parameters. +let VSTestDefaults = + { SettingsPath = null Tests = [] - TimeOut = TimeSpan.FromMinutes 5. + EnableCodeCoverage = false + InIsolation = true + UseVsixExtensions = false + Platform = null + Framework = null + TestCaseFilter = null + Logger = null + ListTestsPath = null + ListDiscoverers = false + ListExecutors = false + ListLoggers = false + ListSettingsProviders = false ToolPath = - match Process.tryFindFile mstestPaths mstestexe with + match Process.tryFindFile vsTestPaths vsTestExe with | Some path -> path | None -> "" - Details = [] + WorkingDir = null + TimeOut = TimeSpan.MaxValue ErrorLevel = ErrorLevel.Error - NoIsolation = true } + TestAdapterPath = null } /// Builds the command line arguments from the given parameter record and the given assemblies. /// [omit] -let internal buildMSTestArgs parameters assembly = - let testResultsFile = - if parameters.ResultsDir <> null then - sprintf @"%s\%s.trx" parameters.ResultsDir (DateTime.Now.ToString("yyyyMMdd-HHmmss.ff")) +let buildVSTestArgs (parameters : VSTestParams) assembly = + let testsToRun = + if not (Seq.isEmpty parameters.Tests) then + sprintf @"/Tests:%s" (parameters.Tests |> String.separated ",") else null - new StringBuilder() - |> StringBuilder.appendIfNotNull assembly "/testcontainer:" - |> StringBuilder.appendIfNotNull parameters.Category "/category:" - |> StringBuilder.appendIfNotNull parameters.TestMetadataPath "/testmetadata:" - |> StringBuilder.appendIfNotNull parameters.TestSettingsPath "/testsettings:" - |> StringBuilder.appendIfNotNull testResultsFile "/resultsfile:" - |> StringBuilder.appendIfTrue parameters.NoIsolation "/noisolation" - |> StringBuilder.forEach parameters.Tests StringBuilder.appendIfNotNullOrEmpty "/test:" - |> StringBuilder.forEach parameters.Details StringBuilder.appendIfNotNullOrEmpty "/detail:" + |> StringBuilder.appendIfTrue (assembly <> null) assembly + |> StringBuilder.appendIfNotNull parameters.SettingsPath "/Settings:" + |> StringBuilder.appendIfTrue (testsToRun <> null) testsToRun + |> StringBuilder.appendIfTrue parameters.EnableCodeCoverage "/EnableCodeCoverage" + |> StringBuilder.appendIfTrue parameters.InIsolation "/InIsolation" + |> StringBuilder.appendIfTrue parameters.UseVsixExtensions "/UseVsixExtensions:true" + |> StringBuilder.appendIfNotNull parameters.Platform "/Platform:" + |> StringBuilder.appendIfNotNull parameters.Framework "/Framework:" + |> StringBuilder.appendIfNotNull parameters.TestCaseFilter "/TestCaseFilter:" + |> StringBuilder.appendIfNotNull parameters.Logger "/Logger:" + |> StringBuilder.appendIfNotNull parameters.ListTestsPath "/ListTests:" + |> StringBuilder.appendIfTrue parameters.ListDiscoverers "/ListDiscoverers" + |> StringBuilder.appendIfTrue parameters.ListExecutors "/ListExecutors" + |> StringBuilder.appendIfTrue parameters.ListLoggers "/ListLoggers" + |> StringBuilder.appendIfTrue parameters.ListSettingsProviders "/ListSettingsProviders" + |> StringBuilder.appendIfNotNull parameters.TestAdapterPath "/TestAdapterPath:" |> StringBuilder.toText -/// Runs MSTest command line tool on a group of assemblies. +/// Runs VSTest command line tool (VSTest.Console.exe) on a group of assemblies. /// ## Parameters /// -/// - `setParams` - Function used to manipulate the default MSTestParams value. +/// - `setParams` - Function used to manipulate the default VSTestParams values. /// - `assemblies` - Sequence of one or more assemblies containing Microsoft Visual Studio Unit Test Framework unit tests. /// /// ## Sample usage /// -/// Target "Test" (fun _ -> +/// Target.create "Test" (fun _ -> /// !! (testDir + @"\*.Tests.dll") -/// |> MSTest (fun p -> { p with Category = "group1" }) +/// |> VSTest.VSTest (fun p -> { p with SettingsPath = "Local.RunSettings" }) /// ) -let exec (setParams : MSTestParams -> MSTestParams) (assemblies : string seq) = +let VSTest (setParams : VSTestParams -> VSTestParams) (assemblies : string seq) = let details = assemblies |> String.separated ", " - use __ = Trace.traceTask "MSTest" details - let parameters = MSTestDefaults |> setParams + use __ = Trace.traceTask "VSTest" details + let parameters = VSTestDefaults |> setParams + if String.IsNullOrEmpty parameters.ToolPath then failwith "VSTest: No tool path specified, or it could not be found automatically." let assemblies = assemblies |> Seq.toArray - if Array.isEmpty assemblies then failwith "MSTest: cannot run tests (the assembly list is empty)." + if Array.isEmpty assemblies then failwith "VSTest: cannot run tests (the assembly list is empty)." let failIfError assembly exitCode = if exitCode > 0 && parameters.ErrorLevel <> ErrorLevel.DontFailBuild then - let message = sprintf "%sMSTest test run failed for %s" Environment.NewLine assembly + let message = sprintf "%sVSTest test run failed for %s" Environment.NewLine assembly Trace.traceError message failwith message for assembly in assemblies do - let args = buildMSTestArgs parameters assembly - Process.execSimple ((fun info -> - { info with - FileName = parameters.ToolPath - WorkingDirectory = parameters.WorkingDir - Arguments = args }) >> Process.withFramework) parameters.TimeOut + let args = buildVSTestArgs parameters assembly + Process.execSimple (fun info -> + { info with + FileName = parameters.ToolPath + WorkingDirectory = parameters.WorkingDir + Arguments = args }) parameters.TimeOut |> failIfError assembly - __.MarkSuccess() From 63439c65186a4e97dc9adf7d303f753e1e1c809b Mon Sep 17 00:00:00 2001 From: Dany Fabian Date: Sat, 30 Jun 2018 13:35:50 +0100 Subject: [PATCH 3/7] Incorporate code review feedback. --- src/app/Fake.DotNet.Testing.VSTest/VSTest.fs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs b/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs index e4558a0efce..d07c121f762 100644 --- a/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs +++ b/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs @@ -1,4 +1,5 @@ /// Contains tasks to run [VSTest](https://msdn.microsoft.com/en-us/library/ms182486.aspx) unit tests. +[] module Fake.DotNet.Testing.VSTest open Fake.Core @@ -7,7 +8,7 @@ open System open System.Text /// [omit] -let vsTestPaths = +let private vsTestPaths = [| @"[ProgramFilesX86]\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow" @"[ProgramFilesX86]\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow" @@ -16,7 +17,7 @@ let vsTestPaths = |] /// [omit] -let vsTestExe = +let private vsTestExe = if Environment.isMono then failwith "VSTest is not supported on the mono platform" else "vstest.console.exe" @@ -24,7 +25,6 @@ let vsTestExe = type ErrorLevel = TestRunnerErrorLevel /// Parameter type to configure [VSTest.Console.exe](https://msdn.microsoft.com/en-us/library/jj155800.aspx) -[] type VSTestParams = { /// Path to the run settings file to run tests with additional settings such as data collectors (optional). SettingsPath : string @@ -66,7 +66,7 @@ type VSTestParams = TestAdapterPath: string} /// VSTest default parameters. -let VSTestDefaults = +let private VSTestDefaults = { SettingsPath = null Tests = [] EnableCodeCoverage = false @@ -92,7 +92,7 @@ let VSTestDefaults = /// Builds the command line arguments from the given parameter record and the given assemblies. /// [omit] -let buildVSTestArgs (parameters : VSTestParams) assembly = +let private buildVSTestArgs (parameters : VSTestParams) assembly = let testsToRun = if not (Seq.isEmpty parameters.Tests) then sprintf @"/Tests:%s" (parameters.Tests |> String.separated ",") @@ -116,7 +116,7 @@ let buildVSTestArgs (parameters : VSTestParams) assembly = |> StringBuilder.appendIfNotNull parameters.TestAdapterPath "/TestAdapterPath:" |> StringBuilder.toText -/// Runs VSTest command line tool (VSTest.Console.exe) on a group of assemblies. +/// Runs VSTest command line tool (VSTest.Console.exe) on a group of assemblies.m /// ## Parameters /// /// - `setParams` - Function used to manipulate the default VSTestParams values. @@ -128,7 +128,7 @@ let buildVSTestArgs (parameters : VSTestParams) assembly = /// !! (testDir + @"\*.Tests.dll") /// |> VSTest.VSTest (fun p -> { p with SettingsPath = "Local.RunSettings" }) /// ) -let VSTest (setParams : VSTestParams -> VSTestParams) (assemblies : string seq) = +let run (setParams : VSTestParams -> VSTestParams) (assemblies : string seq) = let details = assemblies |> String.separated ", " use __ = Trace.traceTask "VSTest" details let parameters = VSTestDefaults |> setParams From ad6ffdf0f1a15723f6648b21d38df04225d9460e Mon Sep 17 00:00:00 2001 From: Dany Fabian Date: Wed, 11 Jul 2018 15:58:10 +0100 Subject: [PATCH 4/7] Update the Obsolete error messages. --- src/legacy/FakeLib/UnitTest/VSTest.fs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/legacy/FakeLib/UnitTest/VSTest.fs b/src/legacy/FakeLib/UnitTest/VSTest.fs index 6983a974ac6..7005278120e 100644 --- a/src/legacy/FakeLib/UnitTest/VSTest.fs +++ b/src/legacy/FakeLib/UnitTest/VSTest.fs @@ -1,30 +1,30 @@ /// Contains tasks to run [VSTest](https://msdn.microsoft.com/en-us/library/ms182486.aspx) unit tests. -[] +[] module Fake.VSTest open System open System.Text /// [omit] -[] +[] let vsTestPaths = [| @"[ProgramFilesX86]\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow"; @"[ProgramFilesX86]\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow"; @"[ProgramFilesX86]\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow" |] /// [omit] -[] +[] let vsTestExe = if isMono then failwith "VSTest is not supported on the mono platform" else "vstest.console.exe" /// Option which allow to specify if a VSTest error should break the build. -[] +[] type ErrorLevel = TestRunnerErrorLevel /// Parameter type to configure [VSTest.Console.exe](https://msdn.microsoft.com/en-us/library/jj155800.aspx) +[] [] -[] type VSTestParams = { /// Path to the run settings file to run tests with additional settings such as data collectors (optional). SettingsPath : string @@ -66,7 +66,7 @@ type VSTestParams = TestAdapterPath: string} /// VSTest default parameters. -[] +[] let VSTestDefaults = { SettingsPath = null Tests = [] @@ -93,7 +93,7 @@ let VSTestDefaults = /// Builds the command line arguments from the given parameter record and the given assemblies. /// [omit] -[] +[] let buildVSTestArgs (parameters : VSTestParams) assembly = let testsToRun = if not (Seq.isEmpty parameters.Tests) then @@ -130,7 +130,7 @@ let buildVSTestArgs (parameters : VSTestParams) assembly = /// !! (testDir + @"\*.Tests.dll") /// |> VSTest (fun p -> { p with SettingsPath = "Local.RunSettings" }) /// ) -[] +[] let VSTest (setParams : VSTestParams -> VSTestParams) (assemblies : string seq) = let details = assemblies |> separated ", " use __ = traceStartTaskUsing "VSTest" details From 6ca34858fd91885ebebefa2c3e8fe201f1aa9790 Mon Sep 17 00:00:00 2001 From: Dany Fabian Date: Wed, 11 Jul 2018 16:02:27 +0100 Subject: [PATCH 5/7] Add link to API docs. --- help/templates/template.cshtml | 1 + 1 file changed, 1 insertion(+) diff --git a/help/templates/template.cshtml b/help/templates/template.cshtml index 5d066a0ee35..142e572d89a 100644 --- a/help/templates/template.cshtml +++ b/help/templates/template.cshtml @@ -135,6 +135,7 @@
  • Testing - MSpec
  • Testing - XUnit2
  • Testing - Expecto
  • +
  • Testing - VSTest
  • Testing - SpecFlow
  • Testing - OpenCover
  • NuGet
  • From b15335ea099555809e3fea532960b39a2cf6fc44 Mon Sep 17 00:00:00 2001 From: Dany Fabian Date: Wed, 11 Jul 2018 16:32:20 +0100 Subject: [PATCH 6/7] Fix incorrect assembly name. --- .../Fake.DotNet.Testing.VSTest.fsproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/Fake.DotNet.Testing.VSTest/Fake.DotNet.Testing.VSTest.fsproj b/src/app/Fake.DotNet.Testing.VSTest/Fake.DotNet.Testing.VSTest.fsproj index a9d168222c2..70bc99fba92 100644 --- a/src/app/Fake.DotNet.Testing.VSTest/Fake.DotNet.Testing.VSTest.fsproj +++ b/src/app/Fake.DotNet.Testing.VSTest/Fake.DotNet.Testing.VSTest.fsproj @@ -2,7 +2,7 @@ net46;netstandard1.6;netstandard2.0 $(DefineConstants);NO_DOTNETCORE_BOOTSTRAP - Fake.DotNet.Testing.MSTest + Fake.DotNet.Testing.VSTest Library From ca93ff5b6d434b98305adfe027a7d365e542b4e5 Mon Sep 17 00:00:00 2001 From: Dany Fabian Date: Wed, 11 Jul 2018 17:23:45 +0100 Subject: [PATCH 7/7] Update API doc. --- src/app/Fake.DotNet.Testing.VSTest/VSTest.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs b/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs index d07c121f762..f1e6620a4f1 100644 --- a/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs +++ b/src/app/Fake.DotNet.Testing.VSTest/VSTest.fs @@ -116,7 +116,7 @@ let private buildVSTestArgs (parameters : VSTestParams) assembly = |> StringBuilder.appendIfNotNull parameters.TestAdapterPath "/TestAdapterPath:" |> StringBuilder.toText -/// Runs VSTest command line tool (VSTest.Console.exe) on a group of assemblies.m +/// Runs the VSTest command line tool (VSTest.Console.exe) on a group of assemblies. /// ## Parameters /// /// - `setParams` - Function used to manipulate the default VSTestParams values. @@ -126,7 +126,7 @@ let private buildVSTestArgs (parameters : VSTestParams) assembly = /// /// Target.create "Test" (fun _ -> /// !! (testDir + @"\*.Tests.dll") -/// |> VSTest.VSTest (fun p -> { p with SettingsPath = "Local.RunSettings" }) +/// |> VSTest.run (fun p -> { p with SettingsPath = "Local.RunSettings" }) /// ) let run (setParams : VSTestParams -> VSTestParams) (assemblies : string seq) = let details = assemblies |> String.separated ", "