Skip to content

Commit

Permalink
feat: handle regular expression match assertions if given var
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed May 22, 2024
1 parent ca23855 commit 1151c65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
3 changes: 3 additions & 0 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ function(assert)
list(GET ARGUMENTS 2 RIGHT_VALUE)

if(OPERATOR STREQUAL MATCHES)
if(DEFINED "${LEFT_VALUE}")
set(LEFT_VALUE "${${LEFT_VALUE}}")
endif()
set(MESSAGE "expected string '${LEFT_VALUE}'${NOT_WORD} to match '${RIGHT_VALUE}'")
elseif(OPERATOR STREQUAL STREQUAL)
set(MESSAGE "expected string '${LEFT_VALUE}'${NOT_WORD} to be equal to '${RIGHT_VALUE}'")
Expand Down
28 changes: 16 additions & 12 deletions test/cmake/AssertionTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,22 @@ function("Directory path assertions")
endfunction()

function("Regular expression match assertions")
assert("some string" MATCHES "so.*ing")
assert(NOT "some string" MATCHES "so.*other.*ing")

mock_message()
assert("some string" MATCHES "so.*other.*ing")
end_mock_message()
assert_message(FATAL_ERROR "expected string 'some string' to match 'so.*other.*ing'")

mock_message()
assert(NOT "some string" MATCHES "so.*ing")
end_mock_message()
assert_message(FATAL_ERROR "expected string 'some string' not to match 'so.*ing'")
set(STRING_VAR "some string")

foreach(VALUE STRING_VAR "${STRING_VAR}")
assert("${VALUE}" MATCHES "so.*ing")
assert(NOT "${VALUE}" MATCHES "so.*other.*ing")

mock_message()
assert(NOT "${VALUE}" MATCHES "so.*ing")
end_mock_message()
assert_message(FATAL_ERROR "expected string 'some string' not to match 'so.*ing'")

mock_message()
assert("${VALUE}" MATCHES "so.*other.*ing")
end_mock_message()
assert_message(FATAL_ERROR "expected string 'some string' to match 'so.*other.*ing'")
endforeach()
endfunction()

function("String equality assertions")
Expand Down

0 comments on commit 1151c65

Please sign in to comment.