From 0b994c950213fcf6d6f2ced8377f6e00f65bb104 Mon Sep 17 00:00:00 2001 From: Remco Kapinga Date: Sun, 28 Jan 2018 10:15:32 +0100 Subject: [PATCH] Fixed detection of empty tests (#835) * Fixed detection of empty tests --- Functions/It.ps1 | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Functions/It.ps1 b/Functions/It.ps1 index 80cd873d7..a4cf139cf 100644 --- a/Functions/It.ps1 +++ b/Functions/It.ps1 @@ -157,12 +157,26 @@ function ItImpl if ($null -eq $test) { $test = {} } #mark empty Its as Pending - #[String]::IsNullOrWhitespace is not available in .NET version used with PowerShell 2 - if ($PSCmdlet.ParameterSetName -eq 'Normal' -and - [String]::IsNullOrEmpty((Remove-Comments $test.ToString()) -replace "\s")) + if ($PSVersionTable.PSVersion.Major -le 2 -and + $PSCmdlet.ParameterSetName -eq 'Normal' -and + [String]::IsNullOrEmpty((Remove-Comments $test.ToString()) -replace "\s")) { $Pending = $true } + elseIf ($PSVersionTable.PSVersion.Major -gt 2) + { + #[String]::IsNullOrWhitespace is not available in .NET version used with PowerShell 2 + # AST is not available also + $testIsEmpty = + [String]::IsNullOrEmpty($test.Ast.BeginBlock.Statements) -and + [String]::IsNullOrEmpty($test.Ast.ProcessBlock.Statements) -and + [String]::IsNullOrEmpty($test.Ast.EndBlock.Statements) + + if ($PSCmdlet.ParameterSetName -eq 'Normal' -and $testIsEmpty) + { + $Pending = $true + } + } $pendingSkip = @{}