Skip to content

Commit

Permalink
This looks like it completes the implementation and makes all the red…
Browse files Browse the repository at this point in the history
… tests green
  • Loading branch information
SteveGilham committed Aug 14, 2019
1 parent cc9cb4b commit f54030e
Show file tree
Hide file tree
Showing 10 changed files with 719 additions and 587 deletions.
4 changes: 3 additions & 1 deletion AltCover.FSApi/CoverageFormats.fs
Expand Up @@ -46,7 +46,9 @@ module CoverageFormats =
XmlUtilities.AssemblyNameWithFallback p (Path.GetFileNameWithoutExtension p)
paths.Add(p, a))
let usefulAssemblies =
assemblies |> Seq.filter (fun p -> identities.ContainsKey paths.[p])
assemblies
|> Seq.filter (fun p -> identities.ContainsKey paths.[p])
|> Seq.map (fun p -> (p,[]))

// ensure default state -- this switches branch recording off
AltCover.Main.init()
Expand Down
1,008 changes: 540 additions & 468 deletions AltCover/AltCover.fs

Large diffs are not rendered by default.

32 changes: 20 additions & 12 deletions AltCover/Instrument.fs
Expand Up @@ -619,12 +619,24 @@ module internal Instrument =
else branch.Start.Operand <- preamble
state

let WriteAssemblies definition file targets sink =
let first = Path.Combine (targets |> Seq.head, file)
String.Format
(System.Globalization.CultureInfo.CurrentCulture,
CommandLine.resources.GetString "instrumented", definition, first) |> sink
WriteAssembly definition first
targets
|> Seq.tail
|> Seq.iter (fun p -> let pathn = Path.Combine(p, file)
String.Format
(System.Globalization.CultureInfo.CurrentCulture,
CommandLine.resources.GetString "instrumented", definition, pathn) |> sink
File.Copy(first, pathn))

let private FinishVisit(state : InstrumentContext) =
try
let counterAssemblyFile =
Path.Combine
(Visitor.InstrumentDirectories() |> Seq.head, (extractName state.RecordingAssembly) + ".dll")
WriteAssembly (state.RecordingAssembly) counterAssemblyFile
let recorderFileName = (extractName state.RecordingAssembly) + ".dll"
WriteAssemblies (state.RecordingAssembly) recorderFileName (Visitor.InstrumentDirectories()) ignore
Directory.GetFiles
(Visitor.InstrumentDirectories() |> Seq.head, "*.deps.json", SearchOption.TopDirectoryOnly)
|> Seq.iter (fun f ->
Expand Down Expand Up @@ -703,13 +715,9 @@ module internal Instrument =
Track state m included track
state

let private VisitAfterAssembly state (assembly : AssemblyDefinition) =
let private VisitAfterAssembly state (assembly : AssemblyDefinition) (paths : string list) =
let originalFileName = Path.GetFileName assembly.MainModule.FileName
let path = Path.Combine(Visitor.InstrumentDirectories() |> Seq.head, originalFileName)
String.Format
(System.Globalization.CultureInfo.CurrentCulture,
CommandLine.resources.GetString "instrumented", assembly, path) |> Output.Info
WriteAssembly assembly path
WriteAssemblies assembly originalFileName paths Output.Info
state

let private VisitStart state =
Expand All @@ -726,7 +734,7 @@ module internal Instrument =
let internal InstrumentationVisitorCore (state : InstrumentContext) (node : Node) =
match node with
| Start _ -> VisitStart state
| Assembly(assembly, included) ->
| Assembly(assembly, included, _) ->
UpdateStrongReferences assembly state.InstrumentedAssemblies |> ignore
if included <> Inspect.Ignore then
assembly.MainModule.AssemblyReferences.Add(state.RecordingAssembly.Name)
Expand All @@ -740,7 +748,7 @@ module internal Instrument =
| AfterMethod(m, included, track) -> VisitAfterMethod state m included track
| AfterType -> state
| AfterModule -> state
| AfterAssembly assembly -> VisitAfterAssembly state assembly
| AfterAssembly (assembly, paths) -> VisitAfterAssembly state assembly paths
| Finish -> FinishVisit state

let internal InstrumentationVisitorWrapper (core : InstrumentContext -> Node -> InstrumentContext)
Expand Down
5 changes: 4 additions & 1 deletion AltCover/Strings.eo.resx
Expand Up @@ -165,7 +165,7 @@ AltCover version
Vidu https://github.com/SteveGilham/altcover/wiki/Usage por plenaj detaloj.</value>
</data>
<data name="NotInPlace" xml:space="preserve">
<value>De kaj al adresaroj estas identaj</value>
<value>De kaj al adresaroj {0} estas identaj</value>
</data>
<data name="UsageError" xml:space="preserve">
<value>Eraro - uzado estas:</value>
Expand Down Expand Up @@ -386,4 +386,7 @@ Se ĉi tiu problemo estis detektita en la antaŭprova instrumenta stadio de `dot
<data name="defer:" xml:space="preserve">
<value>Laŭvola, transdono de skriba kurant-reĝimaj priraportado ĝis elira procezo.</value>
</data>
<data name="DuplicatesNotAllowed" xml:space="preserve">
<value>{0} estis jam specifita por {1}</value>
</data>
</root>
5 changes: 4 additions & 1 deletion AltCover/Strings.resx
Expand Up @@ -166,7 +166,7 @@ See https://github.com/SteveGilham/altcover/wiki/Usage for full details.
</value>
</data>
<data name="NotInPlace" xml:space="preserve">
<value>From and to directories are identical</value>
<value>From and to directories {0} are identical</value>
</data>
<data name="UsageError" xml:space="preserve">
<value>Error - usage is:</value>
Expand Down Expand Up @@ -387,4 +387,7 @@ If this problem was detected in the pre-test instrumentation stage of `dotnet te
<data name="defer:" xml:space="preserve">
<value>Optional, defers writing runner-mode coverage data until process exit.</value>
</data>
<data name="DuplicatesNotAllowed" xml:space="preserve">
<value>{0} was already specified for {1}</value>
</data>
</root>
45 changes: 23 additions & 22 deletions AltCover/Visitor.fs
Expand Up @@ -68,8 +68,8 @@ type internal GoTo =

[<ExcludeFromCodeCoverage; NoComparison>]
type internal Node =
| Start of seq<string>
| Assembly of AssemblyDefinition * Inspect
| Start of seq<string * string list>
| Assembly of AssemblyDefinition * Inspect * string list
| Module of ModuleDefinition * Inspect
| Type of TypeDefinition * Inspect
| Method of MethodDefinition * Inspect * (int * string) option
Expand All @@ -78,12 +78,12 @@ type internal Node =
| AfterMethod of MethodDefinition * Inspect * (int * string) option
| AfterType
| AfterModule
| AfterAssembly of AssemblyDefinition
| AfterAssembly of AssemblyDefinition * string list
| Finish
member this.After() =
(match this with
| Start _ -> [ Finish ]
| Assembly(a, _) -> [ AfterAssembly a ]
| Assembly(a, _, l) -> [ AfterAssembly (a, l) ]
| Module _ -> [ AfterModule ]
| Type _ -> [ AfterType ]
| Method(m, included, track) -> [ AfterMethod(m, included, track) ]
Expand Down Expand Up @@ -317,23 +317,24 @@ module internal Visitor =

let private accumulator = HashSet<AssemblyDefinition>()

let private StartVisit (paths : seq<string>) buildSequence =
let private StartVisit (paths : seq<string * string list>) buildSequence =
paths
|> Seq.collect (AssemblyDefinition.ReadAssembly
>> (fun x ->
x
|> accumulator.Add
|> ignore
// Reject completely if filtered here
let inspection = IsIncluded x

let included =
inspection ||| if inspection = Inspect.Instrument
&& ReportFormat() = Base.ReportFormat.OpenCoverWithTracking then
Inspect.Track
else Inspect.Ignore
ProgramDatabase.ReadSymbols(x)
Assembly(x, included))
|> Seq.collect (fun (path, targets) -> path
|> (AssemblyDefinition.ReadAssembly
>> (fun x ->
x
|> accumulator.Add
|> ignore
// Reject completely if filtered here
let inspection = IsIncluded x

let included =
inspection ||| if inspection = Inspect.Instrument
&& ReportFormat() = Base.ReportFormat.OpenCoverWithTracking then
Inspect.Track
else Inspect.Ignore
ProgramDatabase.ReadSymbols(x)
Assembly(x, included, targets)))
>> buildSequence)

let private VisitAssembly (a : AssemblyDefinition) included buildSequence =
Expand Down Expand Up @@ -760,7 +761,7 @@ module internal Visitor =
// The pattern here is map x |> map y |> map x |> concat => collect (x >> y >> z)
match node with
| Start paths -> StartVisit paths BuildSequence
| Assembly(a, included) -> VisitAssembly a included BuildSequence
| Assembly(a, included, _) -> VisitAssembly a included BuildSequence
| Module(x, included) -> VisitModule x included BuildSequence
| Type(t, included) -> VisitType t included BuildSequence
| Method(m, included, _) -> VisitMethod m included
Expand All @@ -775,7 +776,7 @@ module internal Visitor =
let internal apply (visitors : list<Fix<Node>>) (node : Node) =
visitors |> List.map (invoke node)

let internal Visit (visitors : seq<Fix<Node>>) (assemblies : seq<string>) =
let internal Visit (visitors : seq<Fix<Node>>) (assemblies : seq<string * string list>) =
ZeroPoints()
MethodNumber <- 0
try
Expand Down

0 comments on commit f54030e

Please sign in to comment.