Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call operator not detected for code coverage #1143

Open
KreizIT opened this issue Nov 5, 2018 · 2 comments
Open

Call operator not detected for code coverage #1143

KreizIT opened this issue Nov 5, 2018 · 2 comments
Assignees

Comments

@KreizIT
Copy link

KreizIT commented Nov 5, 2018

1. General summary of the issue

Line where call operator is used is reported as not covered by Pester's codeCoverage capabilty.
ie : $scriptCmd = {& $wrappedCmd @PSBoundParameters }
Code coverage report :
File Function Line Command


ProxyCmd.ps1 Write-TrueHost 29 $scriptCmd = {& $wrappedCmd @PSBoundParameters }
ProxyCmd.ps1 Write-TrueHost 29 & $wrappedCmd @PSBoundParameters

2. Describe Your Environment

Pester version : 4.4.2 C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Pester.psm1
PowerShell version : 5.1.14409.1005
OS version : Microsoft Windows NT 6.1.7601 Service Pack 1

3. Expected Behavior

Report this line as covered

4.Current Behavior

Missing coverage

5. Possible Solution

Tag or mark a line as "excluded" from coverage report ?

6. Context

I'm trying to get a 100% covered code but got only 98% cause of this line :-/

Thanks for help or advise ;)

@KreizIT
Copy link
Author

KreizIT commented Nov 5, 2018

Full code :

function Write-TrueHost {
	[CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=113426', RemotingCapability='None')]
	param(
		[Parameter(Position=0, ValueFromPipeline=$true, ValueFromRemainingArguments=$true)]
		[System.Object]
		${Object},

		[switch]
		${NoNewline},

		[System.Object]
		${Separator},

		[System.ConsoleColor]
		${ForegroundColor},

		[System.ConsoleColor]
		${BackgroundColor})

	begin
	{
		try {
			$outBuffer = $null
			if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
			{
				$PSBoundParameters['OutBuffer'] = 1
			}
			$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Write-Host', [System.Management.Automation.CommandTypes]::Cmdlet)
			$scriptCmd = {& $wrappedCmd @PSBoundParameters }
			$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
			$steppablePipeline.Begin($PSCmdlet)
		} catch {
			throw
		}
	}

	process
	{
		try {
			$steppablePipeline.Process($_)
		} catch {
			throw
		}
	}

	end
	{
		try {
			$steppablePipeline.End()
		} catch {
			throw
		}
	}
}

Describe "Write-TrueHost" {

    It "Sould write to host" {
        $message = Write-TrueHost "Mocked" 6>&1
        $message | Should -BeExactly "Mocked"
    }

    It "Sould buffering to host" {
        $res= (0..10| Write-TrueHost -OutBuffer 5 6>&1)
        $res.count | Should -be 11
    }

}

@nohwnd nohwnd self-assigned this Nov 6, 2018
@nohwnd
Copy link
Member

nohwnd commented Jan 8, 2019

@KreizIT Thans for the issue, the code coverage works by setting breakpoints, so it's possible that we either missed it or the breakpoint cannot be set there. Will review this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants