Skip to content

Commit

Permalink
test: modify test_assert_call.cmake to test capture multiple errors
Browse files Browse the repository at this point in the history
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
  • Loading branch information
threeal committed Oct 21, 2024
1 parent dad3cea commit e76f145
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions test/test_assert_call.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,57 @@ cmake_minimum_required(VERSION 3.24)

include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake)

section("it should assert error messages")
assert_call(message FATAL_ERROR "an error message"
EXPECT_ERROR "an e...r message")
function(throw_errors)
message(SEND_ERROR "a send error message")
message(FATAL_ERROR "a fatal error message")
endfunction()

assert_call(message SEND_ERROR "an error message"
EXPECT_ERROR "an e...r message")
section("it should assert error messages")
assert_call(throw_errors EXPECT_ERROR
"a se.*or message\n"
"a fa.*or message")

assert_call(
CALL message FATAL_ERROR "an error message"
EXPECT_ERROR "an e...r message")
assert_call(CALL throw_errors EXPECT_ERROR
"a se.*or message\n"
"a fa.*or message")

assert_call(message FATAL_ERROR "an error message"
EXPECT_ERROR MATCHES "an e...r message")
assert_call(throw_errors EXPECT_ERROR MATCHES
"a se.*or message\n"
"a fa.*or message")

assert_call(message FATAL_ERROR "an error message"
EXPECT_ERROR STREQUAL "an error message")
assert_call(throw_errors EXPECT_ERROR STREQUAL
"a send error message\n"
"a fatal error message")
endsection()

section("it should fail to assert error messages")
macro(failed_assertion)
assert_call(message FATAL_ERROR "an error message"
EXPECT_ERROR "an..... e...r message")
endmacro()

assert_call(failed_assertion
EXPECT_ERROR STREQUAL "expected error message:\n an error message\n"
"to match:\n an..... e...r message")

macro(failed_assertion)
assert_call(message SEND_ERROR "an error message"
EXPECT_ERROR MATCHES "an..... e...r message")
macro(assert_failures)
assert_call(throw_errors EXPECT_ERROR
"another se.*or message\n"
"another fa.*or message")
endmacro()

assert_call(failed_assertion
EXPECT_ERROR STREQUAL "expected error message:\n an error message\n"
"to match:\n an..... e...r message")
assert_call(assert_failures EXPECT_ERROR STREQUAL
"expected error message:\n"
" a send error message\n"
" a fatal error message\n"
"to match:\n"
" another se.*or message\n"
" another fa.*or message")

macro(failed_assertion)
assert_call(message FATAL_ERROR "an error message"
EXPECT_ERROR STREQUAL "another error message")
macro(assert_failures)
assert_call(throw_errors EXPECT_ERROR
"another send error message\n"
"another fatal error message")
endmacro()

assert_call(failed_assertion
EXPECT_ERROR STREQUAL "expected error message:\n an error message\n"
"to be equal to:\n another error message")
assert_call(assert_failures EXPECT_ERROR STREQUAL
"expected error message:\n"
" a send error message\n"
" a fatal error message\n"
"to match:\n"
" another send error message\n"
" another fatal error message")
endsection()

section("it should fail to assert error messages "
Expand All @@ -55,6 +61,6 @@ section("it should fail to assert error messages "
assert_call(message "a message" EXPECT_ERROR "a message")
endmacro()

assert_call(failed_assertion
EXPECT_ERROR "expected to receive an error message")
assert_call(failed_assertion EXPECT_ERROR
"expected to receive an error message")
endsection()

0 comments on commit e76f145

Please sign in to comment.