Skip to content

v3.x – v6.x PowerShell integration

Steve Gilham edited this page Apr 11, 2020 · 1 revision

Use Import-Module either by specific path using the command given by AltCover.exe ipmo (or dotnet AltCover.dll ipmo or dotnet altcover ipmo or altcover ipmo), or add the appropriate directory to your PSModulePath and do a simple import.

The string output from AltCover ipmo is intended for convenient cutting and pasting; it can be used in a script like

$ipmo = (AltCover ipmo | Out-String).Trim().Split()[1].Trim(@('""'))
Import-Module $ipmo

which unpeels the wrapper around the file path. Just substitute in the appropriate invocation for the AltCover.

Cmdlets

Invoke-AltCover

NAME
    Invoke-AltCover
    
SYNTAX
    Invoke-AltCover [-Runner] -RecorderDirectory <string> [-WorkingDirectory <string>] [-Executable <string>] 
    [-LcovReport <string>] [-Threshold <string>] [-Cobertura <string>] [-OutputFile <string>] [-CommandLine 
    <string[]>] [-DropReturnCode] [-SummaryFormat {Default | R | B | RPlus | BPlus}] [-WhatIf] [-Confirm]  
    [<CommonParameters>]
    
    Invoke-AltCover [-CommandLine <string[]>] [-InputDirectory <string[]>] [-OutputDirectory <string[]>] 
    [-SymbolDirectory <string[]>] [-Dependency <string[]>] [-Key <string[]>] [-StrongNameKey <string>] [-XmlReport 
    <string>] [-FileFilter <string[]>] [-PathFilter <string[]>] [-AssemblyFilter <string[]>] [-AssemblyExcludeFilter 
    <string[]>] [-TypeFilter <string[]>] [-MethodFilter <string[]>] [-AttributeFilter <string[]>] [-CallContext 
    <string[]>] [-OpenCover] [-InPlace] [-Save] [-Single] [-LineCover] [-BranchCover] [-DropReturnCode] [-SourceLink] 
    [-Defer] [-LocalSource] [-VisibleBranches] [-ShowGenerated] [-ShowStatic {KeepHidden | Mark | Reveal}] [-WhatIf] 
    [-Confirm]  [<CommonParameters>]
    
    Invoke-AltCover [-Version] [-WhatIf] [-Confirm]  [<CommonParameters>]
    
ALIASES
    None

REMARKS
    None

† = .net Framework build/Windows PowerShell only before v6.0
‡ = .net core/pwsh builds only before v6.0
⁋ = just <string> before v6.0

The arguments parallel the command-line executable; the main difference is that -Runner is a switch parameter that selects the runner-mode parameter set if present.

The "working directory" used where mentioned in the parameter descriptions is the current set location in PowerShell, not the underlying current directory.

The Summary enumeration values are

  • Default -- OpenCover format
  • R -- TeamCity with R for bRanch
  • B -- TeamCity with B for Block representing branch coverage
  • RPlus -- R + Default
  • BPlus -- B + Default

-ShowStatic new at v6.6 takes the enum values as above or strings from v 6.7

  • KeepHidden -- or -
  • Mark -- or +
  • Reveal -- or ++

Note: As Powershell informational output is suppressed by default in PowerShell 5+, the -InformationAction Continue option is needed to show the progress and summary information for the process if this is desired.

Summary information is also written to the object pipeline from version 5.3

Note: -WhatIf includes validation for the command line arguments. It is ignored for the purely read-only -Version option

ConvertTo-Cobertura

NAME
    ConvertTo-Cobertura

SYNTAX
    ConvertTo-Cobertura [-XmlDocument] <xml> [[-OutputFile] <string>]  [<CommonParameters>]

    ConvertTo-Cobertura [-InputFile] <string> [[-OutputFile] <string>]  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

Takes either OpenCover or classic NCover format input as an XmlDocument (type [xml] in PowerShell terms), as an argument or from the object pipeline. Writes the Cobertura report to the object pipeline as an XDocument, and optionally to a file

ConvertTo-Lcov

NAME
    ConvertTo-Lcov

SYNTAX
    ConvertTo-Lcov [-XmlDocument] <xml> [-OutputFile] <string>  [<CommonParameters>]

    ConvertTo-Lcov [-InputFile] <string> [-OutputFile] <string>  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

Takes either OpenCover or classic NCover format input as an XmlDocument (type [xml] in PowerShell terms), as an argument or from the object pipeline. Writes the Lcov report to a file

ConvertTo-NCover

NAME
    ConvertTo-NCover

SYNTAX
    ConvertTo-NCover [-XmlDocument] <IXPathNavigable> [-OutputFile] <string>  [<CommonParameters>]

    ConvertTo-NCover [-InputFile] <string> [-OutputFile] <string>  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

Takes OpenCover format input either as an XmlDocument (type [xml] in PowerShell terms) from the object pipeline or from a file. Writes the classic NCover format report to the pipeline as an [xml], and, optionally, to a file.

ConvertFrom-NCover

NAME
    ConvertFrom-NCover

SYNTAX
    ConvertFrom-NCover [-XmlDocument] <IXPathNavigable> [-Assembly] <string[]> [[-OutputFile] <string>]
    [<CommonParameters>]

    ConvertFrom-NCover [-InputFile] <string> [-Assembly] <string[]> [[-OutputFile] <string>]  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

Takes classic NCover format input either as an XmlDocument (type [xml] in PowerShell terms) from the object pipeline or from a file. Writes the OpenCover format report to the pipeline as an [xml], and, optionally, to a file. The report will contain data for the assemblies listed as the -Assembly argument and that are in the NCover input.

ConvertTo-BarChart

NAME
    ConvertTo-BarChart

SYNTAX
    ConvertTo-BarChart [-XmlDocument] <IXPathNavigable> [[-OutputFile] <string>]  [<CommonParameters>]

    ConvertTo-BarChart [-InputFile] <string> [[-OutputFile] <string>]  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

Generates an HTML report, based on the old NCover 1.5.8 XSLT, for both NCover and OpenCover coverage format data. The input is as a file name or an [xml] from the pipeline, the output is to the pipeline as an [xml], and, optionally, to a file.

ConvertTo-XDocument

NAME
    ConvertTo-XDocument

SYNTAX
    ConvertTo-XDocument [-XmlDocument] <xml>  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

Takes an [xml] in and puts an XDocument to the object pipeline

ConvertTo-XmlDocument

NAME
    ConvertTo-XmlDocument

SYNTAX
    ConvertTo-XmlDocument [-XDocument] <XDocument>  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

Takes an XDocument in and puts an [xml] to the object pipeline

Compress-Branching

NAME
    Compress-Branching

SYNTAX
    Compress-Branching [-XmlDocument] <IXPathNavigable> [[-OutputFile] <string>] [[-WithinSequencePoint]]
    [<CommonParameters>]

    Compress-Branching [-XmlDocument] <IXPathNavigable> [[-OutputFile] <string>] [-WithinSequencePoint]
    [<CommonParameters>]

    Compress-Branching [-InputFile] <string> [[-OutputFile] <string>] [[-WithinSequencePoint]]  [<CommonParameters>]

    Compress-Branching [-InputFile] <string> [[-OutputFile] <string>] [-WithinSequencePoint]  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

Takes output from the OpenCover program, and adjust from OpenCover's liberal idea of significant branches towards AltCover's more restricted approach -- chose either or both of -SameSpan to unify branches that go from the same start, and take the same trajectory to the same end (OpenCover issue #786 being one instance of this) and -WithinSequencePoint to remove branches interior to a statement (compiler generated things like stashing of lambdas, the hidden conditional Dispose() after a using, or inside F# inlines -- OpenCover issues #657, #807 being instances of this).

Either takes an [xml] from the pipeline or from a file; emits the result as an [xml] to the pipeline and optionally to a file.

Format-FromCoverletOpenCover

NAME
    Format-FromCoverletOpenCover

SYNTAX
    Format-FromCoverletOpenCover [-Report] <XDocument> [[-OutputFile] <string>]  [<CommonParameters>]

    Format-FromCoverletOpenCover [-InputFile] <string> [[-OutputFile] <string>]  [<CommonParameters>]


ALIASES
    None


REMARKS
    None

Takes a coverage report in coverlet's OpenCover dialect, and fills in most of the gaps, particularly giving somewhat meaningful start and end column values for its line-based paradigm, as well as summaries, npath coverage, branch exits and other such details.