Skip to content

Commit

Permalink
Localization, the easy bits, and the Gendarme suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Jan 30, 2018
1 parent 2b90aad commit 8866896
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
3 changes: 1 addition & 2 deletions AltCover.Recorder/Base.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ module Counter =
let DoFlush own counts report =
use coverageFile = new FileStream(report, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.SequentialScan)
let flushStart = UpdateReport own counts coverageFile
let delta = TimeSpan(DateTime.UtcNow.Ticks - flushStart.Ticks)
Console.Out.WriteLine("Coverage statistics flushing took {0:N} seconds", delta.TotalSeconds)
TimeSpan(DateTime.UtcNow.Ticks - flushStart.Ticks)

let AddVisit (counts:Dictionary<string, Dictionary<int, int>>) moduleId hitPointId =
if not (counts.ContainsKey moduleId) then counts.[moduleId] <- Dictionary<int, int>()
Expand Down
3 changes: 2 additions & 1 deletion AltCover.Recorder/Recorder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ module Instance =
| _ -> let counts = Dictionary<string, Dictionary<int, int>> Visits
Visits.Clear()
WithMutex (fun own ->
Counter.DoFlush own counts ReportFile
let delta = Counter.DoFlush own counts ReportFile
Console.Out.WriteLine("Coverage statistics flushing took {0:N} seconds", delta.TotalSeconds)
))

let internal TraceVisit moduleId hitPointId =
Expand Down
15 changes: 11 additions & 4 deletions AltCover/Runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,21 @@ module Runner =
CommandLine.doPathOperation (fun () ->
CommandLine.ProcessTrailingArguments rest (DirectoryInfo(Option.get workingDirectory)))

let WriteResource =
CommandLine.resources.GetString >> Console.WriteLine

let WriteResourceWithFormatItems s x =
Console.WriteLine (s |> CommandLine.resources.GetString, x)

let MonitorBase (hits:ICollection<(string*int)>) report (payload: string list -> unit) (args : string list) =
let binpath = report + ".bin"
do
use stream = File.Create(binpath)
()

printfn "Beginning run..."
"Beginning run..." |> WriteResource
payload args
printfn "Getting results..."
"Getting results..." |> WriteResource

use results = File.OpenRead(binpath)
let formatter = System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Expand All @@ -125,7 +131,7 @@ module Runner =
| :? System.Runtime.Serialization.SerializationException as x ->
()
sink()
printfn "%d visits recorded" hits.Count
WriteResourceWithFormatItems "%d visits recorded" [|hits.Count|]

let WriteReportBase (hits:ICollection<(string*int)>) report =
let counts = Dictionary<string, Dictionary<int, int>>()
Expand Down Expand Up @@ -154,4 +160,5 @@ module Runner =

let payload = GetPayload
GetMonitor hits report payload rest
DoReport hits report
let delta = DoReport hits report
WriteResourceWithFormatItems "Coverage statistics flushing took {0:N} seconds" [|delta.TotalSeconds|]
12 changes: 12 additions & 0 deletions AltCover/Strings.eo.resx
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,16 @@ AltCover Runner [/r[ecordingDirectory]=VALO] [/w[orkingDirectory]=VALO] [/x||exe
<data name="w|workingDirectory=" xml:space="preserve">
<value>Laŭvola: La laboranta dosierujo por la lanĉo de aplikaĵoj</value>
</data>
<data name="%d visits recorded" xml:space="preserve">
<value>{0} vizitoj registritaj</value>
</data>
<data name="Beginning run..." xml:space="preserve">
<value>Komencanta kuri ...</value>
</data>
<data name="Coverage statistics flushing took {0:N} seconds" xml:space="preserve">
<value>Kovraj statistika skribado prenis {0:N} sekundojn</value>
</data>
<data name="Getting results..." xml:space="preserve">
<value>Akiri rezultojn ...</value>
</data>
</root>
12 changes: 12 additions & 0 deletions AltCover/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,16 @@ AltCover Runner [/r[ecordingDirectory]=VALUE] [/w[orkingDirectory]=VALUE] [/x||e
<data name="w|workingDirectory=" xml:space="preserve">
<value>Optional: The working directory for the application launch</value>
</data>
<data name="%d visits recorded" xml:space="preserve">
<value>{0} visits recorded</value>
</data>
<data name="Beginning run..." xml:space="preserve">
<value>Beginning run...</value>
</data>
<data name="Coverage statistics flushing took {0:N} seconds" xml:space="preserve">
<value>Coverage statistics flushing took {0:N} seconds</value>
</data>
<data name="Getting results..." xml:space="preserve">
<value>Getting results...</value>
</data>
</root>
15 changes: 3 additions & 12 deletions Tests/Runner.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,8 @@ type AltCoverTests() = class
|> Seq.iter(fun i -> payload.[i] <- (i+1))
visits.["f6e3edb3-fb20-44b3-817d-f69d1a22fc2f"] <- payload

Counter.DoFlush true visits reportFile
Counter.DoFlush true visits reportFile |> ignore

let head = "Coverage statistics flushing took "
let tail = " seconds\n"
let recorded = stdout.ToString().Replace("\r\n","\n")
Assert.That (recorded.StartsWith(head, StringComparison.Ordinal))
Assert.That (recorded.EndsWith(tail, StringComparison.Ordinal))
use worker' = new FileStream(reportFile, FileMode.Open)
let after = XmlDocument()
after.Load worker'
Expand Down Expand Up @@ -715,6 +710,7 @@ type AltCoverTests() = class
let write (hits:ICollection<(string*int)>) (report:string) =
Assert.That(report, Is.EqualTo "Coverage.Default.xml", "should be default coverage file")
Assert.That(hits, Is.Empty)
TimeSpan.Zero

Runner.GetPayload <- payload
Runner.GetMonitor <- monitor
Expand Down Expand Up @@ -765,13 +761,8 @@ type AltCoverTests() = class
|> Seq.iter(fun i -> payload.[i] <- (i+1))
visits.["f6e3edb3-fb20-44b3-817d-f69d1a22fc2f"] <- payload

Runner.DoReport hits reportFile
Runner.DoReport hits reportFile |> ignore

let head = "Coverage statistics flushing took "
let tail = " seconds\n"
let recorded = stdout.ToString().Replace("\r\n","\n")
Assert.That (recorded.StartsWith(head, StringComparison.Ordinal))
Assert.That (recorded.EndsWith(tail, StringComparison.Ordinal))
use worker' = new FileStream(reportFile, FileMode.Open)
let after = XmlDocument()
after.Load worker'
Expand Down

0 comments on commit 8866896

Please sign in to comment.