Skip to content
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

Added a way to set the --trace parameter on the NUnit3 command line #1513

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions src/app/FakeLib/UnitTest/NUnit/NUnit3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ open System.IO
open Fake

/// Process model for NUnit 3 to use.
type NUnit3ProcessModel =
type NUnit3ProcessModel =
| DefaultProcessModel
| SingleProcessModel
| SeparateProcessModel
| MultipleProcessModel with
| MultipleProcessModel with
member x.ParamString =
match x with
| DefaultProcessModel -> ""
| SingleProcessModel -> "Single"
| SeparateProcessModel -> "Separate"
| SeparateProcessModel -> "Separate"
| MultipleProcessModel -> "Multiple"

/// The --domain option controls of the creation of AppDomains for running tests. See [NUnit-Console Command Line Options](http://www.nunit.org/index.php?p=consoleCommandLine&r=2.6.4)
type NUnit3DomainModel =
type NUnit3DomainModel =
/// The default is to use multiple domains if multiple assemblies are listed on the command line. Otherwise a single domain is used.
| DefaultDomainModel
/// No domain is created - the tests are run in the primary domain. This normally requires copying the NUnit assemblies into the same directory as your tests.
Expand All @@ -37,7 +38,7 @@ type NUnit3DomainModel =

/// The --framework option in running NUnit 3. There are three kinds - VXY, which means either .NET framework or Mono, NetXY (use .NET framework with given version)
/// and MonoXY (Mono framework with given version). You can use Net or Mono to let NUnit select the version.
/// You can pass any value using Other.
/// You can pass any value using Other.
type NUnit3Runtime =
/// Uses the runtime under which the assembly was built.
| Default
Expand Down Expand Up @@ -84,6 +85,23 @@ type NUnit3Runtime =
/// Option which allows to specify if a NUnit error should break the build.
type NUnit3ErrorLevel = TestRunnerErrorLevel

/// The --trace option in NUnit3 console runner. Specifies the internal nunit runner log level.
type NUnit3TraceLevel =
| Default
| Off
| Error
| Warning
| Info
| Verbose
member x.ParamString =
match x with
| Default -> ""
| Off -> "Off"
| Error -> "Error"
| Warning -> "Warning"
| Info -> "Info"
| Verbose -> "Verbose"

/// The --labels option in NUnit3 console runner. Specify whether to write test case names to the output.
type LabelsLevel =
| Default
Expand All @@ -108,8 +126,8 @@ type NUnit3Params =
/// The name (or path) of a file containing a list of tests to run or explore, one per line.
Testlist : string

/// An expression indicating which tests to run. It may specify test names, classes, methods,
/// catgories or properties comparing them to actual values with the operators ==, !=, =~ and !~.
/// An expression indicating which tests to run. It may specify test names, classes, methods,
/// catgories or properties comparing them to actual values with the operators ==, !=, =~ and !~.
/// See [NUnit documentation](https://github.com/nunit/docs/wiki/Test-Selection-Language) for a full description of the syntax.
Where : string

Expand All @@ -126,7 +144,7 @@ type NUnit3Params =

/// Controls how NUnit loads tests in processes. See: [NUnit3ProcessModel](fake-testing-nunit3-nunit3domainmodel.html).
Domain : NUnit3DomainModel

/// Allows you to specify the version of the runtime to be used in executing tests.
/// Default value is runtime under which the assembly was built. See: [NUnit3Runtime](fake-testing-nunit3-nunit3runtime.html).
Framework : NUnit3Runtime
Expand Down Expand Up @@ -176,6 +194,9 @@ type NUnit3Params =

/// Default: [TestRunnerErrorLevel](fake-unittestcommon-testrunnererrorlevel.html).Error
ErrorLevel : NUnit3ErrorLevel

/// Controls the trace logs NUnit3 will output, defaults to Off
TraceLevel : NUnit3TraceLevel
}

/// The [NUnit3Params](fake-testing-nunit3-nunit3params.html) default parameters.
Expand All @@ -185,7 +206,7 @@ type NUnit3Params =
/// - `Where` - `""`
/// - `Config` - `""`
/// - `ProcessModel` - `DefaultProcessModel`
/// - `Agents` - `None`
/// - `Agents` - `None`
/// - `Domain` - `DefaultDomainModel`
/// - `Framework` - `""`
/// - `Force32bit` - `false`
Expand All @@ -201,6 +222,7 @@ type NUnit3Params =
/// - `ShadowCopy` - `false`
/// - `TeamCity` - `false`
/// - `ErrorLevel` - `Error`
/// - `TraceLevel` - `Default` (By default NUnit3 sets this to off internally)
/// ## Defaults
let NUnit3Defaults =
{
Expand All @@ -225,7 +247,8 @@ let NUnit3Defaults =
ShadowCopy = false
TeamCity = false
Labels = LabelsLevel.Default
ErrorLevel = Error
ErrorLevel = NUnit3ErrorLevel.Error
TraceLevel= NUnit3TraceLevel.Default
}

/// Tries to detect the working directory as specified in the parameters or via TeamCity settings
Expand Down Expand Up @@ -253,6 +276,7 @@ let buildNUnit3Args parameters assemblies =
|> appendIfNotNullOrEmpty parameters.Domain.ParamString "--domain="
|> appendIfNotNullOrEmpty parameters.Framework.ParamString "--framework="
|> appendIfNotNullOrEmpty parameters.Labels.ParamString "--labels="
|> appendIfNotNullOrEmpty parameters.TraceLevel.ParamString "--trace="
|> appendIfTrue parameters.Force32bit "--x86"
|> appendIfTrue parameters.DisposeRunners "--dispose-runners"
|> appendIfTrue (parameters.TimeOut <> NUnit3Defaults.TimeOut) (sprintf "--timeout=%i" (int parameters.TimeOut.TotalMilliseconds))
Expand All @@ -278,23 +302,23 @@ let NUnit3 (setParams : NUnit3Params -> NUnit3Params) (assemblies : string seq)
let args = buildNUnit3Args parameters assemblies
trace (tool + " " + args)
let processTimeout = TimeSpan.MaxValue // Don't set a process timeout. The timeout is per test.
let result =
ExecProcess (fun info ->
let result =
ExecProcess (fun info ->
info.FileName <- tool
info.WorkingDirectory <- getWorkingDir parameters
info.Arguments <- args) processTimeout
let errorDescription error =
let errorDescription error =
match error with
| OK -> "OK"
| TestsFailed -> sprintf "NUnit test failed (%d)." error
| FatalError x -> sprintf "NUnit test failed. Process finished with exit code %s (%d)." x error

match parameters.ErrorLevel with
| DontFailBuild ->
| NUnit3ErrorLevel.DontFailBuild ->
match result with
| OK | TestsFailed -> ()
| _ -> raise (FailedTestsException(errorDescription result))
| Error | FailOnFirstError ->
| NUnit3ErrorLevel.Error | FailOnFirstError ->
match result with
| OK -> ()
| _ -> raise (FailedTestsException(errorDescription result))
72 changes: 72 additions & 0 deletions src/test/Test.FAKECore/NUnit3Specs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using Fake.Testing;
using Machine.Specifications;

namespace Test.FAKECore.Testing.NUnit3Specs
{
[Subject(typeof(NUnit3), "runner argument construction")]
internal abstract class BuildArgumentsSpecsBase
{
private Establish context = () =>
{
Assemblies = new[] {"test1.dll", "test2.dll"};
Parameters = NUnit3.NUnit3Defaults;
};

Because of = () =>
{
Arguments = NUnit3.buildNUnit3Args(Parameters, Assemblies);
Console.WriteLine(Arguments);
};

protected static NUnit3.NUnit3Params Parameters;
protected static string[] Assemblies;
protected static string Arguments;
}

internal class When_using_the_default_parameters
: BuildArgumentsSpecsBase
{
It should_not_set_any_trace_value = () =>
{
Arguments.ShouldNotContain("--trace");
};
}

internal class When_using_non_default_trace_parameter
: BuildArgumentsSpecsBase
{
Establish context = () =>
{
Parameters = new NUnit3.NUnit3Params(
NUnit3.NUnit3Defaults.ToolPath,
NUnit3.NUnit3Defaults.Testlist,
NUnit3.NUnit3Defaults.Where,
NUnit3.NUnit3Defaults.Config,
NUnit3.NUnit3Defaults.ProcessModel,
NUnit3.NUnit3Defaults.Agents,
NUnit3.NUnit3Defaults.Domain,
NUnit3.NUnit3Defaults.Framework,
NUnit3.NUnit3Defaults.Force32bit,
NUnit3.NUnit3Defaults.DisposeRunners,
NUnit3.NUnit3Defaults.TimeOut,
NUnit3.NUnit3Defaults.Seed,
NUnit3.NUnit3Defaults.Workers,
NUnit3.NUnit3Defaults.StopOnError,
NUnit3.NUnit3Defaults.WorkingDir,
NUnit3.NUnit3Defaults.OutputDir,
NUnit3.NUnit3Defaults.ErrorDir,
NUnit3.NUnit3Defaults.ResultSpecs,
NUnit3.NUnit3Defaults.ShadowCopy,
NUnit3.NUnit3Defaults.TeamCity,
NUnit3.NUnit3Defaults.Labels,
NUnit3.NUnit3Defaults.ErrorLevel,
NUnit3.NUnit3TraceLevel.Verbose);
};

It should_include_the_expected_trace_argument = () =>
{
Arguments.ShouldContain(@"--trace=Verbose");
};
}
}
1 change: 1 addition & 0 deletions src/test/Test.FAKECore/Test.FAKECore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<Compile Include="FileHandling\GlobbingSpecs.cs" />
<Compile Include="XUnit2HelperSpecs.cs" />
<Compile Include="XUnitHelperSpecs.cs" />
<Compile Include="NUnit3Specs.cs" />
<Compile Include="XUnitSpecs.cs" />
<Compile Include="XUnit2Specs.cs" />
</ItemGroup>
Expand Down