-
Notifications
You must be signed in to change notification settings - Fork 585
/
Common.fs
205 lines (178 loc) · 8.56 KB
/
Common.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
[<AutoOpen>]
[<System.Obsolete("use Fake.DotNet.Testing.NUnit instead")>]
/// Contains types and utility functions relaited to running [NUnit](http://www.nunit.org/) unit tests.
module Fake.NUnitCommon
#nowarn "44"
open System
open System.IO
open System.Text
/// Option which allows to specify if a NUnit error should break the build.
[<System.Obsolete("use Fake.DotNet.Testing.NUnit instead")>]
type NUnitErrorLevel = TestRunnerErrorLevel // a type alias to keep backwards compatibility
/// Process model for nunit to use, see [Project Editor](http://www.nunit.org/index.php?p=projectEditor&r=2.6.4)
[<System.Obsolete("use Fake.DotNet.Testing.NUnit instead")>]
type NUnitProcessModel =
| DefaultProcessModel
| SingleProcessModel
| SeparateProcessModel
| MultipleProcessModel with
member x.ParamString =
match x with
| DefaultProcessModel -> ""
| SingleProcessModel -> "Single"
| 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)
[<System.Obsolete("use Fake.DotNet.Testing.NUnit instead")>]
type NUnitDomainModel =
/// 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.
| NoDomainModel
/// A test domain is created - this is how NUnit worked prior to version 2.4
| SingleDomainModel
/// A separate test domain is created for each assembly
| MultipleDomainModel with
member x.ParamString =
match x with
| DefaultDomainModel -> ""
| NoDomainModel -> "None"
| SingleDomainModel -> "Single"
| MultipleDomainModel -> "Multiple"
/// The [NUnit](http://www.nunit.org/) Console Parameters type.
/// FAKE will use [NUnitDefaults](fake-nunitcommon.html) for values not provided.
///
/// For reference, see: [NUnit-Console Command Line Options](http://www.nunit.org/index.php?p=consoleCommandLine&r=2.6.4)
[<CLIMutable>]
[<System.Obsolete("use Fake.DotNet.Testing.NUnit instead")>]
type NUnitParams =
{
/// The [Categories](http://www.nunit.org/index.php?p=category&r=2.6.4) to be included in a test run. Multiple categories may be specified on either option, by using commas to separate them.
IncludeCategory : string
/// The [Categories](http://www.nunit.org/index.php?p=category&r=2.6.4) to be excluded in a test run. Multiple categories may be specified on either option, by using commas to separate them.
ExcludeCategory : string
/// The path to the NUnit console runner: `nunit-console.exe`
ToolPath : string
/// NUnit console runner name. ( `nunit-console.exe`)
ToolName : string
/// Suppresses use of a separate thread for running the tests and uses the main thread instead.
DontTestInNewThread : bool
/// Causes execution of the test run to terminate immediately on the first test failure or error.
StopOnError : bool
/// Gives ability to not error if an assembly with no tests is passed into nunit
SkipNonTestAssemblies : bool
/// The output path of the nUnit XML report.
OutputFile : string
/// Redirects output created by the tests from standard output (console) to the file specified as value.
Out : string
/// Redirects error output created by the tests from standard error output (console) to the file specified as value.
ErrorOutputFile : string
/// Allows you to specify the version of the runtime to be used in executing tests.
Framework : string
/// Controls how NUnit loads tests in processes. See: [NUnitProcessModel](fake-nunitcommon-nunitprocessmodel.html).
ProcessModel : NUnitProcessModel
/// Causes an identifying label to be displayed at the start of each test case.
ShowLabels : bool
/// The working directory.
WorkingDir : string
/// The path to a custom XSLT transform file to be used to process the XML report.
XsltTransformFile : string
/// The default timeout to be used for test cases. If any test exceeds the timeout value, it is cancelled and reported as an error.
TimeOut : TimeSpan
/// Disables shadow copying of the assembly in order to provide improved performance.
DisableShadowCopy : bool
/// See [NUnitDomainModel](fake-nunitcommon-nunitdomainmodel.html).
Domain : NUnitDomainModel
/// Default: [TestRunnerErrorLevel](fake-unittestcommon-testrunnererrorlevel.html).Error
ErrorLevel : NUnitErrorLevel
/// Default: ""
Fixture: string}
/// The [NUnitParams](fake-nunitcommon-nunitparams.html) default parameters.
///
/// ## Defaults
/// - `IncludeCategory` - `""`
/// - `ExcludeCategory` - `""`
/// - `ToolPath` - The `nunit-console.exe` path if it exists in a subdirectory of the current directory.
/// - `ToolName` - `"nunit-console.exe"`
/// - `DontTestInNewThread`- `false`
/// - `StopOnError` - `false`
/// - `SkipNonTestAssemblies` - `false`
/// - `OutputFile` - `"TestResult.xml"`
/// - `Out` - `""`
/// - `ErrorOutputFile` - `""`
/// - `WorkingDir` - `""`
/// - `Framework` - `""`
/// - `ProcessModel` - `DefaultProcessModel`
/// - `ShowLabels` - `true`
/// - `XsltTransformFile` - `""`
/// - `TimeOut` - 5 minutes
/// - `DisableShadowCopy` - `false`
/// - `Domain` - `DefaultDomainModel`
/// - `ErrorLevel` - `Error`
/// - `Fixture` - `""`
[<System.Obsolete("use Fake.DotNet.Testing.NUnit instead")>]
let NUnitDefaults =
let toolname = "nunit-console.exe"
{ IncludeCategory = ""
ExcludeCategory = ""
ToolPath = findToolFolderInSubPath toolname (currentDirectory @@ "tools" @@ "Nunit")
ToolName = toolname
DontTestInNewThread = false
StopOnError = false
SkipNonTestAssemblies = false
OutputFile = currentDirectory @@ "TestResult.xml"
Out = ""
ErrorOutputFile = ""
WorkingDir = ""
Framework = ""
ProcessModel = DefaultProcessModel
ShowLabels = true
XsltTransformFile = ""
TimeOut = TimeSpan.FromMinutes 5.0
DisableShadowCopy = false
Domain = DefaultDomainModel
ErrorLevel = Error
Fixture = ""}
/// Builds the command line arguments from the given parameter record and the given assemblies.
/// [omit]
[<System.Obsolete("use Fake.DotNet.Testing.NUnit instead")>]
let buildNUnitdArgs parameters assemblies =
new StringBuilder()
|> append "-nologo"
|> appendIfTrue parameters.DisableShadowCopy "-noshadow"
|> appendIfTrue parameters.ShowLabels "-labels"
|> appendIfTrue parameters.DontTestInNewThread "-nothread"
|> appendIfTrue parameters.StopOnError "-stoponerror"
|> appendIfTrue parameters.SkipNonTestAssemblies "-skipnontestassemblies"
|> appendFileNamesIfNotNull assemblies
|> appendIfNotNullOrEmpty parameters.IncludeCategory "-include:"
|> appendIfNotNullOrEmpty parameters.ExcludeCategory "-exclude:"
|> appendIfNotNullOrEmpty parameters.XsltTransformFile "-transform:"
|> appendIfNotNullOrEmpty parameters.OutputFile "-xml:"
|> appendIfNotNullOrEmpty parameters.Out "-out:"
|> appendIfNotNullOrEmpty parameters.Framework "-framework:"
|> appendIfNotNullOrEmpty parameters.ProcessModel.ParamString "-process:"
|> appendIfNotNullOrEmpty parameters.ErrorOutputFile "-err:"
|> appendIfNotNullOrEmpty parameters.Domain.ParamString "-domain:"
|> appendIfNotNullOrEmpty parameters.Fixture "-fixture:"
|> toText
/// Tries to detect the working directory as specified in the parameters or via TeamCity settings
/// [omit]
[<System.Obsolete("use Fake.DotNet.Testing.NUnit instead")>]
let getWorkingDir parameters =
Seq.find isNotNullOrEmpty [ parameters.WorkingDir
environVar ("teamcity.build.workingDir")
"." ]
|> Path.GetFullPath
/// NUnit console returns negative error codes for errors and sum of failed, ignored and exceptional tests otherwise.
/// Zero means that all tests passed.
[<System.Obsolete("use Fake.DotNet.Testing.NUnit instead")>]
let (|OK|TestsFailed|FatalError|) errorCode =
match errorCode with
| 0 -> OK
| -1 -> FatalError "InvalidArg"
| -2 -> FatalError "FileNotFound"
| -3 -> FatalError "FixtureNotFound"
| -100 -> FatalError "UnexpectedError"
| x when x < 0 -> FatalError "FatalError"
| _ -> TestsFailed