diff options
Diffstat (limited to 'Tests/CMakeTests')
-rw-r--r-- | Tests/CMakeTests/StringTest.cmake.in | 4 | ||||
-rw-r--r-- | Tests/CMakeTests/StringTestScript.cmake | 11 | ||||
-rw-r--r-- | Tests/CMakeTests/VersionTest.cmake.in | 88 |
3 files changed, 91 insertions, 12 deletions
diff --git a/Tests/CMakeTests/StringTest.cmake.in b/Tests/CMakeTests/StringTest.cmake.in index a9fe428..92e70c3 100644 --- a/Tests/CMakeTests/StringTest.cmake.in +++ b/Tests/CMakeTests/StringTest.cmake.in @@ -63,7 +63,7 @@ check_cmake_test(String # Execute each test listed in StringTestScript.cmake: # set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/StringTestScript.cmake") -set(number_of_tests_expected 69) +set(number_of_tests_expected 70) include("@CMAKE_CURRENT_SOURCE_DIR@/ExecuteScriptTests.cmake") execute_all_script_tests(${scriptname} number_of_tests_executed) @@ -75,6 +75,6 @@ message(STATUS "scriptname='${scriptname}'") message(STATUS "number_of_tests_executed='${number_of_tests_executed}'") message(STATUS "number_of_tests_expected='${number_of_tests_expected}'") -if(number_of_tests_executed LESS number_of_tests_expected) +if(NOT number_of_tests_executed EQUAL number_of_tests_expected) message(FATAL_ERROR "error: some test cases were skipped") endif() diff --git a/Tests/CMakeTests/StringTestScript.cmake b/Tests/CMakeTests/StringTestScript.cmake index a562e71..44d5653 100644 --- a/Tests/CMakeTests/StringTestScript.cmake +++ b/Tests/CMakeTests/StringTestScript.cmake @@ -122,14 +122,17 @@ elseif(testname STREQUAL substring_not_enough_args) # fail elseif(testname STREQUAL substring_begin_too_large) # fail string(SUBSTRING "abcdefg" 25 100 v) -elseif(testname STREQUAL substring_end_too_large) # fail +elseif(testname STREQUAL substring_end_larger_than_strlen) # pass string(SUBSTRING "abcdefg" 1 100 v) elseif(testname STREQUAL substring_begin_less_than_zero) # fail - string(SUBSTRING "abcdefg" -2 4 v) + string(SUBSTRING "abcdefg" -1 4 v) -elseif(testname STREQUAL substring_end_less_than_begin) # fail - string(SUBSTRING "abcdefg" 6 3 v) +elseif(testname STREQUAL substring_end_less_than_zero) # pass + string(SUBSTRING "abcdefg" 0 -1 v) + +elseif(testname STREQUAL substring_end_less_than_begin) # pass + string(SUBSTRING "abcdefg" 6 0 v) elseif(testname STREQUAL length_not_enough_args) # fail string(LENGTH) diff --git a/Tests/CMakeTests/VersionTest.cmake.in b/Tests/CMakeTests/VersionTest.cmake.in index 9e31cb4..4e946ab 100644 --- a/Tests/CMakeTests/VersionTest.cmake.in +++ b/Tests/CMakeTests/VersionTest.cmake.in @@ -8,9 +8,85 @@ else() message("CMAKE_VERSION=[${CMAKE_VERSION}] is not less than [${min_ver}]") endif() -set(v 1.2.3.4.5.6.7) -if("${v}.8" VERSION_LESS "${v}.9") - message(STATUS "${v}.8 is less than ${v}.9") -else() - message(FATAL_ERROR "${v}.8 is not less than ${v}.9?") -endif() +set(EQUALV "1 1") +list(APPEND EQUALV "1.0 1") +list(APPEND EQUALV "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0 1") +list(APPEND EQUALV "1.2.3.4.5.6.7 1.2.3.4.5.6.7") +list(APPEND EQUALV "1.2.3.4.5.6.7.8.9 1.2.3.4.5.6.7.8.9") + +foreach(v IN LISTS EQUALV) + string(REGEX MATCH "(.*) (.*)" _dummy "${v}") + # modify any of the operands to see the negative check also works + if("${CMAKE_MATCH_1}.2" VERSION_EQUAL CMAKE_MATCH_2) + message(FATAL_ERROR "${CMAKE_MATCH_1}.2 is equal ${CMAKE_MATCH_2}?") + else() + message(STATUS "${CMAKE_MATCH_1}.2 is not equal ${CMAKE_MATCH_2}") + endif() + + if(CMAKE_MATCH_1 VERSION_EQUAL "${CMAKE_MATCH_2}.2") + message(FATAL_ERROR "${CMAKE_MATCH_1} is equal ${CMAKE_MATCH_2}.2?") + else() + message(STATUS "${CMAKE_MATCH_1} is not equal ${CMAKE_MATCH_2}.2") + endif() +endforeach() + +# test the negative outcomes first, due to the implementation the positive +# allow some additional strings to pass that would not fail for the negative +# tests + +list(APPEND EQUALV "1a 1") +list(APPEND EQUALV "1.1a 1.1") +list(APPEND EQUALV "1.0a 1") +list(APPEND EQUALV "1a 1.0") + +foreach(v IN LISTS EQUALV) + # check equal versions + string(REGEX MATCH "(.*) (.*)" _dummy "${v}") + if(CMAKE_MATCH_1 VERSION_EQUAL CMAKE_MATCH_2) + message(STATUS "${CMAKE_MATCH_1} is equal ${CMAKE_MATCH_2}") + else() + message(FATAL_ERROR "${CMAKE_MATCH_1} is not equal ${CMAKE_MATCH_2}?") + endif() + + # still equal, but inverted order of operands + string(REGEX MATCH "(.*) (.*)" _dummy "${v}") + if(CMAKE_MATCH_2 VERSION_EQUAL CMAKE_MATCH_1) + message(STATUS "${CMAKE_MATCH_2} is equal ${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "${CMAKE_MATCH_2} is not equal ${CMAKE_MATCH_1}?") + endif() +endforeach() + +set(LESSV "1.2.3.4.5.6.7.8 1.2.3.4.5.6.7.9") +list(APPEND LESSV "1.2.3.4.5.6.7 1.2.3.4.5.6.7.9") +list(APPEND LESSV "1 1.0.0.1") +foreach(v IN LISTS LESSV) + string(REGEX MATCH "(.*) (.*)" _dummy "${v}") + # check less + if(CMAKE_MATCH_1 VERSION_LESS CMAKE_MATCH_2) + message(STATUS "${CMAKE_MATCH_1} is less than ${CMAKE_MATCH_2}") + else() + message(FATAL_ERROR "${CMAKE_MATCH_1} is not less than ${CMAKE_MATCH_2}?") + endif() + + # check greater + if(CMAKE_MATCH_2 VERSION_GREATER CMAKE_MATCH_1) + message(STATUS "${CMAKE_MATCH_2} is greater than ${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "${CMAKE_MATCH_2} is not greater than ${CMAKE_MATCH_1}?") + endif() + + # check less negative case + if(NOT CMAKE_MATCH_2 VERSION_LESS CMAKE_MATCH_1) + message(STATUS "${CMAKE_MATCH_2} is not less than ${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "${CMAKE_MATCH_2} is less than ${CMAKE_MATCH_1}?") + endif() + + # check greater negative case + if(NOT CMAKE_MATCH_1 VERSION_GREATER CMAKE_MATCH_2) + message(STATUS "${CMAKE_MATCH_1} is not greater than ${CMAKE_MATCH_2}") + else() + message(FATAL_ERROR "${CMAKE_MATCH_1} is greater than ${CMAKE_MATCH_2}?") + endif() +endforeach() |