@@ -1225,52 +1225,49 @@ i -PassThru:$PassThru {
1225
1225
$container.EachTestTeardown | Verify- Equal 0
1226
1226
}
1227
1227
1228
- t " skipping all items in a block will skip the parent block" {
1229
- # this is not implemented, but is a possible feature
1230
- # which could be implemented together with "if any test is explicitly unskipped in child
1231
- # then the block should run, this will be needed for running tests explicitly by path I think
1232
- # it also should be taken into consideration whether or not adding a lazySkip is a good idea and how it would
1233
- # affect implementation of this. Right now skipping the block goes from parent down, and skipping all items in a block
1234
- # will not prevent the parent block setups from running
1235
-
1236
- # $container = @{
1237
- # OneTimeTestSetup = 0
1238
- # OneTimeTestTeardown = 0
1239
- # EachTestSetup = 0
1240
- # EachTestTeardown = 0
1241
- # TestRun = 0
1242
- # }
1228
+ t ' skipping all items in a block will skip the parent block' {
1229
+ $container = @ {
1230
+ OneTimeTestSetup = 0
1231
+ OneTimeTestTeardown = 0
1232
+ EachTestSetup = 0
1233
+ EachTestTeardown = 0
1234
+ TestRun = 0
1235
+ }
1236
+
1237
+ $actual = Invoke-Test - SessionState $ExecutionContext.SessionState - BlockContainer (New-BlockContainerObject - ScriptBlock {
1238
+ New-OneTimeTestSetup - ScriptBlock { $container.OneTimeTestSetup ++ }
1239
+ New-OneTimeTestTeardown - ScriptBlock { $container.OneTimeTestTeardown ++ }
1240
+
1241
+ New-Block ' parent block' {
1242
+ New-OneTimeTestSetup - ScriptBlock { $container.OneTimeTestSetup ++ }
1243
+ New-OneTimeTestTeardown - ScriptBlock { $container.OneTimeTestTeardown ++ }
1244
+
1245
+ New-EachTestSetup - ScriptBlock { $container.EachTestSetup ++ }
1246
+ New-EachTestTeardown - ScriptBlock { $container.EachTestTeardown ++ }
1247
+
1248
+ New-Test ' test1' - Skip {
1249
+ $container.TestRun ++
1250
+ ' a'
1251
+ }
1243
1252
1244
- # $actual = Invoke-Test -SessionState $ExecutionContext.SessionState -BlockContainer (New-BlockContainerObject -ScriptBlock {
1245
- # New-Block "parent block" {
1246
- # New-Block "parent block" {
1247
- # # putting this in child block because each test setup is not supported in root block
1248
- # New-OneTimeTestSetup -ScriptBlock { $container.OneTimeTestSetup++ }
1249
- # New-OneTimeTestTeardown -ScriptBlock { $container.OneTimeTestTeardown++ }
1250
-
1251
- # New-EachTestSetup -ScriptBlock { $container.EachTestSetup++ }
1252
- # New-EachTestTeardown -ScriptBlock { $container.EachTestTeardown++ }
1253
-
1254
- # New-Test "test1" -Skip {
1255
- # $container.TestRun++
1256
- # "a"
1257
- # }
1258
-
1259
- # New-Test "test2" -Skip {
1260
- # $container.TestRun++
1261
- # "a"
1262
- # }
1263
- # }
1264
- # }
1265
- # })
1266
-
1267
- # # $actual.Blocks[0].Skip | Verify-True
1268
- # $actual.Blocks[0].ErrorRecord.Count | Verify-Equal 0
1269
- # $container.TestRun | Verify-Equal 0
1270
- # $container.OneTimeTestSetup | Verify-Equal 0
1271
- # $container.OneTimeTestTeardown | Verify-Equal 0
1272
- # $container.EachTestSetup | Verify-Equal 0
1273
- # $container.EachTestTeardown | Verify-Equal 0
1253
+ New-Block ' inner block' - Skip {
1254
+ New-Test ' test2' {
1255
+ $container.TestRun ++
1256
+ ' a'
1257
+ }
1258
+ }
1259
+ }
1260
+ })
1261
+
1262
+ # Should be marked as Skip by runtime
1263
+ $actual.Blocks [0 ].Skip | Verify- True
1264
+ $actual.Blocks [0 ].ErrorRecord.Count | Verify- Equal 0
1265
+
1266
+ $container.TestRun | Verify- Equal 0
1267
+ $container.OneTimeTestSetup | Verify- Equal 0
1268
+ $container.OneTimeTestTeardown | Verify- Equal 0
1269
+ $container.EachTestSetup | Verify- Equal 0
1270
+ $container.EachTestTeardown | Verify- Equal 0
1274
1271
}
1275
1272
}
1276
1273
@@ -1341,6 +1338,52 @@ i -PassThru:$PassThru {
1341
1338
$container.EachBlockTeardown1 | Verify- Equal 1
1342
1339
# $container.OneTimeBlockTeardown1 | Verify-Equal 1
1343
1340
}
1341
+
1342
+ t ' setup and teardown are executed on skipped parent blocks when a test is explicitly included' {
1343
+ $container = @ {
1344
+ OneTimeTestSetup = 0
1345
+ OneTimeTestTeardown = 0
1346
+ EachTestSetup = 0
1347
+ EachTestTeardown = 0
1348
+ TestRun = 0
1349
+ }
1350
+
1351
+ $sb = {
1352
+ New-OneTimeTestSetup - ScriptBlock { $container.OneTimeTestSetup ++ }
1353
+ New-OneTimeTestTeardown - ScriptBlock { $container.OneTimeTestTeardown ++ }
1354
+
1355
+ New-Block ' parent block' - Skip {
1356
+ New-OneTimeTestSetup - ScriptBlock { $container.OneTimeTestSetup ++ }
1357
+ New-OneTimeTestTeardown - ScriptBlock { $container.OneTimeTestTeardown ++ }
1358
+
1359
+ New-EachTestSetup - ScriptBlock { $container.EachTestSetup ++ }
1360
+ New-EachTestTeardown - ScriptBlock { $container.EachTestTeardown ++ }
1361
+
1362
+ New-Test ' test1' - Skip { # <--- Linefilter here ($sb assignment + 11 lines). Should run
1363
+ $container.TestRun ++
1364
+ ' a'
1365
+ }
1366
+
1367
+ New-Test ' test2' - Skip { # Should not run
1368
+ $container.TestRun ++
1369
+ ' a'
1370
+ }
1371
+ }
1372
+ }
1373
+
1374
+ $f = New-FilterObject - Line " $ ( $sb.File ) :$ ( $sb.StartPosition.StartLine + 11 ) "
1375
+ $actual = Invoke-Test - SessionState $ExecutionContext.SessionState - BlockContainer (New-BlockContainerObject - ScriptBlock $sb ) - Filter $f
1376
+
1377
+ # Should be marked as Skip = false by runtime
1378
+ $actual.Blocks [0 ].Skip | Verify- False
1379
+ $actual.Blocks [0 ].ErrorRecord.Count | Verify- Equal 0
1380
+
1381
+ $container.TestRun | Verify- Equal 1
1382
+ $container.OneTimeTestSetup | Verify- Equal 2
1383
+ $container.OneTimeTestTeardown | Verify- Equal 2
1384
+ $container.EachTestSetup | Verify- Equal 1
1385
+ $container.EachTestTeardown | Verify- Equal 1
1386
+ }
1344
1387
}
1345
1388
1346
1389
b " plugins" {
0 commit comments