|
1 | | -$ErrorActionPreference = "Stop" |
2 | | -# Do not set error action preference let Pester handle it instead |
3 | | -$result = 0 |
| 1 | +function New-TemporaryDirectory { |
| 2 | + $tmp = [System.IO.Path]::GetTempPath() # Not $env:TEMP, see https://stackoverflow.com/a/946017 |
| 3 | + $name = (New-Guid).ToString("N") |
| 4 | + New-Item -ItemType Directory -Path (Join-Path $tmp $name) |
| 5 | +} |
| 6 | + |
| 7 | +$moduleDir = New-TemporaryDirectory |
| 8 | +$pesterModule = Find-Module -Name Pester -MaximumVersion "5.9999" -MinimumVersion "5.0" |
| 9 | +$pesterModule | Save-Module -Path $moduleDir |
| 10 | + |
| 11 | +Import-Module "$moduleDir\Pester\$($pesterModule.Version)\Pester.psm1" |
4 | 12 |
|
5 | | -Import-Module ./Pester/pester.psm1; |
6 | 13 | $status = (Get-Service -Name "wuauserv").Status |
7 | 14 | $startupType = Get-Service "wuauserv" | Select-Object -ExpandProperty StartType | Out-String |
8 | 15 | "wuauserv status = * $status *" |
9 | 16 | "wuauserv startuptype = * $startupType *" |
10 | 17 |
|
11 | | -foreach ($module in (Get-ChildItem "./stemcell-builder/modules").Name) { |
12 | | - Push-Location "./stemcell-builder/modules/$module" |
| 18 | +$result = 0 |
| 19 | + |
| 20 | +$testModules = Get-ChildItem "./bosh-psmodules-repo/modules/" -recurse | where {$_.name -match ".*.Tests.ps1"} | foreach {$_.DirectoryName} |
| 21 | +foreach ($module in $testModules) { |
| 22 | + Write-Host "Testing: $module" |
| 23 | + Push-Location "$module" |
| 24 | + |
| 25 | + # Do not set $ErrorActionPreference and let Pester handle it nativetly; setting it to Stop globally will |
| 26 | + # break the tests since they are written with the assumption non zero exit codes will not fail a test |
| 27 | + # See: https://github.com/pester/Pester/issues/1404#issuecomment-568659518 for details |
13 | 28 | $results=Invoke-Pester -PassThru |
14 | 29 | if ($results.FailedCount -gt 0) { |
15 | 30 | $result += $results.FailedCount |
16 | 31 | } |
17 | | - Pop-Location |
| 32 | + |
| 33 | + Pop-Location |
18 | 34 | } |
| 35 | + |
19 | 36 | echo "Failed Tests: $result" |
20 | 37 | exit $result |
| 38 | + |
0 commit comments