ExitValues.cmake 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #1st TEST RESULT_VARIABLE ONLY
  2. execute_process(COMMAND ${EXIT_CODE_EXE} "zero_exit"
  3. RESULT_VARIABLE r0
  4. )
  5. message(STATUS " 1 - 1 RESULT_VARIABLE: ${r0}")
  6. if(NOT r0 EQUAL 0)
  7. message(FATAL_ERROR "zero exit code expected")
  8. endif()
  9. execute_process(COMMAND ${EXIT_CODE_EXE} "non_zero_exit"
  10. RESULT_VARIABLE r01
  11. ERROR_QUIET
  12. )
  13. message(STATUS " 1 - 2 RESULT_VARIABLE: ${r01}")
  14. if(r01 EQUAL 0)
  15. message(FATAL_ERROR "non-zero exit code expected")
  16. endif()
  17. #2nd TEST RESULT_VARIABLE and RESULTS_VARIABLE
  18. execute_process(COMMAND ${EXIT_CODE_EXE} "zero_exit"
  19. RESULT_VARIABLE r1
  20. RESULTS_VARIABLE r1s
  21. )
  22. message(STATUS " 2 - 1 RESULT_VARIABLE: ${r1}")
  23. message(STATUS " 2 - 1 RESULTS_VARIABLE: ${r1s}")
  24. if(NOT r1 EQUAL 0 OR NOT r1s EQUAL 0)
  25. message(FATAL_ERROR "zero exit code expected")
  26. endif()
  27. execute_process(COMMAND ${EXIT_CODE_EXE} "non_zero_exit"
  28. RESULT_VARIABLE r11
  29. RESULTS_VARIABLE r11s
  30. ERROR_QUIET
  31. )
  32. message(STATUS " 2 - 2 RESULT_VARIABLE: ${r11}")
  33. message(STATUS " 2 - 2 RESULTS_VARIABLE: ${r11s}")
  34. if(r11 EQUAL 0 OR r11s EQUAL 0)
  35. message(FATAL_ERROR "non-zero exit code expected")
  36. endif()
  37. #3rd TEST RESULTS_VARIABLE
  38. execute_process(COMMAND ${EXIT_CODE_EXE} "zero_exit"
  39. RESULTS_VARIABLE r2s
  40. )
  41. message(STATUS " 3 - 1 RESULTS_VARIABLE: ${r2s}")
  42. if(NOT r2s EQUAL 0)
  43. message(FATAL_ERROR "zero exit code expected")
  44. endif()
  45. execute_process(COMMAND ${EXIT_CODE_EXE} "non_zero_exit"
  46. RESULTS_VARIABLE r21s
  47. ERROR_QUIET
  48. )
  49. message(STATUS " 3 - 2 RESULTS_VARIABLE: ${r21s}")
  50. if(r21s EQUAL 0)
  51. message(FATAL_ERROR "non-zero exit code expected")
  52. endif()
  53. #4th TEST RESULT_VARIABLE and RESULTS_VARIABLE WITH MULTICOMMAND
  54. execute_process(COMMAND ${EXIT_CODE_EXE} "non_zero_exit"
  55. COMMAND ${EXIT_CODE_EXE} "zero_exit"
  56. COMMAND ${EXIT_CODE_EXE} "non_zero_exit"
  57. COMMAND ${EXIT_CODE_EXE} "zero_exit"
  58. COMMAND ${EXIT_CODE_EXE} "non_zero_exit"
  59. COMMAND ${EXIT_CODE_EXE} "zero_exit"
  60. RESULT_VARIABLE r31
  61. RESULTS_VARIABLE r31s
  62. OUTPUT_QUIET
  63. ERROR_QUIET
  64. )
  65. message(STATUS " 4 - 1 RESULT_VARIABLE: ${r31}")
  66. message(STATUS " 4 - 1 RESULTS_VARIABLE: ${r31s}")
  67. if(NOT r31 EQUAL 0)
  68. message(FATAL_ERROR "zero exit code expected for last command")
  69. endif()
  70. list(LENGTH r31s r31sLen)
  71. message(STATUS " 4 - 1 RESULTS_VARIABLE_LENGTH: ${r31sLen}")
  72. if(NOT r31sLen EQUAL 6)
  73. message(FATAL_ERROR "length of RESULTS_VARIABLE is not as expected")
  74. else()
  75. foreach(loop_var RANGE 5)
  76. list(GET r31s ${loop_var} rsLocal)
  77. math(EXPR isOdd "${loop_var} % 2")
  78. if(isOdd)
  79. if(NOT rsLocal EQUAL 0)
  80. message(FATAL_ERROR "zero exit code expected")
  81. endif()
  82. else()
  83. if(rsLocal EQUAL 0)
  84. message(FATAL_ERROR "non-zero exit code expected")
  85. endif()
  86. endif()
  87. endforeach()
  88. endif()
  89. #5th TEST RESULT_VARIABLE and RESULTS_VARIABLE WITH MULTICOMMAND
  90. execute_process(COMMAND ${EXIT_CODE_EXE} "zero_exit"
  91. COMMAND ${EXIT_CODE_EXE} "zero_exit"
  92. COMMAND ${EXIT_CODE_EXE} "non_zero_exit"
  93. RESULT_VARIABLE r41
  94. RESULTS_VARIABLE r41s
  95. OUTPUT_QUIET
  96. ERROR_QUIET
  97. )
  98. message(STATUS " 5 - 1 RESULT_VARIABLE: ${r41}")
  99. message(STATUS " 5 - 1 RESULTS_VARIABLE: ${r41s}")
  100. if(r41 EQUAL 0)
  101. message(FATAL_ERROR "non-zero exit code expected for last command")
  102. endif()
  103. list(LENGTH r41s r41sLen)
  104. message(STATUS " 5 - 1 RESULTS_VARIABLE_LENGTH: ${r41sLen}")
  105. if(NOT r31sLen EQUAL 6)
  106. message(FATAL_ERROR "length of RESULTS_VARIABLE is not as expected")
  107. else()
  108. list(GET r41s 0 rsLocal)
  109. if(NOT rsLocal EQUAL 0)
  110. message(FATAL_ERROR "zero exit code expected")
  111. endif()
  112. list(GET r41s 1 rsLocal)
  113. if(NOT rsLocal EQUAL 0)
  114. message(FATAL_ERROR "zero exit code expected")
  115. endif()
  116. list(GET r41s 2 rsLocal)
  117. if(rsLocal EQUAL 0)
  118. message(FATAL_ERROR "non-zero exit code expected")
  119. endif()
  120. endif()