-
Notifications
You must be signed in to change notification settings - Fork 588
/
Copy pathCoverlet.fs
119 lines (107 loc) · 4.52 KB
/
Coverlet.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
/// Contains options to run [Coverlet](https://github.com/tonerdo/coverlet) as part of dotnet test.
[<RequireQualifiedAccess>]
module Fake.DotNet.Testing.Coverlet
open Fake.DotNet
/// The coverage report file format.
type OutputFormat =
| Json
| Lcov
| OpenCover
| Cobertura
| TeamCity
/// The type of coverage to use when failing under a threshold.
type ThresholdType =
| Line
| Branch
| Method
/// The statistic to use when failing under a threshold.
type ThresholdStat =
| Minimum
| Total
| Average
/// Coverlet MSBuild parameters. For more details see: https://github.com/tonerdo/coverlet/blob/master/Documentation/MSBuildIntegration.md
type CoverletParams =
{ /// (Required) Format of the generated output.
OutputFormat : OutputFormat
/// (Required) Path to the generated output file, or directory if it ends with a `/`.
Output : string
/// Namespaces to include, as (AssemblyName, Namespace) pairs. Supports `*` and `?` globbing.
Include : (string * string) list
/// Namespaces to exclude, as (AssemblyName, Namespace) pairs. Supports `*` and `?` globbing.
Exclude : (string * string) list
/// Exclude methods, types and assemblies annotated with these attributes.
ExcludeByAttribute : string list
/// Exclude these source files. Supports path globbing.
ExcludeByFile : string list
/// Coverlet json file to merge with the output of this run.
MergeWith : string option
/// Minimum coverage percent. Build fails if the result is below.
Threshold : int option
/// Type of coverage to check against the threshold.
ThresholdType : ThresholdType
/// Coverage statistic to check against the threshold.
ThresholdStat : ThresholdStat
/// Generate results with URL links from SourceLink instead of file paths.
UseSourceLink : bool }
/// The default parameters.
let private defaults =
{ OutputFormat = OutputFormat.Json
Output = "./"
Include = []
Exclude = []
ExcludeByAttribute = []
ExcludeByFile = []
MergeWith = None
Threshold = None
ThresholdType = ThresholdType.Line
ThresholdStat = ThresholdStat.Minimum
UseSourceLink = false }
let private outputFormatToString = function
| OutputFormat.Json -> "json"
| OutputFormat.Lcov -> "lcov"
| OutputFormat.OpenCover -> "opencover"
| OutputFormat.Cobertura -> "cobertura"
| OutputFormat.TeamCity -> "teamcity"
let private namespacesToString =
Seq.map (fun (asm, ns) -> "[" + asm + "]" + ns)
>> String.concat ","
let private thresholdTypeToString = function
| ThresholdType.Line -> "line"
| ThresholdType.Branch -> "branch"
| ThresholdType.Method -> "method"
let private thresholdStatToString = function
| ThresholdStat.Minimum -> "minimum"
| ThresholdStat.Total -> "total"
| ThresholdStat.Average -> "average"
/// Add Coverlet parameters to the MSBuild command.
let withMSBuildArguments (param: CoverletParams -> CoverletParams) (args: MSBuild.CliArguments) =
let param = param defaults
let properties =
[
"CollectCoverage", "true"
"OutputFormat", outputFormatToString param.OutputFormat
"CoverletOutput", param.Output
if not (List.isEmpty param.Include) then
"Include", namespacesToString param.Include
if not (List.isEmpty param.Exclude) then
"Exclude", namespacesToString param.Exclude
if not (List.isEmpty param.ExcludeByAttribute) then
"ExcludeByAttribute", String.concat "," param.ExcludeByAttribute
if not (List.isEmpty param.ExcludeByFile) then
"ExcludeByFile", String.concat "," param.ExcludeByFile
match param.MergeWith with
| Some f -> "MergeWith", f
| None -> ()
match param.Threshold with
| Some t ->
"Threshold", string t
"ThresholdType", thresholdTypeToString param.ThresholdType
"ThresholdStat", thresholdStatToString param.ThresholdStat
| None -> ()
if param.UseSourceLink then
"UseSourceLink", "true"
]
{ args with Properties = args.Properties @ properties }
/// Add Coverlet parameters to the dotnet test command.
let withDotNetTestOptions (param: CoverletParams -> CoverletParams) (options: DotNet.TestOptions) =
{ options with MSBuildParams = withMSBuildArguments param options.MSBuildParams }