Skip to content

Commit

Permalink
Only pay for what we use -- efficiency in the case when we are doing …
Browse files Browse the repository at this point in the history
…opencover + runner w/o tracking
  • Loading branch information
SteveGilham committed Mar 20, 2018
1 parent af216b0 commit 1704e95
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion AltCover.Recorder/Base.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open System.Globalization
open System.IO
open System.Xml

type ReportFormat = NCover = 0 | OpenCover = 1
type ReportFormat = NCover = 0 | OpenCover = 1 | OpenCoverWithTracking = 2

[<System.Runtime.InteropServices.ProgIdAttribute("ExcludeFromCodeCoverage hack for OpenCover issue 615")>]
type internal Track =
Expand Down Expand Up @@ -86,6 +86,7 @@ module Counter =
System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion)

let (m, i, m', s, v) = match format with
| ReportFormat.OpenCoverWithTracking
| ReportFormat.OpenCover -> ("//Module", "hash", "Classes/Class/Methods/Method", "SequencePoints/SequencePoint", "vc")
| _ -> ("//module", "moduleId", "method", "seqpnt", "visitcount")
coverageDocument.SelectNodes(m)
Expand All @@ -106,6 +107,7 @@ module Counter =
|> Seq.cast<XmlElement>
|> Seq.toList |> List.rev)
|> Seq.mapi (fun counter pt -> ((match format with
| ReportFormat.OpenCoverWithTracking
| ReportFormat.OpenCover -> "uspid" |> pt.GetAttribute |> FindIndexFromUspid
| _ -> counter),
pt))
Expand Down
2 changes: 1 addition & 1 deletion AltCover.Recorder/Recorder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ module Instance =
mailbox.CurrentQueueLength

let private IsOpenCoverRunner() =
(CoverageFormat = ReportFormat.OpenCover) &&
(CoverageFormat = ReportFormat.OpenCoverWithTracking) &&
((trace.Definitive && trace.Runner) ||
(ReportFile <> "Coverage.Default.xml" && System.IO.File.Exists (ReportFile + ".acv")))

Expand Down
1 change: 1 addition & 0 deletions AltCover/AltCover.fs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ module Main =
(CommandLine.resources.GetString "reportingto"),
Visitor.ReportPath())
let reporter, document = match Visitor.ReportFormat() with
| ReportFormat.OpenCoverWithTracking
| ReportFormat.OpenCover -> OpenCover.ReportGenerator ()
| _ -> Report.ReportGenerator ()
let visitors = [ reporter ; Instrument.InstrumentGenerator assemblyNames ]
Expand Down
1 change: 1 addition & 0 deletions AltCover/Instrument.fs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ module Instrument =
RecordingMethod = recordingMethod }
| _ -> state
{ restate with ModuleId = match Visitor.ReportFormat() with
| AltCover.Base.ReportFormat.OpenCoverWithTracking
| AltCover.Base.ReportFormat.OpenCover -> KeyStore.HashFile m.FileName
| _ -> m.Mvid.ToString() }

Expand Down
1 change: 1 addition & 0 deletions AltCover/Runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ module Runner =

let internal PostProcess (counts:Dictionary<string, Dictionary<int, int * Base.Track list>>) format (document:XmlDocument) =
match format with
| Base.ReportFormat.OpenCoverWithTracking
| Base.ReportFormat.OpenCover ->
let updateMethod (dict:Dictionary<int, int * Base.Track list>) (vs, vm, pt) (``method``:XmlElement) =
let sp = ``method``.GetElementsByTagName("SequencePoint")
Expand Down
12 changes: 8 additions & 4 deletions AltCover/Visitor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ module Visitor =
let defaultReportPath = "coverage.xml"
let ReportPath () = Path.GetFullPath (Option.getOrElse defaultReportPath reportPath)

let mutable internal reportFormat : Option<ReportFormat> = None
let defaultReportFormat = ReportFormat.NCover
let ReportFormat () = (Option.getOrElse defaultReportFormat reportFormat)

let mutable internal interval : Option<int> = None
let defaultInterval = 0
let Interval () = (Option.getOrElse defaultInterval interval)

let mutable internal reportFormat : Option<ReportFormat> = None
let defaultReportFormat = ReportFormat.NCover
let ReportFormat () = let fmt = (Option.getOrElse defaultReportFormat reportFormat)
if fmt = ReportFormat.OpenCover &&
(TrackingNames.Any() || Interval() > 0) then
ReportFormat.OpenCoverWithTracking
else fmt

let mutable internal defaultStrongNameKey : option<StrongNameKeyPair> = None
let internal keys = new Dictionary<UInt64, KeyRecord>()

Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ type AltCoverTests() = class
let report = proxyObject.InvokeMethod("get_ReportFile",[||]).ToString()
Assert.That (report, Is.EqualTo (Path.GetFullPath unique))
let report2 = proxyObject.InvokeMethod("get_CoverageFormat",[||]) :?> System.Int32
Assert.That (report2, AltCover.Base.ReportFormat.OpenCover |> int |> Is.EqualTo)
Assert.That (report2, AltCover.Base.ReportFormat.OpenCoverWithTracking |> int |> Is.EqualTo)
let report3 = proxyObject.InvokeMethod("get_Timer",[||]) :?> System.Int64
Assert.That (report3, 1234567890L |> Is.EqualTo)
finally
Expand Down

0 comments on commit 1704e95

Please sign in to comment.