Skip to content

Commit

Permalink
feat: add string equality assertion functions (#12)
Browse files Browse the repository at this point in the history
* feat: add string equality assertion functions

* test: add test for testing string equality assertion functions
  • Loading branch information
threeal authored May 3, 2024
1 parent 64f31e8 commit 49ea225
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,25 @@ function(assert_not_defined VARIABLE)
message(FATAL_ERROR "expected variable '${VARIABLE}' not to be defined")
endif()
endfunction()

# Asserts whether the given strings are equal.
#
# Arguments:
# - STR1: The first string to assert.
# - STR2: The second string to assert.
function(assert_strequal STR1 STR2)
if(NOT "${STR1}" STREQUAL "${STR2}")
message(FATAL_ERROR "expected string '${STR1}' to be equal to '${STR2}'")
endif()
endfunction()

# Asserts whether the given strings are not equal.
#
# Arguments:
# - STR1: The first string to assert.
# - STR2: The second string to assert.
function(assert_not_strequal STR1 STR2)
if("${STR1}" STREQUAL "${STR2}")
message(FATAL_ERROR "expected string '${STR1}' not to be equal to '${STR2}'")
endif()
endfunction()
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ add_cmake_test(
"Assert a false condition"
"Assert a defined variable"
"Assert an undefined variable"
"Assert equal strings"
"Assert unequal strings"
)
8 changes: 8 additions & 0 deletions test/cmake/AssertionTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ function(test_assert_an_undefined_variable)
assert_not_defined(SOME_VARIABLE)
endfunction()

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

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

if(NOT DEFINED TEST_COMMAND)
message(FATAL_ERROR "The 'TEST_COMMAND' variable should be defined")
elseif(NOT COMMAND test_${TEST_COMMAND})
Expand Down

0 comments on commit 49ea225

Please sign in to comment.