diff options
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/FindRuby/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Tests/FindRuby/Rvm/CMakeLists.txt | 75 | ||||
-rw-r--r-- | Tests/FindRuby/Rvm/RvmDefault.cmake | 17 | ||||
-rw-r--r-- | Tests/FindRuby/Rvm/RvmOnly.cmake | 41 | ||||
-rw-r--r-- | Tests/FindRuby/Rvm/RvmStandard.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/GenerateExportHeader/exportheader_test.cpp | 6 |
6 files changed, 159 insertions, 4 deletions
diff --git a/Tests/FindRuby/CMakeLists.txt b/Tests/FindRuby/CMakeLists.txt index 193cb4f..3f4807c 100644 --- a/Tests/FindRuby/CMakeLists.txt +++ b/Tests/FindRuby/CMakeLists.txt @@ -24,7 +24,7 @@ if(CMake_TEST_FindRuby) --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) set_tests_properties(FindRuby.Fail PROPERTIES - PASS_REGULAR_EXPRESSION "Could NOT find Ruby: Found unsuitable version \".*\", but required is.*least \"[0-9]+\\.[0-9]+\\.[0-9]+\" \\(found .*\\)") + PASS_REGULAR_EXPRESSION "Could NOT find Ruby.*(Required is at least version \"[0-9]+\\.[0-9]+\\.[0-9]+\")") # Looks for 1.9.9 EXACTLY, which unlike the "FindRuby" test above will fail on every machine # since this version doesn't exist (ruby goes from 1.9.3 to 2.0.0) @@ -41,4 +41,17 @@ if(CMake_TEST_FindRuby) set_tests_properties(FindRuby.FailExact PROPERTIES PASS_REGULAR_EXPRESSION "Could NOT find Ruby: Found unsuitable version \".*\", but required is.*exact version \"[0-9]+\\.[0-9]+\\.[0-9]+\" \\(found .*\\)") + # RVM specific test + if(CMake_TEST_FindRuby_RVM) + add_test(NAME FindRuby.Rvm COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindRuby/Rvm" + "${CMake_BINARY_DIR}/Tests/FindRuby/Rvm" + ${build_generator_args} + --build-project TestRVM + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + endif() endif() diff --git a/Tests/FindRuby/Rvm/CMakeLists.txt b/Tests/FindRuby/Rvm/CMakeLists.txt new file mode 100644 index 0000000..545fc94 --- /dev/null +++ b/Tests/FindRuby/Rvm/CMakeLists.txt @@ -0,0 +1,75 @@ +cmake_minimum_required(VERSION 3.17) +project(TestRVM LANGUAGES NONE) + +include(CTest) + +# To run this test, you need to have at least one RVM ruby installed +# and to ensure that the env variable 'MY_RUBY_HOME' is set to a valid RVM ruby when you run the test +# (which is the case if you have done `rvm use x.y.z`, but could be manually set too) + +# Properly using rvm would require sourcing a shell script, eg `source "$HOME/.rvm/scripts/rvm"` +# Instead, I'll just rely on the env variable MY_RUBY_HOME +set(MY_RUBY_HOME "$ENV{MY_RUBY_HOME}") +if(NOT MY_RUBY_HOME) + message(FATAL_ERROR "Env variable MY_RUBY_HOME should be set to a valid RVM ruby location, or you should call `rvm use x.y.z` before") +endif() +execute_process (COMMAND "${MY_RUBY_HOME}/bin/ruby" -e "puts RUBY_VERSION" + RESULT_VARIABLE result + OUTPUT_VARIABLE RVM_RUBY_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + +if (result) + message (FATAL_ERROR "Unable to detect RVM ruby version from `${MY_RUBY_HOME}/bin/ruby`: ${RVM_RUBY_VERSION}") +endif() + +execute_process(COMMAND "${CMAKE_COMMAND}" -E env --unset=MY_RUBY_HOME --unset=PATH + "which" "ruby" + RESULT_VARIABLE result + OUTPUT_VARIABLE SYSTEM_RUBY + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + +if (SYSTEM_RUBY MATCHES "^${MY_RUBY_HOME}/.+") + message(FATAL_ERROR "Unable to find system ruby, found ${SYSTEM_RUBY} which is part of MY_RUBY_HOME=${MY_RUBY_HOME}") +endif() + +# Check version of the system ruby executable. +execute_process (COMMAND "${SYSTEM_RUBY}" -e "puts RUBY_VERSION" + RESULT_VARIABLE result + OUTPUT_VARIABLE SYSTEM_RUBY_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + +if (result) + message (FATAL_ERROR "Unable to detect system ruby version from '${SYSTEM_RUBY}': ${SYSTEM_RUBY_VERSION}") +endif() + +if(SYSTEM_RUBY_VERSION VERSION_EQUAL RVM_RUBY_VERSION) + message(FATAL_ERROR "Your RVM Ruby Version and your System ruby version are the same (${RVM_RUBY_VERSION}).") +endif() + +message("Found System Ruby (${SYSTEM_RUBY_VERSION}): ${SYSTEM_RUBY}") +message("Found RVM Ruby (${RVM_RUBY_VERSION}): ${MY_RUBY_HOME}/bin/ruby") + +add_test(NAME FindRuby.RvmDefault + COMMAND "${CMAKE_COMMAND}" -E env "MY_RUBY_HOME=${MY_RUBY_HOME}" + "${CMAKE_COMMAND}" "-DRUBY_HOME=${MY_RUBY_HOME}" + -P "${CMAKE_CURRENT_LIST_DIR}/RvmDefault.cmake") + +add_test(NAME FindRuby.RvmOnly + COMMAND "${CMAKE_COMMAND}" -E env --unset=PATH + "MY_RUBY_HOME=${MY_RUBY_HOME}" + "${CMAKE_COMMAND}" "-DRUBY_HOME=${MY_RUBY_HOME}" + "-DRVM_RUBY_VERSION=${RVM_RUBY_VERSION}" "-DSYSTEM_RUBY_VERSION=${SYSTEM_RUBY_VERSION}" + -P "${CMAKE_CURRENT_LIST_DIR}/RvmOnly.cmake") +add_test(NAME FindRuby.UnsetRvmOnly + COMMAND "${CMAKE_COMMAND}" -E env --unset=MY_RUBY_HOME "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" + "${CMAKE_COMMAND}" "-DRVM_RUBY_VERSION=${RVM_RUBY_VERSION}" "-DSYSTEM_RUBY_VERSION=${SYSTEM_RUBY_VERSION}" + -P "${CMAKE_CURRENT_LIST_DIR}/RvmOnly.cmake") + +add_test(NAME FindRuby.RvmStandard + COMMAND "${CMAKE_COMMAND}" -E env "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" + "MY_RUBY_HOME=${MY_RUBY_HOME}" + "${CMAKE_COMMAND}" "-DRUBY_HOME=${MY_RUBY_HOME}" + -P "${CMAKE_CURRENT_LIST_DIR}/RvmStandard.cmake") diff --git a/Tests/FindRuby/Rvm/RvmDefault.cmake b/Tests/FindRuby/Rvm/RvmDefault.cmake new file mode 100644 index 0000000..a66b911 --- /dev/null +++ b/Tests/FindRuby/Rvm/RvmDefault.cmake @@ -0,0 +1,17 @@ +set(CMAKE_FIND_LIBRARY_PREFIXES "") +set(CMAKE_FIND_LIBRARY_SUFFIXES "") + +find_package (Ruby 2.1.1 REQUIRED) +if (NOT RUBY_EXECUTABLE MATCHES "^${RUBY_HOME}/.+") + message (FATAL_ERROR "Failed to use RVM environment: ${RUBY_EXECUTABLE}, ${RUBY_HOME}") +endif() + +find_package (Ruby 2.1 REQUIRED) +if (NOT RUBY_EXECUTABLE MATCHES "^${RUBY_HOME}/.+") + message (FATAL_ERROR "Failed to use RVM environment: ${RUBY_EXECUTABLE}, ${RUBY_HOME}") +endif() + +find_package (Ruby REQUIRED) +if (NOT RUBY_EXECUTABLE MATCHES "^${RUBY_HOME}/.+") + message (FATAL_ERROR "Failed to use RVM environment: ${RUBY_EXECUTABLE}, ${RUBY_HOME}") +endif() diff --git a/Tests/FindRuby/Rvm/RvmOnly.cmake b/Tests/FindRuby/Rvm/RvmOnly.cmake new file mode 100644 index 0000000..3851a7c --- /dev/null +++ b/Tests/FindRuby/Rvm/RvmOnly.cmake @@ -0,0 +1,41 @@ +set(CMAKE_FIND_LIBRARY_PREFIXES "") +set(CMAKE_FIND_LIBRARY_SUFFIXES "") + +set(Ruby_FIND_VIRTUALENV ONLY) + +# Test: FindRuby.RvmOnly +if (RUBY_HOME) + # => Trying to find exactly system ruby using ONLY virtual environment should fail + find_package (Ruby ${SYSTEM_RUBY_VERSION} EXACT QUIET) + if(Ruby_FOUND) + message (FATAL_ERROR "Ruby unexpectedly found.") + endif() + # And should work to find the rvm version + find_package (Ruby ${RVM_RUBY_VERSION} EXACT QUIET) + if(Ruby_FOUND) + message (FATAL_ERROR "Ruby unexpectedly found.") + endif() +endif() + + +# Test: FindRuby.UnsetRvmOnly +if (NOT RUBY_HOME) + + # If ENV{MY_RUBY_HOME} isn't defined, it should default back to "STANDARD" + # At which point: + + # It shouldn't find the RVM ruby + find_package (Ruby ${RVM_RUBY_VERSION} EXACT QUIET) + if(Ruby_FOUND) + message(FATAL_ERROR "Found RVM ruby when expecting system") + endif() + + # it should find the system ruby + find_package (Ruby ${SYSTEM_RUBY_VERSION} EXACT QUIET) + if(NOT Ruby_FOUND) + message (FATAL_ERROR "Ruby not found.") + endif() + if (Ruby_FOUND MATCHES "^${RUBY_HOME}/.+") + message(FATAL_ERROR "Failed to find system ruby") + endif() +endif() diff --git a/Tests/FindRuby/Rvm/RvmStandard.cmake b/Tests/FindRuby/Rvm/RvmStandard.cmake new file mode 100644 index 0000000..26befdb7 --- /dev/null +++ b/Tests/FindRuby/Rvm/RvmStandard.cmake @@ -0,0 +1,9 @@ +set(CMAKE_FIND_LIBRARY_PREFIXES "") +set(CMAKE_FIND_LIBRARY_SUFFIXES "") + +set (Ruby_FIND_VIRTUALENV STANDARD) +find_package (Ruby REQUIRED) + +if (RUBY_EXECUTABLE MATCHES "^${RUBY_HOME}/.+") + message (FATAL_ERROR "RVM ruby unexpectedly found at ${RUBY_EXECUTABLE}, matches ${RUBY_HOME}") +endif() diff --git a/Tests/RunCMake/GenerateExportHeader/exportheader_test.cpp b/Tests/RunCMake/GenerateExportHeader/exportheader_test.cpp index ba77679..dcaa4f2 100644 --- a/Tests/RunCMake/GenerateExportHeader/exportheader_test.cpp +++ b/Tests/RunCMake/GenerateExportHeader/exportheader_test.cpp @@ -32,14 +32,14 @@ void compare(const char* refName, const char* testName) // trailing null to the string that we need to strip before testing for a // trailing space. if (refLine.size() && refLine[refLine.size() - 1] == 0) { - refLine = refLine.substr(0, refLine.size() - 1); + refLine.resize(refLine.size() - 1); } if (testLine.size() && testLine[testLine.size() - 1] == 0) { - testLine = testLine.substr(0, testLine.size() - 1); + testLine.resize(testLine.size() - 1); } // The reference files never have trailing spaces: if (testLine.size() && testLine[testLine.size() - 1] == ' ') { - testLine = testLine.substr(0, testLine.size() - 1); + testLine.resize(testLine.size() - 1); } if (refLine != testLine) { std::cout << "Ref and test are not the same:\n Ref: \"" << refLine |