-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* NEW: Add `Fake.DotNet.Testing.Coverlet`, thanks @Tarmil - #2413 * BUGFIX: `paket pack` module was broken, thanks @sergey-tihon - #2418
- Loading branch information
Showing
13 changed files
with
327 additions
and
1 deletion.
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
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,77 @@ | ||
# Analyze your code coverage with Coverlet | ||
|
||
From the [project](https://github.com/tonerdo/coverlet): | ||
> Coverlet is a cross platform code coverage framework for .NET, with support for line, branch and method coverage. It works with .NET Framework on Windows and .NET Core on all supported platforms. | ||
[API-Reference](apidocs/v5/fake-dotnet-testing-coverlet.html) | ||
|
||
## Minimal working example | ||
|
||
To work with Coverlet, you must first: | ||
|
||
* Add the NuGet reference `coverlet.msbuild` to your test projects (and only your test projects!). | ||
* Ensure that these test projects are marked as such with a property `<IsTestProject>true</IsTestProject>`. | ||
|
||
Then, Coverlet will run as part of `dotnet test` using `Coverlet.withDotNetTestOptions`: | ||
|
||
```fsharp | ||
#r "paket: | ||
nuget Fake.DotNet.Testing.Coverlet //" | ||
open Fake.DotNet | ||
open Fake.DotNet.Testing | ||
DotNet.test (fun p -> | ||
{ p with | ||
// Your dotnet test configuration here... | ||
Configuration = DotNet.BuildConfiguration.Release | ||
} | ||
|> Coverlet.withDotNetTestOptions (fun p -> | ||
{ p with | ||
Output = "coverage.json" | ||
})) | ||
"tests/MyProject.fsproj" | ||
``` | ||
|
||
## Full example | ||
|
||
```fsharp | ||
#r "paket: | ||
nuget Fake.DotNet.Testing.Coverlet //" | ||
open Fake.DotNet | ||
open Fake.DotNet.Testing | ||
DotNet.test (fun p -> | ||
{ p with | ||
// Your dotnet test configuration here... | ||
Configuration = DotNet.BuildConfiguration.Release | ||
} | ||
|> Coverlet.withDotNetTestOptions (fun p -> | ||
{ p with | ||
OutputFormat = Coverlet.OutputFormat.OpenCover | ||
Output = "coverage.xml" | ||
Include = [ | ||
// Include all namespaces from assemblies whose name starts with MyProject | ||
"MyProject.*", "*" | ||
] | ||
Exclude = [ | ||
// Exclude all namespaces from assemblies whose name ends with .Test or .Tests | ||
"*.Tests?", "*" | ||
// Exclude all namespaces starting with System., even in included assemblies | ||
"*", "System.*" | ||
] | ||
// Exclude assemblies, types and methods marked with these attributes | ||
ExcludeByAttribute = ["MyCustomIgnoreCoverageAttribute"] | ||
// Exclude all code from these files | ||
ExcludeByFile = ["AssemblyInfo.fs"; "Program.fs"] | ||
// Merge results with results from another coverage session | ||
// (which must have OutputFormat = Json) | ||
MergeWith = Some "other-coverage.json" | ||
// Fail if total line coverage is below 80% | ||
Threshold = Some 80 | ||
TresholdType = Coverlet.ThresholdType.Line | ||
ThresholdStat = Coverlet.ThresholdState.Total | ||
// Generate links to SourceLink URLs rather than local paths | ||
UseSourceLink = true | ||
})) | ||
"tests/MyProject.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
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,19 @@ | ||
// Auto-Generated by FAKE; do not edit | ||
namespace System | ||
open System.Reflection | ||
|
||
[<assembly: AssemblyTitleAttribute("FAKE - F# Make Code coverage with Coverlet")>] | ||
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>] | ||
[<assembly: AssemblyVersionAttribute("5.18.0")>] | ||
[<assembly: AssemblyInformationalVersionAttribute("5.18.0")>] | ||
[<assembly: AssemblyFileVersionAttribute("5.18.0")>] | ||
[<assembly: AssemblyMetadataAttribute("BuildDate","2019-10-21")>] | ||
do () | ||
|
||
module internal AssemblyVersionInformation = | ||
let [<Literal>] AssemblyTitle = "FAKE - F# Make Code coverage with Coverlet" | ||
let [<Literal>] AssemblyProduct = "FAKE - F# Make" | ||
let [<Literal>] AssemblyVersion = "5.18.0" | ||
let [<Literal>] AssemblyInformationalVersion = "5.18.0" | ||
let [<Literal>] AssemblyFileVersion = "5.18.0" | ||
let [<Literal>] AssemblyMetadata_BuildDate = "2019-10-21" |
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,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 } |
22 changes: 22 additions & 0 deletions
22
src/app/Fake.DotNet.Testing.Coverlet/Fake.DotNet.Testing.Coverlet.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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks> | ||
<DefineConstants>$(DefineConstants);NO_DOTNETCORE_BOOTSTRAP</DefineConstants> | ||
<AssemblyName>Fake.DotNet.Testing.Coverlet</AssemblyName> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DefineConstants>$(DefineConstants);NETSTANDARD;USE_HTTPCLIENT</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyInfo.fs" /> | ||
<Compile Include="Coverlet.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Fake.DotNet.Cli\Fake.DotNet.Cli.fsproj" /> | ||
</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,4 @@ | ||
group netcore | ||
|
||
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
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.