Skip to content

Commit

Permalink
test: update testing to cover failed assertion (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal authored May 5, 2024
1 parent b697491 commit d672110
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions test/cmake/AssertionTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,63 @@ include(Assertion)

function(test_assert_a_true_condition)
assert_true(TRUE)

mock_message(ON)
assert_false(TRUE)

mock_message(OFF)
assert_message(FATAL_ERROR "expected the condition to be false")
endfunction()

function(test_assert_a_false_condition)
assert_false(FALSE)

mock_message(ON)
assert_true(FALSE)

mock_message(OFF)
assert_message(FATAL_ERROR "expected the condition to be true")
endfunction()

function(test_assert_a_defined_variable)
set(SOME_VARIABLE "some value")
assert_defined(SOME_VARIABLE)

mock_message(ON)
assert_not_defined(SOME_VARIABLE)

mock_message(OFF)
assert_message(FATAL_ERROR "expected variable 'SOME_VARIABLE' not to be defined")
endfunction()

function(test_assert_an_undefined_variable)
assert_not_defined(SOME_VARIABLE)

mock_message(ON)
assert_defined(SOME_VARIABLE)

mock_message(OFF)
assert_message(FATAL_ERROR "expected variable 'SOME_VARIABLE' to be defined")
endfunction()

function(test_assert_equal_strings)
assert_strequal("some string" "some string")

mock_message(ON)
assert_not_strequal("some string" "some string")

mock_message(OFF)
assert_message(FATAL_ERROR "expected string 'some string' not to be equal to 'some string'")
endfunction()

function(test_assert_unequal_strings)
assert_not_strequal("some string" "some other string")

mock_message(ON)
assert_strequal("some string" "some other string")

mock_message(OFF)
assert_message(FATAL_ERROR "expected string 'some string' to be equal to 'some other string'")
endfunction()

function(call_sample_messages)
Expand All @@ -38,8 +74,8 @@ endfunction()
function(test_mock_message)
mock_message(ON)
call_sample_messages()
mock_message(OFF)

mock_message(OFF)
assert_defined(WARNING_MESSAGES)
assert_strequal("${WARNING_MESSAGES}" "some warning message;some other warning message")

Expand All @@ -53,12 +89,18 @@ endfunction()
function(test_assert_messages)
mock_message(ON)
call_sample_messages()
mock_message(OFF)

mock_message(OFF)
assert_message(WARNING "some warning message")
assert_message(WARNING "some other warning message")
assert_message(ERROR "some error message")
assert_message(FATAL_ERROR "some fatal error message")

mock_message(ON)
assert_message(ERROR "some other error message")

mock_message(OFF)
assert_message(FATAL_ERROR "expected error message '' to be equal to 'some other error message'")
endfunction()

if(NOT DEFINED TEST_COMMAND)
Expand Down

0 comments on commit d672110

Please sign in to comment.