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