Skip to content

Commit ecab3dc

Browse files
committed
feat: modify fail function to auto insert :
1 parent 7f93a85 commit ecab3dc

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

cmake/Assertion.cmake

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ macro(fail FIRST_LINE)
3838
foreach(LINE IN ITEMS ${ARGN})
3939
if(DEFINED "${LINE}")
4040
string(REPLACE "\n" "\n " LINE "${${LINE}}")
41-
string(APPEND MESSAGE "\n ${LINE}")
41+
string(APPEND MESSAGE ":\n ${LINE}")
4242
else()
4343
string(APPEND MESSAGE "\n${LINE}")
4444
endif()
@@ -64,98 +64,98 @@ function(assert)
6464
if(ARGC EQUAL 2)
6565
if(NOT ARGV0 STREQUAL NOT)
6666
if(ARGV0 STREQUAL DEFINED)
67-
fail("expected variable:" ARGV1 "to be defined")
67+
fail("expected variable" ARGV1 "to be defined")
6868
elseif(ARGV0 STREQUAL EXISTS)
69-
fail("expected path:" ARGV1 "to exist")
69+
fail("expected path" ARGV1 "to exist")
7070
elseif(ARGV0 STREQUAL IS_DIRECTORY)
71-
fail("expected path:" ARGV1 "to be a directory")
71+
fail("expected path" ARGV1 "to be a directory")
7272
else()
7373
set(ARGS "${ARGV0} ${ARGV1}")
74-
fail("expected:" ARGS "to resolve to true")
74+
fail("expected" ARGS "to resolve to true")
7575
endif()
7676
else()
7777
set(ARGS "${ARGV0} ${ARGV1}")
78-
fail("expected:" ARGS "to resolve to true")
78+
fail("expected" ARGS "to resolve to true")
7979
endif()
8080
elseif(ARGC EQUAL 3)
8181
if(ARGV0 STREQUAL NOT)
8282
if(ARGV1 STREQUAL DEFINED)
83-
fail("expected variable:" ARGV2 "not to be defined")
83+
fail("expected variable" ARGV2 "not to be defined")
8484
elseif(ARGV1 STREQUAL EXISTS)
85-
fail("expected path:" ARGV2 "not to exist")
85+
fail("expected path" ARGV2 "not to exist")
8686
elseif(ARGV1 STREQUAL IS_DIRECTORY)
87-
fail("expected path:" ARGV2 "not to be a directory")
87+
fail("expected path" ARGV2 "not to be a directory")
8888
else()
8989
set(ARGS "${ARGV0} ${ARGV1} ${ARGV2}")
90-
fail("expected:" ARGS "to resolve to true")
90+
fail("expected" ARGS "to resolve to true")
9191
endif()
9292
else()
9393
if(ARGV1 STREQUAL MATCHES)
9494
if(DEFINED "${ARGV0}")
95-
fail("expected string:" "${ARGV0}" "of variable:" ARGV0
96-
"to match:" ARGV2)
95+
fail("expected string" "${ARGV0}" "of variable" ARGV0
96+
"to match" ARGV2)
9797
else()
98-
fail("expected string:" ARGV0 "to match:" ARGV2)
98+
fail("expected string" ARGV0 "to match" ARGV2)
9999
endif()
100100
elseif(ARGV1 STREQUAL STREQUAL)
101101
if(DEFINED "${ARGV0}")
102102
if(DEFINED "${ARGV2}")
103-
fail("expected string:" "${ARGV0}" "of variable:" ARGV0
104-
"to be equal to string:" "${ARGV2}" "of variable:" ARGV2)
103+
fail("expected string" "${ARGV0}" "of variable" ARGV0
104+
"to be equal to string" "${ARGV2}" "of variable" ARGV2)
105105
else()
106-
fail("expected string:" "${ARGV0}" "of variable:" ARGV0
107-
"to be equal to:" ARGV2)
106+
fail("expected string" "${ARGV0}" "of variable" ARGV0
107+
"to be equal to" ARGV2)
108108
endif()
109109
else()
110110
if(DEFINED "${ARGV2}")
111-
fail("expected string:" ARGV0
112-
"to be equal to string:" "${ARGV2}" "of variable:" ARGV2)
111+
fail("expected string" ARGV0
112+
"to be equal to string" "${ARGV2}" "of variable" ARGV2)
113113
else()
114-
fail("expected string:" ARGV0 "to be equal to:" ARGV2)
114+
fail("expected string" ARGV0 "to be equal to" ARGV2)
115115
endif()
116116
endif()
117117
else()
118118
set(ARGS "${ARGV0} ${ARGV1} ${ARGV2}")
119-
fail("expected:" ARGS "to resolve to true")
119+
fail("expected" ARGS "to resolve to true")
120120
endif()
121121
endif()
122122
elseif(ARGC EQUAL 4)
123123
if(ARGV0 STREQUAL NOT)
124124
if(ARGV2 STREQUAL MATCHES)
125125
if(DEFINED "${ARGV1}")
126-
fail("expected string:" "${ARGV1}" "of variable:" ARGV1
127-
"not to match:" ARGV3)
126+
fail("expected string" "${ARGV1}" "of variable" ARGV1
127+
"not to match" ARGV3)
128128
else()
129-
fail("expected string:" ARGV1 "not to match:" ARGV3)
129+
fail("expected string" ARGV1 "not to match" ARGV3)
130130
endif()
131131
elseif(ARGV2 STREQUAL STREQUAL)
132132
if(DEFINED "${ARGV1}")
133133
if(DEFINED "${ARGV3}")
134-
fail("expected string:" "${ARGV1}" "of variable:" ARGV1
135-
"not to be equal to string:" "${ARGV3}" "of variable:" ARGV3)
134+
fail("expected string" "${ARGV1}" "of variable" ARGV1
135+
"not to be equal to string" "${ARGV3}" "of variable" ARGV3)
136136
else()
137-
fail("expected string:" "${ARGV1}" "of variable:" ARGV1
138-
"not to be equal to:" ARGV3)
137+
fail("expected string" "${ARGV1}" "of variable" ARGV1
138+
"not to be equal to" ARGV3)
139139
endif()
140140
else()
141141
if(DEFINED "${ARGV3}")
142-
fail("expected string:" ARGV1
143-
"not to be equal to string:" "${ARGV3}" "of variable:" ARGV3)
142+
fail("expected string" ARGV1
143+
"not to be equal to string" "${ARGV3}" "of variable" ARGV3)
144144
else()
145-
fail("expected string:" ARGV1 "not to be equal to:" ARGV3)
145+
fail("expected string" ARGV1 "not to be equal to" ARGV3)
146146
endif()
147147
endif()
148148
else()
149149
set(ARGS "${ARGV0} ${ARGV1} ${ARGV2} ${ARGV3}")
150-
fail("expected:" ARGS "to resolve to true")
150+
fail("expected" ARGS "to resolve to true")
151151
endif()
152152
else()
153153
set(ARGS "${ARGV0} ${ARGV1} ${ARGV2} ${ARGV3}")
154-
fail("expected:" ARGS "to resolve to true")
154+
fail("expected" ARGS "to resolve to true")
155155
endif()
156156
else()
157157
string(REPLACE ";" " " ARGS "${ARG_UNPARSED_ARGUMENTS}")
158-
fail("expected:" ARGS "to resolve to true")
158+
fail("expected" ARGS "to resolve to true")
159159
endif()
160160
endif()
161161
endfunction()
@@ -221,16 +221,16 @@ function(assert_fatal_error)
221221
math(EXPR CAPTURE_LEVEL "${CAPTURE_LEVEL} - 1")
222222
set_property(GLOBAL PROPERTY fatal_error_capture_level "${CAPTURE_LEVEL}")
223223

224-
fail("expected to receive a fatal error message that matches:"
224+
fail("expected to receive a fatal error message that matches"
225225
EXPECTED_MESSAGE)
226226
return()
227227
endif()
228228

229229
# Assert the captured fatal error message with the expected message.
230230
get_property(ACTUAL_MESSAGE GLOBAL PROPERTY captured_fatal_error)
231231
if(NOT "${ACTUAL_MESSAGE}" MATCHES "${EXPECTED_MESSAGE}")
232-
fail("expected fatal error message:" ACTUAL_MESSAGE
233-
"to match:" EXPECTED_MESSAGE)
232+
fail("expected fatal error message" ACTUAL_MESSAGE
233+
"to match" EXPECTED_MESSAGE)
234234
endif()
235235
endfunction()
236236

@@ -271,18 +271,18 @@ function(assert_execute_process)
271271

272272
if(DEFINED ARG_ERROR AND RES EQUAL 0)
273273
string(REPLACE ";" " " COMMAND "${ARG_COMMAND}")
274-
fail("expected command:" COMMAND "to fail")
274+
fail("expected command" COMMAND "to fail")
275275
elseif(NOT DEFINED ARG_ERROR AND NOT RES EQUAL 0)
276276
string(REPLACE ";" " " COMMAND "${ARG_COMMAND}")
277-
fail("expected command:" COMMAND "not to fail with error:" ERR)
277+
fail("expected command" COMMAND "not to fail with error" ERR)
278278
elseif(DEFINED EXPECTED_OUTPUT AND NOT "${OUT}" MATCHES "${EXPECTED_OUTPUT}")
279279
string(REPLACE ";" " " COMMAND "${ARG_COMMAND}")
280-
fail("expected the output:" OUT "of command:" COMMAND
281-
"to match:" EXPECTED_OUTPUT)
280+
fail("expected the output" OUT "of command" COMMAND
281+
"to match" EXPECTED_OUTPUT)
282282
elseif(DEFINED EXPECTED_ERROR AND NOT "${ERR}" MATCHES "${EXPECTED_ERROR}")
283283
string(REPLACE ";" " " COMMAND "${ARG_COMMAND}")
284-
fail("expected the error:" ERR "of command:" COMMAND
285-
"to match:" EXPECTED_ERROR)
284+
fail("expected the error" ERR "of command" COMMAND
285+
"to match" EXPECTED_ERROR)
286286
endif()
287287
endfunction()
288288

test/Fail.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@ section("it should fail with a formatted fatal error message "
1818
set(REASON_MULTILINE "some reason\non multiple lines")
1919

2020
assert_fatal_error(
21-
CALL fail "something happened:" REASON
21+
CALL fail "something happened" REASON
2222
MESSAGE "something happened:\n some reason")
2323

2424
assert_fatal_error(
25-
CALL fail "something happened:" REASON_MULTILINE
25+
CALL fail "something happened" REASON_MULTILINE
2626
MESSAGE "something happened:\n some reason\n on multiple lines")
2727

2828
assert_fatal_error(
29-
CALL fail "something happened\non multiple lines:" REASON
29+
CALL fail "something happened\non multiple lines" REASON
3030
MESSAGE "something happened\non multiple lines:\n some reason")
3131

3232
assert_fatal_error(
33-
CALL fail "something happened\non multiple lines:" REASON_MULTILINE
33+
CALL fail "something happened\non multiple lines" REASON_MULTILINE
3434
MESSAGE "something happened\non multiple lines:\n"
3535
" some reason\n on multiple lines")
3636

3737
assert_fatal_error(
38-
CALL fail "something happened" "on multiple lines:" REASON
38+
CALL fail "something happened" "on multiple lines" REASON
3939
MESSAGE "something happened\non multiple lines:\n some reason")
4040

4141
assert_fatal_error(
4242
CALL fail
43-
"something happened" "on multiple lines:" REASON
44-
"something else happened:" REASON_MULTILINE
43+
"something happened" "on multiple lines" REASON
44+
"something else happened" REASON_MULTILINE
4545
MESSAGE "something happened\non multiple lines:\n some reason\n"
4646
"something else happened:\n some reason\n on multiple lines")
4747
endsection()

0 commit comments

Comments
 (0)