forked from pester/Pester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pester.Runtime.ResultObject.ts.ps1
230 lines (194 loc) · 8.64 KB
/
Pester.Runtime.ResultObject.ts.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
param ([switch] $PassThru)
Get-Item function:wrapper -ErrorAction SilentlyContinue | remove-item
Get-Module Pester.Runtime.Wrapper, Pester.Utility, P, Pester, Axiom | Remove-Module
. $PSScriptRoot\..\src\Pester.Utility.ps1
New-Module -Name Pester.Runtime.Wrapper -ScriptBlock {
# make sure that the Pester.Runtime code runs in a module,
# because in the end it would be inlined into a module as well
# so the behavior here needs to reflect that to avoid false positive
# issues, like $Data variable in test conflicting with a parameter $Data
# in the runtime, which won't happen when they are isolated by a module
. $PSScriptRoot\..\src\Pester.Runtime.ps1
} | Import-Module -DisableNameChecking
Import-Module $PSScriptRoot\p.psm1 -DisableNameChecking
Import-Module $PSScriptRoot\axiom\Axiom.psm1 -DisableNameChecking
$global:PesterPreference = @{
Debug = @{
ShowFullErrors = $true
WriteDebugMessages = $false
WriteDebugMessagesFrom = "Timing*"
}
}
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
i -PassThru:$PassThru {
b "Counting tests" {
t "Passed and counts are correct for non nested blocks" {
$actual = Invoke-Test -SessionState $ExecutionContext.SessionState -BlockContainer (
New-BlockContainerObject -ScriptBlock {
New-Block -Name "b1" {
New-Test "t1" {
$true
}
New-Test "t2" {
throw
}
}
New-Block -name "b2" {
New-Test "b2" {
$true
}
}
}
)
# the whole container did not pass because there were failed tests
$actual.Passed | Verify-False
# the container itself passes because no setup/teardown failed directly in it
$actual.OwnPassed | Verify-True
# there are 3 tests total
$actual.TotalCount | Verify-Equal 3
# two tests passed
$actual.PassedCount | Verify-Equal 2
# one test failed
$actual.FailedCount | Verify-Equal 1
# block b1
# the block did not pass because it contains a failed test
$actual.Blocks[0].Passed | Verify-False
# no setup/teardown failed in this test so the block itself passed
$actual.Blocks[0].OwnPassed | Verify-True
# there are 2 tests total
$actual.Blocks[0].TotalCount | Verify-Equal 2
# one test passed
$actual.Blocks[0].PassedCount | Verify-Equal 1
# one test failed
$actual.Blocks[0].FailedCount | Verify-Equal 1
# block b2
# the block passed because there were no failed tests
$actual.Blocks[1].Passed | Verify-True
# no setup/teardown failed in this test so the block itself passed
$actual.Blocks[1].OwnPassed | Verify-True
# there is 1 test total
$actual.Blocks[1].TotalCount | Verify-Equal 1
# one test passed
$actual.Blocks[1].PassedCount | Verify-Equal 1
# 0 tests failed
$actual.Blocks[1].FailedCount | Verify-Equal 0
}
t "Passed and counts are correct nested blocks" {
$actual = Invoke-Test -SessionState $ExecutionContext.SessionState -BlockContainer (
New-BlockContainerObject -ScriptBlock {
New-Block -Name "b1" {
New-Block -Name "b1.1" {
New-Test "t1" {
$true
}
New-Test "t2" {
throw
}
}
}
}
)
# the whole container did not pass because there were failed tests
$actual.Passed | Verify-False
# the container itself passes because no setup/teardown failed directly in it
$actual.OwnPassed | Verify-True
$actual.TotalCount | Verify-Equal 2
$actual.PassedCount | Verify-Equal 1
$actual.FailedCount | Verify-Equal 1
# block b1
# the block did not pass because it contains a failed test block
$actual.Blocks[0].Passed | Verify-False
# no setup/teardown failed in this test so the block itself passed
$actual.Blocks[0].OwnPassed | Verify-True
# block b1.1
# there are 2 tests total
$actual.Blocks[0].Blocks[0].TotalCount | Verify-Equal 2
# one test passed
$actual.Blocks[0].Blocks[0].PassedCount | Verify-Equal 1
# one test failed
$actual.Blocks[0].Blocks[0].FailedCount | Verify-Equal 1
}
t "Passed and counts are correct on blocks that fail in setup or teardown blocks" {
$actual = Invoke-Test -SessionState $ExecutionContext.SessionState -BlockContainer (
New-BlockContainerObject -ScriptBlock {
New-Block -Name "b1" {
New-Block -Name "b1.1" {
New-OneTimeTestSetup { throw }
New-Test "t1" {
$true
}
}
}
New-Block -Name "b2" {
New-Block -Name "b2.1" {
New-OneTimeTestTeardown { throw }
New-Test "t2" {
$true
}
}
}
New-Block -name "b3" {
New-OneTimeTestSetup { throw }
New-Test "t3" {
$true
}
}
New-Block -name "b4" {
New-OneTimeTestTeardown { throw }
New-Test "t4" {
$true
}
}
}
)
# the whole container did not pass because there were failed tests
$actual.Passed | Verify-False
# the container itself passes because no setup/teardown failed directly in it
$actual.OwnPassed | Verify-True
$actual.TotalCount | Verify-Equal 4
# two tests pass but their teardowns don't pass
$actual.PassedCount | Verify-Equal 2
# two tests fail because their setups fail
$actual.FailedCount | Verify-Equal 2
# block b1
# the block did not pass because it contains a failed setup block
$actual.Blocks[0].Passed | Verify-False
# setup/teardown failed in child but not here, so this block itself passed
$actual.Blocks[0].OwnPassed | Verify-True
# block b1.1
$actual.Blocks[0].Blocks[0].Passed | Verify-False
$actual.Blocks[0].Blocks[0].OwnPassed | Verify-False
$actual.Blocks[0].Blocks[0].TotalCount | Verify-Equal 1
# the test failed because the setup failed
$actual.Blocks[0].Blocks[0].PassedCount | Verify-Equal 0
$actual.Blocks[0].Blocks[0].FailedCount | Verify-Equal 1
# block b2.1
$actual.Blocks[1].Blocks[0].Passed | Verify-False
$actual.Blocks[1].Blocks[0].OwnPassed | Verify-False
$actual.Blocks[1].Blocks[0].TotalCount | Verify-Equal 1
# the test passed, but the teardown failed so the block failed
$actual.Blocks[1].Blocks[0].PassedCount | Verify-Equal 1
$actual.Blocks[1].Blocks[0].FailedCount | Verify-Equal 0
}
}
t "Passed and counts are correct container that fails in top-level BeforeAll" {
$actual = Invoke-Test -SessionState $ExecutionContext.SessionState -BlockContainer (
New-BlockContainerObject -ScriptBlock {
New-OneTimeTestSetup { throw }
New-Block -Name "b1" {
New-Block -Name "b1.1" {
New-Test "t1" {
$true
}
}
}
}
)
$actual.Passed | Verify-False
$actual.OwnPassed | Verify-False
$actual.TotalCount | Verify-Equal 1
$actual.PassedCount | Verify-Equal 0
$actual.FailedCount | Verify-Equal 1
}
}