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
MSTest: add Tests parameter to specify list of tests #1615
Merged
matthid
merged 5 commits into
fsprojects:master
from
alex-bogomaz:mstest-specify-tests-to-run
Jul 28, 2017
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4caaf6a
MSTest: add Tests parameter to specify list of tests
alex-bogomaz 94a47de
Merge branch 'master' into mstest-specify-tests-to-run
alex-bogomaz 43626f4
Added MSTest module
alex-bogomaz 40fe900
Move MSTest module closer to other test modules
alex-bogomaz 9466708
Run MSTestSpecs on Windows only
alex-bogomaz File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 mstest test runner")>] | ||
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>] | ||
[<assembly: AssemblyVersionAttribute("5.0.0")>] | ||
[<assembly: AssemblyInformationalVersionAttribute("5.0.0")>] | ||
[<assembly: AssemblyFileVersionAttribute("5.0.0")>] | ||
do () | ||
|
||
module internal AssemblyVersionInformation = | ||
let [<Literal>] AssemblyTitle = "FAKE - F# Make Running mstest test runner" | ||
let [<Literal>] AssemblyProduct = "FAKE - F# Make" | ||
let [<Literal>] AssemblyVersion = "5.0.0" | ||
let [<Literal>] AssemblyInformationalVersion = "5.0.0" | ||
let [<Literal>] AssemblyFileVersion = "5.0.0" |
55 changes: 55 additions & 0 deletions
55
src/app/Fake.DotNet.Testing.MSTest/Fake.DotNet.Testing.MSTest.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VersionPrefix>1.0.0-alpha-10</VersionPrefix> | ||
<!--<TargetFrameworks>net46;netstandard1.6</TargetFrameworks>--> | ||
<TargetFramework>netstandard1.6</TargetFramework> | ||
<DefineConstants>$(DefineConstants);NO_DOTNETCORE_BOOTSTRAP</DefineConstants> | ||
<DebugType>pdbonly</DebugType> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<AssemblyName>Fake.DotNet.Testing.MSTest</AssemblyName> | ||
<OutputType>Library</OutputType> | ||
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);portable-net45+win8;dnxcore50</PackageTargetFallback> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' "> | ||
<DefineConstants>$(DefineConstants);NETSTANDARD;USE_HTTPCLIENT</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyInfo.fs" /> | ||
<Compile Include="MSTest.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.Tracing\Fake.Core.Tracing.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.String\Fake.Core.String.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.Globbing\Fake.Core.Globbing.fsproj" /> | ||
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.BuildServer\Fake.Core.BuildServer.fsproj" /> | ||
<ProjectReference Include="..\Fake.Testing.Common\Fake.Testing.Common.fsproj"> | ||
<FromP2P>true</FromP2P> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj"> | ||
<FromP2P>true</FromP2P> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<!--<ItemGroup Condition=" '$(TargetFramework)' == 'net46' "> | ||
<Reference Include="mscorlib"> | ||
<FromP2P>true</FromP2P> | ||
</Reference> | ||
<Reference Include="System"> | ||
<FromP2P>true</FromP2P> | ||
</Reference> | ||
<Reference Include="System.Core"> | ||
<FromP2P>true</FromP2P> | ||
</Reference> | ||
</ItemGroup>--> | ||
<ItemGroup> | ||
<DotNetCliToolReference Include="dotnet-compile-fsc"> | ||
<Version>1.0.0-preview2-020000</Version> | ||
</DotNetCliToolReference> | ||
</ItemGroup> | ||
<Import Project="..\..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/// 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.String | ||
open Fake.Core.Process | ||
open Fake.Core | ||
open Fake.Testing.Common | ||
|
||
/// [omit] | ||
let mstestPaths = | ||
[| @"[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.isMono then failwith "MSTest is not supported on mono platform" | ||
else "mstest.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. | ||
type ErrorLevel = TestRunnerErrorLevel | ||
|
||
/// Parameter type to configure the MSTest.exe. | ||
[<CLIMutable>] | ||
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 | ||
/// 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 tryFindFile mstestPaths mstestexe with | ||
| Some path -> path | ||
| None -> "" | ||
ErrorLevel = ErrorLevel.Error | ||
NoIsolation = true } | ||
|
||
/// Builds the command line arguments from the given parameter record and the given assemblies. | ||
/// [omit] | ||
let buildMSTestArgs parameters assembly = | ||
let testResultsFile = | ||
if parameters.ResultsDir <> null then | ||
sprintf @"%s\%s.trx" parameters.ResultsDir (DateTime.Now.ToString("yyyyMMdd-HHmmss.ff")) | ||
else null | ||
|
||
let builder = | ||
new StringBuilder() | ||
|> appendIfNotNull assembly "/testcontainer:" | ||
|> appendIfNotNull parameters.Category "/category:" | ||
|> appendIfNotNull parameters.TestMetadataPath "/testmetadata:" | ||
|> appendIfNotNull parameters.TestSettingsPath "/testsettings:" | ||
|> appendIfNotNull testResultsFile "/resultsfile:" | ||
|> appendIfTrue parameters.NoIsolation "/noisolation" | ||
|
||
parameters.Tests | ||
|> List.iter (fun t -> builder |> appendIfNotNullOrEmpty t "/test:" |> ignore) | ||
|
||
builder |> 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 MSTest (setParams : MSTestParams -> MSTestParams) (assemblies : string seq) = | ||
let details = assemblies |> 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 | ||
ExecProcess (fun info -> | ||
info.FileName <- parameters.ToolPath | ||
info.WorkingDirectory <- parameters.WorkingDir | ||
info.Arguments <- args) parameters.TimeOut | ||
|> failIfError assembly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
group netcore | ||
FSharp.NET.Sdk | ||
FSharp.Core | ||
NETStandard.Library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,6 +306,9 @@ | |
<Compile Include="UnitTest\MSTest.fs" /> | ||
<Compile Include="UnitTest\ProcessTestRunner.fs" /> | ||
<Compile Include="UnitTest\VSTest.fs" /> | ||
<Compile Include="..\Fake.DotNet.Testing.MSTest\MSTest.fs"> | ||
<Link>Fake.DotNet.Testing.MSTest/MSTest.fs</Link> | ||
</Compile> | ||
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. Can we move that up to the other "Modules"? This prevents accidental usage of "old" members (and makes the IDE help you) |
||
<Compile Include="AssemblyInfoFile.fs" /> | ||
<Compile Include="AssemblyInfoHelper.fs" /> | ||
<Compile Include="FXCopHelper.fs" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We have a small bootstrapping problem with this ;). I think we can remove those lines for now.