Public/Test-Psm.ps1
function Test-Psm { <# .Synopsis Test-Psm runs invoke-pester on the current module .DESCRIPTION Test-Psm runs invoke-pester by default... .EXAMPLE Test-Psm #> [CmdletBinding(SupportsShouldProcess=$true)] param () BEGIN{ Write-Verbose "Starting Test-Psm..." Confirm-IsInitializedModulePath $psd1 = Import-Clixml .\module-psd1.xml $folderPath = "Module-Test" }#begin PROCESS{ if ($psCmdlet.ShouldProcess(<# on target --> #>"Module Name", <# What if: Performing operation --> #>"operation...")) { Write-Verbose "Importing module .\$($psd1.RootModule)..." Import-Module ".\$($psd1.RootModule)" -Verbose if ($scriptBlock) { Write-Verbose "Running script block" & ([scriptblock]::Create($scriptBlock)) } else { If (Test-Path -Path $folderPath -PathType Container) { Write-Verbose -Message "Importing from $folderPath" $testScripts = Get-ChildItem -Path $folderPath -Filter "*.ps1" ForEach ($testScript in $testScripts) { if ($testScript.BaseName -match "tests") { continue } Write-Verbose -Message " Importing $($testScript.BaseName)" . $($testScript.FullName) -Verbose } } else { Write-Error "Please pass a script block as a string to 'Test-Psm' or create testScripts in the $folderPath/ directory." } } } }#process END{ Write-Verbose "Finished Test-Psm..." }#end } |