File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ describe ValidateScriptBlock {
2+ it ' Can validates a ScriptBlock' {
3+ & ({
4+ [ValidateScriptBlock (DataLanguage)]
5+ $DataScriptBlock = { 1 }
6+
7+ & $DataScriptBlock
8+ }.Transpile()) | Should - be 1
9+ }
10+
11+ it ' Can ensure a ScriptBlock has no blocks' {
12+ & ({
13+ [ValidateScriptBlock (NoBlocks)]$Sb = { 1 }
14+
15+ & $sb
16+ }.Transpile()) | Should - be 1
17+
18+ {
19+ & ({
20+ [ValidateScriptBlock (NoBlocks)]$Sb = { process { 1 } }
21+
22+ & $sb
23+ }.Transpile())
24+ } | Should - Throw
25+ }
26+
27+ it ' Can ensure a ScriptBlock may only -IncludeCommand' {
28+ {
29+ & ({
30+ [ValidateScriptBlock (IncludeCommand= ' *-Process' )]$Sb = { Get-Command }
31+
32+ & $sb
33+ }.Transpile())
34+ } | Should - Throw
35+ }
36+
37+ it ' Can ensure a ScriptBlock has -NoLoop' {
38+ {
39+ & ({
40+ [ValidateScriptBlock (NoLoop)]$Sb = { foreach ($n in 1 .. 100 ) {$n } }
41+
42+ & $sb
43+ }.Transpile())
44+ } | Should - Throw
45+ }
46+
47+ it ' Can ensure a ScriptBlock has -NoWhileLoop' {
48+ {
49+ & ({
50+ [ValidateScriptBlock (NoLoop)]$Sb = { while (1 ) {$n } }
51+
52+ & $sb
53+ }.Transpile())
54+ } | Should - Throw
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments