From 1151c65a618ba2534f9b32d7a4478117449b1245 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 23 May 2024 00:10:18 +0700 Subject: [PATCH] feat: handle regular expression match assertions if given var --- cmake/Assertion.cmake | 3 +++ test/cmake/AssertionTest.cmake | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) 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..83271a3 100644 --- a/test/cmake/AssertionTest.cmake +++ b/test/cmake/AssertionTest.cmake @@ -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")