meson.build 972 B

12345678910111213141516171819202122232425262728293031323334
  1. project('foreach', 'c')
  2. tests = [['test1', 'prog1', 'prog1.c'],
  3. ['test2', 'prog2', 'prog2.c', 'fallback'],
  4. ['test3', 'prog3', 'prog3.c', 'urgh']]
  5. assert(tests[0].get(3, 'fallbck') == 'fallbck', 'array #1 fallback did not match')
  6. assert(tests[1].get(3, 'failbk') == 'fallback', 'array #2 value did not match')
  7. assert(tests[2].get(3, 'urgh') == 'urgh', 'array #3 value did not match')
  8. foreach i : tests
  9. test(i.get(0), executable(i.get(1), i.get(2), install : true))
  10. # Ensure that changing the tests variable does not
  11. # affect ongoing iteration in the foreach loop.
  12. #
  13. # Being able to do that would make Meson Turing complete and
  14. # we definitely don't want that.
  15. tests = ['test4', 'prog4', 'prog4.c']
  16. endforeach
  17. items = ['a', 'continue', 'b', 'break', 'c']
  18. result = []
  19. foreach i : items
  20. if i == 'continue'
  21. continue
  22. elif i == 'break'
  23. break
  24. endif
  25. result += i
  26. endforeach
  27. assert(result == ['a', 'b'], 'Continue or break in foreach failed')