-
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
Port VSTest to FAKE 5 #2008
Port VSTest to FAKE 5 #2008
Changes from 3 commits
320bdd6
fd78339
575e15f
63439c6
ad6ffdf
6ca3485
b15335e
ca93ff5
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,17 @@ | ||
// Auto-Generated by FAKE; do not edit | ||
namespace System | ||
open System.Reflection | ||
|
||
[<assembly: AssemblyTitleAttribute("FAKE - F# Make Running VSTest test runner")>] | ||
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>] | ||
[<assembly: AssemblyVersionAttribute("5.1.0")>] | ||
[<assembly: AssemblyInformationalVersionAttribute("5.1.0")>] | ||
[<assembly: AssemblyFileVersionAttribute("5.1.0")>] | ||
do () | ||
|
||
module internal AssemblyVersionInformation = | ||
let [<Literal>] AssemblyTitle = "FAKE - F# Make Running VSTest test runner" | ||
let [<Literal>] AssemblyProduct = "FAKE - F# Make" | ||
let [<Literal>] AssemblyVersion = "5.1.0" | ||
let [<Literal>] AssemblyInformationalVersion = "5.1.0" | ||
let [<Literal>] AssemblyFileVersion = "5.1.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks> | ||
<DefineConstants>$(DefineConstants);NO_DOTNETCORE_BOOTSTRAP</DefineConstants> | ||
<AssemblyName>Fake.DotNet.Testing.MSTest</AssemblyName> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DefineConstants>$(DefineConstants);NETSTANDARD;USE_HTTPCLIENT</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyInfo.fs" /> | ||
<Compile Include="VSTest.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.Trace\Fake.Core.Trace.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.String\Fake.Core.String.fsproj" /> | ||
<ProjectReference Include="..\Fake.Testing.Common\Fake.Testing.Common.fsproj" /> | ||
</ItemGroup> | ||
<Import Project="..\..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/// Contains tasks to run [VSTest](https://msdn.microsoft.com/en-us/library/ms182486.aspx) unit tests. | ||
module Fake.DotNet.Testing.VSTest | ||
|
||
open Fake.Core | ||
open Fake.Testing.Common | ||
open System | ||
open System.Text | ||
|
||
/// [omit] | ||
let vsTestPaths = | ||
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. internal? |
||
[| | ||
@"[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 vsTestExe = | ||
if Environment.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) | ||
[<CLIMutable>] | ||
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. remove CliMutable |
||
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<string> | ||
/// 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 | ||
/// A timeout for the test runner (optional). | ||
TimeOut : TimeSpan | ||
/// Error level for controlling how VSTest failures should break the build (optional). | ||
ErrorLevel : ErrorLevel | ||
/// Path to test adapter e.g. xUnit (optional) | ||
TestAdapterPath: string} | ||
|
||
/// VSTest default parameters. | ||
let VSTestDefaults = | ||
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. internal |
||
{ SettingsPath = null | ||
Tests = [] | ||
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 vsTestPaths vsTestExe with | ||
| Some path -> path | ||
| None -> "" | ||
WorkingDir = null | ||
TimeOut = TimeSpan.MaxValue | ||
ErrorLevel = ErrorLevel.Error | ||
TestAdapterPath = null } | ||
|
||
/// Builds the command line arguments from the given parameter record and the given assemblies. | ||
/// [omit] | ||
let buildVSTestArgs (parameters : VSTestParams) assembly = | ||
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. internal? |
||
let testsToRun = | ||
if not (Seq.isEmpty parameters.Tests) then | ||
sprintf @"/Tests:%s" (parameters.Tests |> String.separated ",") | ||
else null | ||
new StringBuilder() | ||
|> 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 VSTest command line tool (VSTest.Console.exe) on a group of assemblies. | ||
/// ## Parameters | ||
/// | ||
/// - `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.create "Test" (fun _ -> | ||
/// !! (testDir + @"\*.Tests.dll") | ||
/// |> VSTest.VSTest (fun p -> { p with SettingsPath = "Local.RunSettings" }) | ||
/// ) | ||
let VSTest (setParams : VSTestParams -> VSTestParams) (assemblies : string seq) = | ||
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. Maybe rename that such that it looks like |
||
let details = assemblies |> String.separated ", " | ||
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 "VSTest: cannot run tests (the assembly list is empty)." | ||
let failIfError assembly exitCode = | ||
if exitCode > 0 && parameters.ErrorLevel <> ErrorLevel.DontFailBuild then | ||
let message = sprintf "%sVSTest test run failed for %s" Environment.NewLine assembly | ||
Trace.traceError message | ||
failwith message | ||
for assembly in assemblies do | ||
let args = buildVSTestArgs parameters assembly | ||
Process.execSimple (fun info -> | ||
{ info with | ||
FileName = parameters.ToolPath | ||
WorkingDirectory = parameters.WorkingDir | ||
Arguments = args }) parameters.TimeOut | ||
|> failIfError assembly |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
group netcore | ||
|
||
FSharp.Core | ||
NETStandard.Library |
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 add
[<RequireQualifiedAccess>]