Skip to content

Commit

Permalink
Merge pull request #928 from jhamm/xunit2-noappdomain
Browse files Browse the repository at this point in the history
Add support for new Xunit2 runner -noappdomain flag
  • Loading branch information
forki committed Aug 27, 2015
2 parents 52a1c3f + 929c2be commit d657ec2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/app/FakeLib/UnitTest/XUnit/XUnit2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Fake.Testing.XUnit2

open System
open System.IO
open System.Linq
open System.Text
open Fake

Expand All @@ -14,6 +15,7 @@ Copyright (C) 2014 Outercurve Foundation.
usage: xunit.console <assemblyFile> [configFile] [options]
Valid options:
-noappdomain : do not use app domains to run test code
-parallel option : set parallelization based on option
: none - turn off all parallelization
: collections - only parallelize collections
Expand Down Expand Up @@ -70,6 +72,8 @@ type CollectionConcurrencyMode =
type XUnit2Params =
{ /// The path to the xUnit console runner: `xunit.console.exe`
ToolPath : string
/// Do not use app domains to run test code.
NoAppDomain : bool
/// The xUnit parallelization mode.
Parallel : ParallelMode
/// The xUnit thread limiting strategy.
Expand Down Expand Up @@ -107,6 +111,7 @@ type XUnit2Params =
///
/// ## Defaults
///
/// - `NoAppDomain` - `false`
/// - `Parallel` - `NoParallelization`
/// - `MaxThreads` - `Default`
/// - `HtmlOutputPath` - `None`
Expand All @@ -124,7 +129,8 @@ type XUnit2Params =
/// - `Silent` - `false`
/// - `Wait` - `false`
let XUnit2Defaults =
{ Parallel = NoParallelization
{ NoAppDomain = false
Parallel = NoParallelization
MaxThreads = Default
HtmlOutputPath = None
XmlOutputPath = None
Expand All @@ -151,6 +157,7 @@ let internal buildXUnit2Args assemblies parameters =

new StringBuilder()
|> appendFileNamesIfNotNull assemblies
|> appendIfTrueWithoutQuotes parameters.NoAppDomain "-noappdomain"
|> appendWithoutQuotes "-parallel"
|> appendWithoutQuotes (ParallelMode.ToArgument parameters.Parallel)
|> appendIfSome (CollectionConcurrencyMode.ToArgument parameters.MaxThreads) (sprintf "-maxthreads %d")
Expand All @@ -167,6 +174,16 @@ let internal buildXUnit2Args assemblies parameters =
|> appendTraits parameters.ExcludeTraits "-notrait"
|> toText

/// Helper method to detect if the xunit console runner supports the -noappdomain flag.
/// If the xunit console runner does not support this flag, it will change the value to false
/// so it does not interfere with older versions.
let internal discoverNoAppDomainExists parameters =
let helpText =
ExecProcessAndReturnMessages (fun info ->
info.FileName <- parameters.ToolPath ) (TimeSpan.FromMinutes 1.)
let canSetNoAppDomain = helpText.Messages.Any(fun msg -> msg.Contains("-noappdomain"))
{parameters with NoAppDomain = canSetNoAppDomain}

module internal ResultHandling =
let (|OK|Failure|) = function
| 0 -> OK
Expand Down Expand Up @@ -205,7 +222,12 @@ module internal ResultHandling =
let xUnit2 setParams assemblies =
let details = separated ", " assemblies
traceStartTask "xUnit2" details
let parameters = setParams XUnit2Defaults
let parametersFirst = setParams XUnit2Defaults

let parameters =
if parametersFirst.NoAppDomain
then discoverNoAppDomainExists parametersFirst
else parametersFirst

let result =
ExecProcess (fun info ->
Expand Down
12 changes: 12 additions & 0 deletions src/test/Test.FAKECore/XUnit2Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ internal class When_using_the_default_parameters

It should_not_force_AppVeyor_output = () =>
Arguments.ShouldNotContain(" -appveyor");

It should_not_force_NoAppDomain = () =>
Arguments.ShouldNotContain(" -noappdomain");
}

internal class When_using_parameters_which_include_traits
Expand All @@ -79,6 +82,7 @@ internal class When_using_parameters_which_include_traits
{
Parameters = new XUnit2.XUnit2Params(
XUnit2.XUnit2Defaults.ToolPath,
XUnit2.XUnit2Defaults.NoAppDomain,
XUnit2.XUnit2Defaults.Parallel,
XUnit2.XUnit2Defaults.MaxThreads,
XUnit2.XUnit2Defaults.HtmlOutputPath,
Expand Down Expand Up @@ -114,6 +118,7 @@ internal class When_using_parameters_which_include_reports
{
Parameters = new XUnit2.XUnit2Params(
XUnit2.XUnit2Defaults.ToolPath,
XUnit2.XUnit2Defaults.NoAppDomain,
XUnit2.XUnit2Defaults.Parallel,
XUnit2.XUnit2Defaults.MaxThreads,
FSharpOption<string>.Some("html.html"),
Expand Down Expand Up @@ -152,6 +157,7 @@ internal class When_using_parameters_which_request_total_parallel_execution
{
Parameters = new XUnit2.XUnit2Params(
XUnit2.XUnit2Defaults.ToolPath,
XUnit2.XUnit2Defaults.NoAppDomain,
XUnit2.ParallelMode.All,
XUnit2.CollectionConcurrencyMode.Unlimited,
XUnit2.XUnit2Defaults.HtmlOutputPath,
Expand Down Expand Up @@ -184,6 +190,7 @@ internal class When_using_parameters_which_request_assembly_only_parallel_execut
{
Parameters = new XUnit2.XUnit2Params(
XUnit2.XUnit2Defaults.ToolPath,
XUnit2.XUnit2Defaults.NoAppDomain,
XUnit2.ParallelMode.Assemblies,
XUnit2.CollectionConcurrencyMode.Default,
XUnit2.XUnit2Defaults.HtmlOutputPath,
Expand Down Expand Up @@ -216,6 +223,7 @@ internal class When_using_parameters_which_request_collection_only_parallel_exec
{
Parameters = new XUnit2.XUnit2Params(
XUnit2.XUnit2Defaults.ToolPath,
XUnit2.XUnit2Defaults.NoAppDomain,
XUnit2.ParallelMode.Collections,
XUnit2.CollectionConcurrencyMode.NewMaxThreads(42),
XUnit2.XUnit2Defaults.HtmlOutputPath,
Expand Down Expand Up @@ -249,6 +257,7 @@ internal class When_using_parameters_which_request_non_default_flags
{
Parameters = new XUnit2.XUnit2Params(
XUnit2.XUnit2Defaults.ToolPath,
!XUnit2.XUnit2Defaults.NoAppDomain,
XUnit2.XUnit2Defaults.Parallel,
XUnit2.XUnit2Defaults.MaxThreads,
XUnit2.XUnit2Defaults.HtmlOutputPath,
Expand Down Expand Up @@ -281,6 +290,9 @@ internal class When_using_parameters_which_request_non_default_flags

It should_force_AppVeyor_output = () =>
Arguments.ShouldContain(" -appveyor");

It should_force_NoAppDomain = () =>
Arguments.ShouldContain(" -noappdomain");
}

[Subject(typeof(XUnit2), "result handling")]
Expand Down

0 comments on commit d657ec2

Please sign in to comment.