Public/Get-WatchmenTest.ps1

function Get-WatchmenTest {
    [cmdletbinding()]
    param(
        [parameter(Mandatory, ValueFromPipeline)]
        [ValidateScript({Test-Path $_})]
        [string[]]$Path = (Get-Location).Path,

        [switch]$Recurse
    )

    begin {
        Write-Debug -Message "Entering: $($PSCmdlet.MyInvocation.MyCommand.Name)"
        Initialize-Watchmen
    }

    process {
        try {
            foreach ($loc in $path) {
                $item = Get-Item -Path (Resolve-Path $loc)
                if ($item.PSIsContainer) {
                    $files = Get-ChildItem -Path $item -Filter '*.watchmen.ps1' -Recurse:$Recurse
                    $global:watchmen.CurrentWatchmenFileRoot = $item.FullName
                } else {
                    $files = $item
                    $global:watchmen.CurrentWatchmenFileRoot = $item.Directory
                }

                $tests = @()
                foreach ($file in $files) {
                    Write-Verbose -Message "Loading Watchmen tests from file [$($file.FullName)]"
                    $fileTests = @()
                    $fileTests += . $file.FullName

                    $tests += $fileTests
                    $global:watchmen.TestSets += $fileTests
                }

                $tests
            }
        } catch {
            throw $_
            # Remove-Variable -Name Watchmen -Scope Global -ErrorAction Ignore
        }
    }

    end {
        #Remove-Variable -Name Watchmen -Scope Global -ErrorAction Ignore
        Write-Debug -Message "Exiting: $($PSCmdlet.MyInvocation.MyCommand.Name)"
    }
}