11param (
2- [ValidateSet (' None' , ' Default' , ' Passed' , ' Failed' , ' Pending' , ' Skipped' , ' Inconclusive' , ' Describe' , ' Context' , ' Summary' , ' Header' , ' Fails' , ' All' )]
3- [string ]
4- $Show = " None" ,
5-
6- [ValidateSet (' Everything' , ' Functions' , ' General' )]
7- [string ]
8- $Run = " Everything" ,
9-
10- [string ]
11- $Filter = " *.Tests.ps1"
2+ [ValidateSet (' None' , ' Default' , ' Passed' , ' Failed' , ' Pending' , ' Skipped' , ' Inconclusive' , ' Describe' , ' Context' , ' Summary' , ' Header' , ' Fails' , ' All' )]
3+ [string ]
4+ $Show = " None" ,
5+
6+ [ValidateSet (' Everything' , ' Functions' , ' General' )]
7+ [string ]
8+ $Run = " Everything" ,
9+
10+ [string ]
11+ $Filter = " *.Tests.ps1"
1212)
1313
1414Write-Host " Starting Tests" - ForegroundColor Green
@@ -24,63 +24,56 @@ $totalRun = 0
2424
2525$testresults = @ ()
2626
27- if ($Run -match " Everything|General" )
28- {
29- Write-PSFMessage - Level Important - Message " Modules imported, proceeding with general tests"
30- foreach ($file in (Get-ChildItem " $PSScriptRoot \general" - Filter $Filter ))
31- {
32- Write-PSFMessage - Level Significant - Message " Executing <c='em'>$ ( $file.Name ) </c>"
33- $TestOuputFile = Join-Path " $PSScriptRoot \..\..\TestResults" " TEST-$ ( $file.BaseName ) .xml"
34- $results = Invoke-Pester - Script $file.FullName - Show $Show - PassThru - OutputFile $TestOuputFile - OutputFormat NUnitXml
35- foreach ($result in $results )
36- {
37- $totalRun += $result.TotalCount
38- $totalFailed += $result.FailedCount
39- $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
40- $name = $_.Name
41- $testresults += [pscustomobject ]@ {
42- Describe = $_.Describe
43- Context = $_.Context
44- Name = " It $name "
45- Result = $_.Result
46- Message = $_.FailureMessage
47- }
48- }
49- }
50- }
27+ if ($Run -match " Everything|General" ) {
28+ Write-PSFMessage - Level Important - Message " Modules imported, proceeding with general tests"
29+ foreach ($file in (Get-ChildItem " $PSScriptRoot \general" - Filter $Filter )) {
30+ Write-PSFMessage - Level Significant - Message " Executing <c='em'>$ ( $file.Name ) </c>"
31+ $TestOuputFile = Join-Path " $PSScriptRoot \..\..\TestResults" " TEST-$ ( $file.BaseName ) .xml"
32+ $results = Invoke-Pester - Script $file.FullName - Show $Show - PassThru - OutputFile $TestOuputFile - OutputFormat NUnitXml
33+ foreach ($result in $results ) {
34+ $totalRun += $result.TotalCount
35+ $totalFailed += $result.FailedCount
36+ $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
37+ $name = $_.Name
38+ $testresults += [pscustomobject ]@ {
39+ Describe = $_.Describe
40+ Context = $_.Context
41+ Name = " It $name "
42+ Result = $_.Result
43+ Message = $_.FailureMessage
44+ }
45+ }
46+ }
47+ }
5148}
5249
53- if ($Run -match " Everything|Functions" )
54- {
55- Write-PSFMessage - Level Important - Message " Proceeding with individual tests"
56- foreach ($file in (Get-ChildItem " $PSScriptRoot \functions" - Recurse - File - Filter $Filter ))
57- {
58- Write-PSFMessage - Level Significant - Message " Executing $ ( $file.Name ) "
59- $results = Invoke-Pester - Script $file.FullName - Show $Show - PassThru
60- foreach ($result in $results )
61- {
62- $totalRun += $result.TotalCount
63- $totalFailed += $result.FailedCount
64- $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
65- $name = $_.Name
66- $testresults += [pscustomobject ]@ {
67- Describe = $_.Describe
68- Context = $_.Context
69- Name = " It $name "
70- Result = $_.Result
71- Message = $_.FailureMessage
72- }
73- }
74- }
75- }
50+ if ($Run -match " Everything|Functions" ) {
51+ Write-PSFMessage - Level Important - Message " Proceeding with individual tests"
52+ foreach ($file in (Get-ChildItem " $PSScriptRoot \functions" - Recurse - File - Filter $Filter )) {
53+ Write-PSFMessage - Level Significant - Message " Executing $ ( $file.Name ) "
54+ $results = Invoke-Pester - Script $file.FullName - Show $Show - PassThru
55+ foreach ($result in $results ) {
56+ $totalRun += $result.TotalCount
57+ $totalFailed += $result.FailedCount
58+ $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
59+ $name = $_.Name
60+ $testresults += [pscustomobject ]@ {
61+ Describe = $_.Describe
62+ Context = $_.Context
63+ Name = " It $name "
64+ Result = $_.Result
65+ Message = $_.FailureMessage
66+ }
67+ }
68+ }
69+ }
7670}
7771
7872$testresults | Sort-Object Describe, Context, Name, Result, Message | Format-List
7973
8074if ($totalFailed -eq 0 ) { Write-PSFMessage - Level Critical - Message " All <c='em'>$totalRun </c> tests executed without a single failure!" }
8175else { Write-PSFMessage - Level Critical - Message " <c='em'>$totalFailed tests</c> out of <c='sub'>$totalRun </c> tests failed!" }
8276
83- if ($totalFailed -gt 0 )
84- {
85- throw " $totalFailed / $totalRun tests failed!"
77+ if ($totalFailed -gt 0 ) {
78+ throw " $totalFailed / $totalRun tests failed!"
8679}
0 commit comments