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

Support for ReportGenerator #399

Merged
merged 1 commit into from
Apr 22, 2014
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
1 change: 1 addition & 0 deletions src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<Compile Include="AppVeyor.fs" />
<Compile Include="TypeScript.fs" />
<Compile Include="OpenCoverHelper.fs" />
<Compile Include="ReportGeneratorHelper.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Expand Down
95 changes: 95 additions & 0 deletions src/app/FakeLib/ReportGeneratorHelper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/// Contains a task which can be used to run [ReportGenerator](https://reportgenerator.codeplex.com),
/// which converts XML reports generated by PartCover, OpenCover or NCover into a readable report in various formats.
module Fake.ReportGeneratorHelper

open System
open System.Text

type ReportGeneratorReportType =
| Html = 0
| HtmlSummary = 1
| Xml = 2
| XmlSummary = 3
| Latex = 4
| LatexSummary = 5

type ReportGeneratorLogVerbosity =
| Verbose = 0
| Info = 1
| Error = 2

/// ReportGenerator parameters, for more details see: https://reportgenerator.codeplex.com.
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 : ReportGeneratorReportType list
/// Optional directories which contain the corresponding source code.
SourceDirs : string list
/// 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 : ReportGeneratorLogVerbosity
/// The directory where the ReportGenerator process will be started.
WorkingDir : string
/// The timeout for the ReportGenerator process.
TimeOut : TimeSpan }

/// ReportGenerator default parameters
let ReportGeneratorDefaultParams =
{ ExePath = "./tools/ReportGenerator/bin/ReportGenerator.exe"
TargetDir = currentDirectory
ReportTypes = [ ReportGeneratorReportType.Html ]
SourceDirs = []
Filters = []
LogVerbosity = ReportGeneratorLogVerbosity.Verbose
WorkingDir = currentDirectory
TimeOut = TimeSpan.FromMinutes 5. }

/// Runs ReportGenerator on one or more coverage reports.
/// ## Parameters
///
/// - `setParams` - Function used to overwrite the default ReportGenerator parameters.
/// - `reports` - Coverage reports.
///
/// ## Sample
///
/// ReportGenerator (fun p -> { p with TargetDir = "c:/reports/" }) [ "c:/opencover.xml" ]
let ReportGenerator setParams (reports : string list) =
let taskName = "ReportGenerator"
let description = "Generating reports"
traceStartTask taskName description
let param = setParams ReportGeneratorDefaultParams

let processArgs =
let args = ref (new StringBuilder())
let append (s : string) = args := (!args).Append(s)
append "\"-reports:"
append (String.Join(";", reports))
append "\" \"-targetdir:"
append param.TargetDir
append "\" -reporttypes:"
append (String.Join(";", param.ReportTypes |> List.map (fun rt -> rt.ToString())))
if param.SourceDirs.Length > 0 then
append " \"-sourcedirs:"
append (String.Join(";", param.SourceDirs))
append "\""
if param.Filters.Length > 0 then
append " \"-filters:"
append (String.Join(";", param.Filters))
append "\""
append " -verbosity:"
append (param.LogVerbosity.ToString())
(!args).ToString()
tracefn "ReportGenerator command\n%s %s" param.ExePath processArgs
let ok =
execProcess (fun info ->
info.FileName <- param.ExePath
if param.WorkingDir <> String.Empty then info.WorkingDirectory <- param.WorkingDir
info.Arguments <- processArgs) param.TimeOut
if not ok then failwithf "ReportGenerator reported errors."
traceEndTask taskName description