Public/Get-WatchmenTest.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
                    $script:watchmen.CurrentWatchmenFileRoot = $item.FullName
                } else {
                    $files = $item
                    $script: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
                    $script:watchmen.TestSets += $fileTests
                }

                $tests
            }
        } catch {
            throw $_
        }
    }

    end {
        Write-Debug -Message "Exiting: $($PSCmdlet.MyInvocation.MyCommand.Name)"
    }
}