Skip to content

Commit 5dee69b

Browse files
committed
PS: Add loop CFG tests.
1 parent f00f55f commit 5dee69b

File tree

2 files changed

+213
-8
lines changed

2 files changed

+213
-8
lines changed

powershell/ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 157 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ functions.ps1:
2828
#-----| -> number1
2929

3030
# 3| param(...)
31-
#-----| -> ...|...
31+
#-----| -> ...+...
3232

3333
# 3| {...}
3434
#-----| -> exit {...} (normal)
@@ -48,7 +48,7 @@ functions.ps1:
4848
# 8| ...+...
4949
#-----| -> {...}
5050

51-
# 8| ...|...
51+
# 8| ...+...
5252
#-----| -> ...+...
5353

5454
# 8| number2
@@ -92,7 +92,7 @@ functions.ps1:
9292
#-----| -> name0
9393

9494
# 14| param(...)
95-
#-----| -> ...|...
95+
#-----| -> ...+...
9696

9797
# 14| {...}
9898
#-----| -> exit {...} (normal)
@@ -127,7 +127,7 @@ functions.ps1:
127127
# 19| ...+...
128128
#-----| -> {...}
129129

130-
# 19| ...|...
130+
# 19| ...+...
131131
#-----| -> ...+...
132132

133133
# 19| name2
@@ -196,7 +196,7 @@ functions.ps1:
196196

197197
# 44| {...}
198198
#-----| -> sum
199-
#-----| -> ...|...
199+
#-----| -> sum
200200

201201
# 46| sum
202202
#-----| -> _
@@ -213,15 +213,15 @@ functions.ps1:
213213
# 48| {...}
214214
#-----| -> exit {...} (normal)
215215

216-
# 50| ...|...
217-
#-----| -> sum
218-
219216
# 50| sum
220217
#-----| -> sum
221218

222219
# 50| sum
223220
#-----| -> {...}
224221

222+
# 50| sum
223+
#-----| -> sum
224+
225225
global.ps1:
226226
# 1| {...}
227227
#-----| -> c
@@ -281,3 +281,152 @@ global.ps1:
281281

282282
# 6| b
283283
#-----| -> ...+...
284+
285+
loops.ps1:
286+
# 1| Test-While
287+
#-----| -> Test-Break
288+
289+
# 1| enter loops.ps1
290+
#-----| -> loops.ps1
291+
292+
# 1| exit loops.ps1
293+
294+
# 1| exit loops.ps1 (normal)
295+
#-----| -> exit loops.ps1
296+
297+
# 1| loops.ps1
298+
#-----| -> Test-While
299+
300+
# 1| {...}
301+
#-----| -> exit loops.ps1 (normal)
302+
303+
# 1| enter {...}
304+
#-----| -> {...}
305+
306+
# 1| {...}
307+
#-----| -> a
308+
309+
# 2| a
310+
#-----| -> 0
311+
312+
# 2| ...=...
313+
314+
# 2| 0
315+
#-----| -> ...=...
316+
317+
# 2| 0
318+
#-----| -> 0
319+
320+
# 9| Test-Break
321+
#-----| -> Test-Continue
322+
323+
# 9| enter {...}
324+
#-----| -> {...}
325+
326+
# 9| {...}
327+
#-----| -> a
328+
329+
# 10| a
330+
#-----| -> 0
331+
332+
# 10| ...=...
333+
334+
# 10| 0
335+
#-----| -> ...=...
336+
337+
# 10| 0
338+
#-----| -> 0
339+
340+
# 17| Test-Continue
341+
#-----| -> Test-DoWhile
342+
343+
# 17| enter {...}
344+
#-----| -> {...}
345+
346+
# 17| {...}
347+
#-----| -> a
348+
349+
# 18| a
350+
#-----| -> 0
351+
352+
# 18| ...=...
353+
354+
# 18| 0
355+
#-----| -> ...=...
356+
357+
# 18| 0
358+
#-----| -> 0
359+
360+
# 25| Test-DoWhile
361+
#-----| -> Test-DoUntil
362+
363+
# 25| enter {...}
364+
#-----| -> {...}
365+
366+
# 25| {...}
367+
#-----| -> a
368+
369+
# 26| a
370+
#-----| -> 0
371+
372+
# 26| ...=...
373+
374+
# 26| 0
375+
#-----| -> ...=...
376+
377+
# 26| 0
378+
#-----| -> 0
379+
380+
# 33| Test-DoUntil
381+
#-----| -> Tet-For
382+
383+
# 33| enter {...}
384+
#-----| -> {...}
385+
386+
# 33| {...}
387+
#-----| -> a
388+
389+
# 34| a
390+
#-----| -> 0
391+
392+
# 34| ...=...
393+
394+
# 34| 0
395+
#-----| -> ...=...
396+
397+
# 34| 0
398+
#-----| -> 0
399+
400+
# 41| Tet-For
401+
#-----| -> Test-ForEach
402+
403+
# 41| enter {...}
404+
#-----| -> {...}
405+
406+
# 41| {...}
407+
#-----| -> a
408+
409+
# 42| a
410+
#-----| -> 0
411+
412+
# 42| ...=...
413+
414+
# 42| 0
415+
#-----| -> ...=...
416+
417+
# 42| 0
418+
#-----| -> 0
419+
420+
# 49| Test-ForEach
421+
#-----| -> {...}
422+
423+
# 49| enter {...}
424+
#-----| -> {...}
425+
426+
# 49| {...}
427+
#-----| -> letterArray
428+
429+
# 50| letterArray
430+
#-----| -> ...,...
431+
432+
# 50| ...,...
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
function Test-While {
2+
$a = 0
3+
4+
while($a -le 10) {
5+
$a = $a + 1
6+
}
7+
}
8+
9+
function Test-Break {
10+
$a = 0
11+
while($a -le 10) {
12+
break
13+
$a = $a + 1
14+
}
15+
}
16+
17+
function Test-Continue {
18+
$a = 0
19+
while($a -le 10) {
20+
continue
21+
$a = $a + 1
22+
}
23+
}
24+
25+
function Test-DoWhile {
26+
$a = 0
27+
28+
do {
29+
$a = $a + 1
30+
} while ($a -le 10)
31+
}
32+
33+
function Test-DoUntil {
34+
$a = 0
35+
36+
do {
37+
$a = $a + 1
38+
} until ($a -ge 10)
39+
}
40+
41+
function Tet-For {
42+
$a = 0
43+
44+
for ($i = 0; $i -le 10; $i = $i + 1) {
45+
$a = $a + 1
46+
}
47+
}
48+
49+
function Test-ForEach {
50+
$letterArray = 'a','b','c','d'
51+
$a = 0
52+
foreach ($letter in $letterArray)
53+
{
54+
$a = $a + 1
55+
}
56+
}

0 commit comments

Comments
 (0)