@@ -1668,6 +1668,12 @@ i -PassThru:$PassThru {
1668
1668
}
1669
1669
}
1670
1670
}
1671
+
1672
+ t " Does not accept unbound scriptblocks" {
1673
+ # Would execute in Pester's internal module state
1674
+ $ex = { New-PesterContainer - ScriptBlock ([ScriptBlock ]::Create(' $true' )) } | Verify- Throw
1675
+ $ex.Exception.Message | Verify- Like ' Unbound scriptblock*'
1676
+ }
1671
1677
}
1672
1678
1673
1679
b " BeforeDiscovery" {
@@ -1691,6 +1697,15 @@ i -PassThru:$PassThru {
1691
1697
$r.Containers [0 ].Blocks[0 ].Tests[0 ].Result | Verify- Equal " Passed"
1692
1698
$r.Containers [0 ].Blocks[1 ].Tests[0 ].Result | Verify- Equal " Passed"
1693
1699
}
1700
+
1701
+ t " Does not accept unbound scriptblocks" {
1702
+ # Would execute in Pester's internal module state
1703
+ $sb = { BeforeDiscovery ([ScriptBlock ]::Create(' $true' )) }
1704
+ $container = New-PesterContainer - ScriptBlock $sb
1705
+ $r = Invoke-Pester - Container $container - PassThru
1706
+ $r.Containers [0 ].Result | Verify- Equal ' Failed'
1707
+ $r.Containers [0 ].ErrorRecord.Exception.Message | Verify- Like ' Unbound scriptblock*'
1708
+ }
1694
1709
}
1695
1710
1696
1711
b " Parametric tests" {
@@ -2922,4 +2937,33 @@ i -PassThru:$PassThru {
2922
2937
$pwd.Path | Verify- Equal $beforePWD
2923
2938
}
2924
2939
}
2940
+
2941
+ b ' Unbound scriptblocks' {
2942
+ # Would execute in Pester's internal module state
2943
+ t ' Throws when provided to Run.ScriptBlock' {
2944
+ $sb = [scriptblock ]::Create(' ' )
2945
+ $conf = New-PesterConfiguration
2946
+ $conf.Run.ScriptBlock = $sb
2947
+ $conf.Run.Throw = $true
2948
+ $conf.Output.CIFormat = ' None'
2949
+
2950
+ $ex = { Invoke-Pester - Configuration $conf } | Verify- Throw
2951
+ $ex.Exception.Message | Verify- Like ' *Unbound scriptblock*'
2952
+ }
2953
+
2954
+ t ' Throws when provided to Run.Container' {
2955
+ $c = [Pester.ContainerInfo ]::Create()
2956
+ $c.Type = ' ScriptBlock'
2957
+ $c.Item = [scriptblock ]::Create(' ' )
2958
+ $c.Data = @ {}
2959
+
2960
+ $conf = New-PesterConfiguration
2961
+ $conf.Run.Container = $c
2962
+ $conf.Run.Throw = $true
2963
+ $conf.Output.CIFormat = ' None'
2964
+
2965
+ $ex = { Invoke-Pester - Configuration $conf } | Verify- Throw
2966
+ $ex.Exception.Message | Verify- Like ' *Unbound scriptblock*'
2967
+ }
2968
+ }
2925
2969
}
0 commit comments