diff --git a/cmake/Assertion.cmake b/cmake/Assertion.cmake index 54484b2..ce92d8e 100644 --- a/cmake/Assertion.cmake +++ b/cmake/Assertion.cmake @@ -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}'") diff --git a/test/cmake/AssertionTest.cmake b/test/cmake/AssertionTest.cmake index f9b8e2e..39a0b3e 100644 --- a/test/cmake/AssertionTest.cmake +++ b/test/cmake/AssertionTest.cmake @@ -72,16 +72,31 @@ function("Directory path assertions") endfunction() function("Regular expression match assertions") - assert("some string" MATCHES "so.*ing") - assert(NOT "some string" MATCHES "so.*other.*ing") + set(STRING_VAR "some string") + + assert(STRING_VAR MATCHES "so.*ing") + assert("${STRING_VAR}" MATCHES "so.*ing") + + assert(NOT STRING_VAR MATCHES "so.*other.*ing") + assert(NOT "${STRING_VAR}" MATCHES "so.*other.*ing") + + mock_message() + assert(STRING_VAR MATCHES "so.*other.*ing") + end_mock_message() + assert_message(FATAL_ERROR "expected string 'some string' to match 'so.*other.*ing'") mock_message() - assert("some string" MATCHES "so.*other.*ing") + assert("${STRING_VAR}" 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") + assert(NOT STRING_VAR MATCHES "so.*ing") + end_mock_message() + assert_message(FATAL_ERROR "expected string 'some string' not to match 'so.*ing'") + + mock_message() + assert(NOT ${STRING_VAR} MATCHES "so.*ing") end_mock_message() assert_message(FATAL_ERROR "expected string 'some string' not to match 'so.*ing'") endfunction()