Public/Add-PsmTest.ps1
function Add-PsmTest { <# .Synopsis A function that creates a function.Tests.ps1 file stub .DESCRIPTION A function that creates a function.Tests.ps1 file stub for an easy start to creating powershell modules/function in a TDD manner .EXAMPLE Add-PsmTest "Write-HereWeGo" Add-PsmTest "Write-HereWeGo" -Whatif #> [CmdletBinding(SupportsShouldProcess=$true)] param( [Parameter( Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [ValidatePattern("^[a-zA-Z]{3,}-[a-zA-Z]{3,}$")] [string]$functionName ) BEGIN{ Write-Verbose "Starting Add-PsmTest..." Confirm-IsInitializedModulePath $packageXml = Import-CliXml .\module-psd1.xml }#begin PROCESS{ if ($psCmdlet.ShouldProcess(<# on target --> #>"$($packageXml.RootModule)", <# What if: Performing operation --> #>"Adding new test function $functionName")) { Show-IsApprovedVerb $functionName if (Test-Path -Path .\Tests -PathType Container) { Get-PsmTestContent $functionName $packageXml.RootModule | Set-Content .\Tests\$functionName.Tests.ps1 Write-Verbose ".\Tests\$functionName.ps1 file written" } else { throw "No .\Tests folder found, this is not an initialized module folder... Run: ``Initialize-Psm``" } } }#process END{ Write-Verbose "Finished Add-PsmTest..." }#end } |