Skip to content

Commit

Permalink
Portable - Operational positive test and consequences
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Apr 5, 2024
1 parent e9e3813 commit cb49107
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 18 deletions.
4 changes: 2 additions & 2 deletions AltCover.Engine/Canonical.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if RUNNER
#if RUNNER || RECORDER
namespace AltCover
#else
namespace AltCoverFake.DotNet.Testing
Expand All @@ -15,7 +15,7 @@ module internal Canonical =
Uri("file://" + (Path.GetFullPath path), UriKind.Absolute)
.LocalPath

#if !FAKE && !NoCanonicalDirectories
#if !FAKE && !NoCanonicalDirectories && !RECORDER
let canonicalDirectory (path: string) =
let last = path |> Seq.last

Expand Down
24 changes: 15 additions & 9 deletions AltCover.Engine/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ module internal Main =
CoverageParameters.sourcelink.Value <- false // ddFlag
CoverageParameters.coalesceBranches.Value <- false // ddFlag
CoverageParameters.staticFilter <- None
CoverageParameters.showGenerated.Value <- false
CoverageParameters.trivia.Value <- false
CoverageParameters.portable.Value <- false
CoverageParameters.showGenerated.Value <- false // ddFlag
CoverageParameters.trivia.Value <- false // ddFlag
CoverageParameters.portable.Value <- false // ddFlag

let internal validateCallContext predicate x =
if not (String.IsNullOrWhiteSpace x) then
Expand Down Expand Up @@ -710,6 +710,17 @@ module internal Main =
| ReportFormat.NativeJson -> NativeJson.reportGenerator ()
| _ -> Report.reportGenerator ()

let internal canonicalReportPath () =
Path.Combine(
(if CoverageParameters.inplace.Value then
CoverageParameters.inputDirectories ()
else
CoverageParameters.outputDirectories ())
|> Seq.head,
CoverageParameters.reportPath ()
)
|> Canonical.canonicalPath

[<SuppressMessage("Gendarme.Rules.BadPractice",
"GetEntryAssemblyMayReturnNullRule",
Justification = "That is the whole point of the call.")>]
Expand Down Expand Up @@ -738,12 +749,7 @@ module internal Main =
| Right(rest, fromInfo, toInfo, targetInfo) ->
CommandLine.applyVerbosity ()

let report =
Path.Combine(
CoverageParameters.outputDirectories ()
|> Seq.head,
CoverageParameters.reportPath ()
)
let report = canonicalReportPath ()

let result =
CommandLine.doPathOperation
Expand Down
1 change: 1 addition & 0 deletions AltCover.Recorder/AltCover.Recorder.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<Compile Include="..\_Generated\VisibleToTest.fs" Link="VisibleToTest.fs" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="..\AltCover.Engine\StringExtension.fs" Link="StringExtension.fs" />
<Compile Include="..\AltCover.Engine\Canonical.fs" Link="Canonical.fs" />
<Compile Include="Base.fs" />
<Compile Include="Tracer.fs" />
<Compile Include="Recorder.fs" />
Expand Down
3 changes: 3 additions & 0 deletions AltCover.Recorder/Recorder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ open System.Reflection

open System.Resources
open System.Runtime.CompilerServices
#if !NET20
open System.Threading
#endif

open AltCover.Shared

Expand All @@ -31,6 +33,7 @@ module Instance =
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
ReportFile
)
|> AltCover.Canonical.canonicalPath

/// <summary>
/// Gets whether to defer output until process exit
Expand Down
3 changes: 2 additions & 1 deletion AltCover.Tests/Expecto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,8 @@ module ExpectoTestManifest =
Tests.AltCoverTests3.ParsingMixedQuietWorks, "Tests3.ParsingMixedQuietWorks"
Tests.AltCoverTests3.OutputLeftPassesThrough, "Tests3.OutputLeftPassesThrough"
Tests.AltCoverTests3.OutputInPlaceFails, "Tests3.OutputInPlaceFails"
Tests.AltCoverTests3.PortableFailsOnMultiInputs, "Tests3.PortableFailsOnMultiInputs"
Tests.AltCoverTests3.PortableFailsOnMultiInputs,
"Tests3.PortableFailsOnMultiInputs"
Tests.AltCoverTests3.ScreeningFilesShouldRejectTheInstrumentedOnes,
"Tests3.ScreeningFilesShouldRejectTheInstrumentedOnes"
Tests.AltCoverTests3.OutputToNewPlaceIsOK, "Tests3.OutputToNewPlaceIsOK"
Expand Down
34 changes: 31 additions & 3 deletions AltCover.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -998,20 +998,42 @@ module AltCoverTests =
[<Test>]
let ReportFileShouldBeCorrectlyExtended () =
try
Main.init ()

let path1 =
Path.Combine(SolutionRoot.location, "test.xml")

let from = Path.Combine(path1, "from")
let toward = Path.Combine(path1, "to")

CoverageParameters.theReportFormat <- Some ReportFormat.NCover
CoverageParameters.theReportPath <- Some path1
test <@ CoverageParameters.reportPath () = path1 @>

CoverageParameters.theInputDirectories.Clear()
CoverageParameters.theOutputDirectories.Clear()
CoverageParameters.theInputDirectories.Add from
CoverageParameters.theOutputDirectories.Add toward

CoverageParameters.portable.Value <- true
test <@ CoverageParameters.reportPath () = "./test.xml" @>

test
<@
Main.I.canonicalReportPath () = (Path.Combine(toward, "test.xml")
|> Canonical.canonicalPath)
@>

CoverageParameters.inplace.Value <- true

test
<@
Main.I.canonicalReportPath () = (Path.Combine(from, "test.xml")
|> Canonical.canonicalPath)
@>

finally
CoverageParameters.theReportPath <- None
CoverageParameters.theReportFormat <- None
CoverageParameters.portable.Value <- false
Main.init ()

[<Test>]
let ReportFileShouldBeCorrectlySuffixed () =
Expand All @@ -1028,22 +1050,28 @@ module AltCoverTests =
CoverageParameters.theReportFormat <- Some ReportFormat.NCover
CoverageParameters.theReportPath <- Some path1
test <@ CoverageParameters.reportPath () = path1 @>
test <@ Main.I.canonicalReportPath () = Canonical.canonicalPath (path1) @>

CoverageParameters.theReportPath <- Some path2
test <@ CoverageParameters.reportPath () = path2 @>
test <@ Main.I.canonicalReportPath () = Canonical.canonicalPath (path2) @>

CoverageParameters.theReportPath <- Some path3
test <@ CoverageParameters.reportPath () = path1 @>
test <@ Main.I.canonicalReportPath () = Canonical.canonicalPath (path1) @>

CoverageParameters.theReportFormat <- Some ReportFormat.NativeJson
CoverageParameters.theReportPath <- Some path1
test <@ CoverageParameters.reportPath () = path3 @>
test <@ Main.I.canonicalReportPath () = Canonical.canonicalPath (path3) @>

CoverageParameters.theReportPath <- Some path2
test <@ CoverageParameters.reportPath () = path2 @>
test <@ Main.I.canonicalReportPath () = Canonical.canonicalPath (path2) @>

CoverageParameters.theReportPath <- Some path3
test <@ CoverageParameters.reportPath () = path3 @>
test <@ Main.I.canonicalReportPath () = Canonical.canonicalPath (path3) @>

finally
CoverageParameters.theReportPath <- None
Expand Down
12 changes: 9 additions & 3 deletions Build/targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7620,6 +7620,8 @@ module Targets =
let o =
Path.getFullName "./_Binaries/_DotnetGlobalTest/Debug+AnyCPU/net8.0"

let r = Path.Combine(o, Path.GetFileName x)

[ AltCoverCommand.ArgumentType.ImportModule
AltCoverCommand.ArgumentType.GetVersion ]
|> List.iter (
Expand All @@ -7640,15 +7642,16 @@ module Targets =
AssemblyFilter = [| "xunit" |]
LocalSource = true
InPlace = true
Save = false }
Save = false
Portable = true }
)
|> AltCoverCommand.Prepare

{ AltCoverCommand.Options.Create prep with
WorkingDirectory = working }
|> AltCoverCommand.run

Actions.CheckSample4Content x
Actions.CheckSample4Content r

printfn "Execute the instrumented tests"

Expand All @@ -7667,7 +7670,7 @@ module Targets =
WorkingDirectory = working }
|> AltCoverCommand.run

Actions.CheckSample4Visits before x
Actions.CheckSample4Visits before r

let command =
"""$ImportModule = (altcover ImportModule | Out-String).Trim().Split()[1].Trim(@([char]34)); Import-Module $ImportModule; ConvertTo-BarChart -?"""
Expand All @@ -7677,6 +7680,9 @@ module Targets =
|> Proc.run
|> (Actions.AssertResult "pwsh")

// put where we want it later
Shell.copy (Path.GetDirectoryName x) [ r ]

finally
if set then
Actions.RunDotnet
Expand Down

0 comments on commit cb49107

Please sign in to comment.