pester/Pester — pull request #148 by dlwyatt (2014-07-04 04:32:46+00:00)
Title: Code coverage analysis

Added -CodeCoverage parameter to Invoke-Pester. This allows users to specify files (or parts of files) which should be analyzed to see if any commands were not executed by the tests. The parameter's usage is somewhat like the Property parameters of Select-Object and Format-*; it can be passed either simple strings, or hashtables for finer control. Strings are paths to source files (which may contain wildcards), and the hashtables can contain the following keys (for convenience, each key may be abbreviated to its first letter, as shown):

@{
Path = 'Path to file (may contain wildcards)'
Function = 'Name of function to analyze (may contain wildcards)'
StartLine = 'First line of script to analyze. Defaults to beginning of file. Ignored if Function is present.'
EndLine = 'Last line of script to analyze. Defaults to end of file. Ignored if Function is present.'
}

@{
p = 'Path to file (may contain wildcards)'
f = 'Name of function to analyze (may contain wildcards)'
s = 'First line of script to analyze. Defaults to beginning of file. Ignored if Function is present.'
e = 'Last line of script to analyze. Defaults to end of file. Ignored if Function is present.'
}

The coverage report looks something like the following sample (and will also show up as a property on the -Passthru object, if this switch is used):

Code coverage report:
Covered 85.71 % of 7 analyzed commands in 1 file.

Missed commands:

File Line Command
---- ---- -------
C:\Users\Dave\desktop\test.ps1 18 'I am function two. I never get called.'