TestingHelper.psm1
Write-Host "Loading TestingHelper ..." -ForegroundColor DarkCyan function Test-Assert { [CmdletBinding()] [Alias("Assert")] param ( [Parameter(Mandatory = $true)] [bool] $Condition, [Parameter()] [bool] $Expected = $true, [Parameter()] [string] $Comment = "No Comment" ) Write-Verbose -Message "Assert -Condition $Condition -Expected $Expected - $Comment" if ($Condition -ne $Expected) { throw "Assertion - Found $Condition Expected $Expected - $Comment" } else { Write-Host "." -NoNewline -ForegroundColor DarkMagenta } } function Start-TestFunction { [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string] $FunctionName ) Write-Host "$FunctionName ... [" -NoNewline -ForegroundColor DarkCyan & $FunctionName Write-Host "] " -NoNewline -ForegroundColor DarkCyan Write-Host "PASS" -ForegroundColor DarkYellow } function Start-Test { [CmdletBinding()] param ( [string]$Prefix ) Write-Host "Running functions $Prefix* ..." -ForegroundColor DarkYellow $f = Get-ChildItem function:$Prefix* $f | ForEach-Object {Write-Verbose -Message $_.Name} $f | ForEach-Object{ Start-TestFunction -FunctionName $_.Name } } function IsTrue { [CmdletBinding()] param ( [Parameter()] [bool] $Condition ) Assert -Condition $Condition -Expected $true } function IsFalse { [CmdletBinding()] param ( [Parameter()] [bool] $Condition ) Assert -Condition $Condition -Expected $false } function Trace-Message { [CmdletBinding()] param ( [Parameter(Position=1)] [string] $Message ) Write-Verbose -Message $Message } |