Debian Codegraph @

vendored-meson/meson/test cases/common/60 foreach/meson.build

raw
1 project('foreach', 'c')
2
3 tests = [['test1', 'prog1', 'prog1.c'],
4 ['test2', 'prog2', 'prog2.c', 'fallback'],
5 ['test3', 'prog3', 'prog3.c', 'urgh']]
6
7 assert(tests[0].get(3, 'fallbck') == 'fallbck', 'array #1 fallback did not match')
8 assert(tests[1].get(3, 'failbk') == 'fallback', 'array #2 value did not match')
9 assert(tests[2].get(3, 'urgh') == 'urgh', 'array #3 value did not match')
10
11 foreach i : tests
12 test(i.get(0), executable(i.get(1), i.get(2), install : true))
13
14 # Ensure that changing the tests variable does not
15 # affect ongoing iteration in the foreach loop.
16 #
17 # Being able to do that would make Meson Turing complete and
18 # we definitely don't want that.
19 tests = ['test4', 'prog4', 'prog4.c']
20 endforeach
21
22 items = ['a', 'continue', 'b', 'break', 'c']
23 result = []
24 foreach i : items
25 if i == 'continue'
26 continue
27 elif i == 'break'
28 break
29 endif
30 result += i
31 endforeach
32
33 assert(result == ['a', 'b'], 'Continue or break in foreach failed')
34
35 items = []
36 iter = range(2)
37 foreach i : iter
38 items += i
39 endforeach
40 assert(items == [0, 1])
41 assert(iter[1] == 1)
42
43 items = []
44 foreach i : range(1, 2)
45 items += i
46 endforeach
47 assert(items == [1])
48
49 items = []
50 foreach i : range(1, 10, 2)
51 items += i
52 endforeach
53 assert(items == [1, 3, 5, 7, 9])