-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1887 from magicmonty/reportgenerator
Ported ReportGeneratorHelper to FAKE 5
- Loading branch information
Showing
9 changed files
with
224 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Fake.Testing.ReportGenerator | ||
|
||
ReportGenerator converts XML reports generated by OpenCover, PartCover, dotCover, Visual Studio, NCover or Cobertura into human readable reports in various formats. | ||
|
||
he reports do not only show the coverage quota, but also include the source code and visualize which lines have been covered. | ||
|
||
ReportGenerator supports merging several reports into one. It is also possible to pass one XML file containing several reports to ReportGenerator (e.g. a build log file). | ||
|
||
See https://github.com/danielpalme/ReportGenerator | ||
|
||
## Minimal working example | ||
|
||
```fsharp | ||
"#r "paket: | ||
nuget Fake.Core.Target | ||
nuget Fake.Testing.ReportGenerator" | ||
open Fake.Core | ||
open Fake.Core.TargetOperators | ||
open Fake.Testing | ||
... | ||
Target.create "Generate Reports" (fun _ -> | ||
let parameters p = { p with TargetDir = "c:/reports/" } | ||
!! "**/opencover.xml" | ||
|> ReportGenerator.generateReports parameters | ||
) | ||
Target.create "Default" DoNothing | ||
"Clean" | ||
==> "SetAssemblyInfo" | ||
==> "Build" | ||
==> "RunCoverage" | ||
==> "Generate Reports" | ||
==> "Default" | ||
Target.runOrDefault "Default" | ||
``` |
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,17 @@ | ||
// Auto-Generated by FAKE; do not edit | ||
namespace System | ||
open System.Reflection | ||
|
||
[<assembly: AssemblyTitleAttribute("FAKE - F# Make Convert XML coverage output to various formats")>] | ||
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>] | ||
[<assembly: AssemblyVersionAttribute("5.0.0")>] | ||
[<assembly: AssemblyInformationalVersionAttribute("5.0.0-beta025")>] | ||
[<assembly: AssemblyFileVersionAttribute("5.0.0")>] | ||
do () | ||
|
||
module internal AssemblyVersionInformation = | ||
let [<Literal>] AssemblyTitle = "FAKE - F# Make Convert XML coverage output to various formats" | ||
let [<Literal>] AssemblyProduct = "FAKE - F# Make" | ||
let [<Literal>] AssemblyVersion = "5.0.0" | ||
let [<Literal>] AssemblyInformationalVersion = "5.0.0-beta025" | ||
let [<Literal>] AssemblyFileVersion = "5.0.0" |
24 changes: 24 additions & 0 deletions
24
src/app/Fake.Testing.ReportGenerator/Fake.Testing.ReportGenerator.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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks> | ||
<DefineConstants>$(DefineConstants);NO_DOTNETCORE_BOOTSTRAP</DefineConstants> | ||
<AssemblyName>Fake.Testing.ReportGenerator</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="ReportGenerator.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Fake.Core.Trace\Fake.Core.Trace.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" /> | ||
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" /> | ||
</ItemGroup> | ||
<Import Project="..\..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
115 changes: 115 additions & 0 deletions
115
src/app/Fake.Testing.ReportGenerator/ReportGenerator.fs
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,115 @@ | ||
/// Contains a task which can be used to run [ReportGenerator](https://github.com/danielpalme/ReportGenerator), | ||
/// which converts XML reports generated by PartCover, OpenCover or NCover into a readable report in various formats. | ||
/// | ||
/// ## Sample | ||
/// | ||
/// ``` | ||
/// open Fake.Testing | ||
/// | ||
/// Target.create "Generate Reports" (fun _ -> | ||
/// let parameters p = { p with TargetDir = "c:/reports/" } | ||
/// !! "**/opencover.xml" | ||
/// |> ReportGenerator.generateReports parameters | ||
/// ) | ||
/// ``` | ||
[<RequireQualifiedAccess>] | ||
module Fake.Testing.ReportGenerator | ||
|
||
open System | ||
open System.Text | ||
open System.IO | ||
|
||
open Fake.Core | ||
open Fake.IO | ||
|
||
type ReportType = | ||
| Html = 0 | ||
| HtmlSummary = 1 | ||
| Xml = 2 | ||
| XmlSummary = 3 | ||
| Latex = 4 | ||
| LatexSummary = 5 | ||
| Badges = 6 | ||
|
||
type LogVerbosity = | ||
| Verbose = 0 | ||
| Info = 1 | ||
| Error = 2 | ||
|
||
/// ReportGenerator parameters, for more details see: https://github.com/danielpalme/ReportGenerator. | ||
type ReportGeneratorParams = | ||
{ /// (Required) Path to the ReportGenerator exe file. | ||
ExePath : string | ||
/// (Required) The directory where the generated report should be saved. | ||
TargetDir : string | ||
/// The output formats and scope. | ||
ReportTypes : ReportType list | ||
/// Optional directories which contain the corresponding source code. | ||
SourceDirs : string list | ||
/// Optional directory for storing persistent coverage information. | ||
/// Can be used in future reports to show coverage evolution. | ||
HistoryDir : string | ||
/// Optional list of assemblies that should be included or excluded | ||
/// in the report. Exclusion filters take precedence over inclusion | ||
/// filters. Wildcards are allowed. | ||
Filters : string list | ||
/// The verbosity level of the log messages. | ||
LogVerbosity : LogVerbosity | ||
/// The directory where the ReportGenerator process will be started. | ||
WorkingDir : string | ||
/// The timeout for the ReportGenerator process. | ||
TimeOut : TimeSpan } | ||
|
||
let private currentDirectory = Directory.GetCurrentDirectory () | ||
|
||
/// ReportGenerator default parameters | ||
let private ReportGeneratorDefaultParams = | ||
{ ExePath = "./tools/ReportGenerator/bin/ReportGenerator.exe" | ||
TargetDir = currentDirectory | ||
ReportTypes = [ ReportType.Html ] | ||
SourceDirs = [] | ||
HistoryDir = String.Empty | ||
Filters = [] | ||
LogVerbosity = LogVerbosity.Verbose | ||
WorkingDir = currentDirectory | ||
TimeOut = TimeSpan.FromMinutes 5. } | ||
|
||
/// Builds the report generator command line arguments from the given parameters and reports | ||
/// [omit] | ||
let private buildReportGeneratorArgs parameters (reports : string seq) = | ||
let reportTypes = parameters.ReportTypes |> List.map (fun rt -> rt.ToString()) | ||
let sourceDirs = sprintf "-sourcedirs:%s" (String.Join(";", parameters.SourceDirs)) | ||
let filters = sprintf "-filters:%s" (String.Join(";", parameters.Filters)) | ||
|
||
new StringBuilder() | ||
|> StringBuilder.append (sprintf "-reports:%s" (String.Join(";", reports))) | ||
|> StringBuilder.append (sprintf "-targetdir:%s" parameters.TargetDir) | ||
|> StringBuilder.appendWithoutQuotes (sprintf "-reporttypes:%s" (String.Join(";", reportTypes))) | ||
|> StringBuilder.appendIfTrue (parameters.SourceDirs.Length > 0) sourceDirs | ||
|> StringBuilder.appendStringIfValueIsNotNullOrEmpty (parameters.HistoryDir) (sprintf "-historydir:%s" parameters.HistoryDir) | ||
|> StringBuilder.appendIfTrue (parameters.Filters.Length > 0) filters | ||
|> StringBuilder.appendWithoutQuotes (sprintf "-verbosity:%s" (parameters.LogVerbosity.ToString())) | ||
|> StringBuilder.toText | ||
|
||
/// Runs ReportGenerator on one or more coverage reports. | ||
/// ## Parameters | ||
/// | ||
/// - `setParams` - Function used to overwrite the default ReportGenerator parameters. | ||
/// - `reports` - Coverage reports. | ||
let generateReports setParams (reports : string list) = | ||
let taskName = "ReportGenerator" | ||
let description = "Generating reports" | ||
|
||
use __ = Trace.traceTask taskName description | ||
let param = setParams ReportGeneratorDefaultParams | ||
|
||
let processArgs = buildReportGeneratorArgs param reports | ||
Trace.tracefn "ReportGenerator command\n%s %s" param.ExePath processArgs | ||
|
||
let processStartInfo info = | ||
{ info with FileName = param.ExePath | ||
WorkingDirectory = if param.WorkingDir |> String.isNullOrEmpty then info.WorkingDirectory else param.WorkingDir | ||
Arguments = processArgs } | ||
match Process.execSimple processStartInfo param.TimeOut with | ||
| 0 -> () | ||
| v -> failwithf "ReportGenerator reported errors: %i" v |
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