FindRuby: Add dedicated tests

Issue: #20370
This commit is contained in:
Julien Marrec 2020-02-21 16:46:24 +01:00 committed by Brad King
parent ffa08d256f
commit b00d736a0b
6 changed files with 82 additions and 0 deletions

View File

@ -1478,6 +1478,10 @@ ${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGH
add_subdirectory(UseSWIG) add_subdirectory(UseSWIG)
endif() endif()
if(CMake_TEST_FindRuby)
add_subdirectory(FindRuby)
endif()
add_subdirectory(FindThreads) add_subdirectory(FindThreads)
# Matlab module # Matlab module

View File

@ -0,0 +1,44 @@
if(CMake_TEST_FindRuby)
# Looks for ruby >=1.9.9, which is true on any Ubuntu (that installs it) or macOS (> 10.9)
add_test(NAME FindRuby.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindRuby/Test"
"${CMake_BINARY_DIR}/Tests/FindRuby/Test"
${build_generator_args}
--build-project TestRuby
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
# Looks for ruby >= 50.1.0, which should logically fail
add_test(NAME FindRuby.Fail COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindRuby/Fail"
"${CMake_BINARY_DIR}/Tests/FindRuby/Fail"
${build_generator_args}
--build-project TestRubyFail
--build-options ${build_options}
--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 .*\\)")
# 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)
add_test(NAME FindRuby.FailExact COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindRuby/FailExact"
"${CMake_BINARY_DIR}/Tests/FindRuby/FailExact"
${build_generator_args}
--build-project TestRubyFailExact
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
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 .*\\)")
endif()

View File

@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.17)
project(TestRubyFail LANGUAGES NONE)
# Should always fail since there is NO ruby 50.1.0 yet.
find_package(Ruby 50.1.0 REQUIRED)

View File

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.17)
project(TestRubyFailExact LANGUAGES NONE)
# Should always fail since there is NO ruby 1.9.9 (goes from 1.9.3 to 2.0.0)
find_package(Ruby 1.9.9 EXACT REQUIRED)
if (NOT Ruby_FOUND)
message (FATAL_ERROR "Failed to find Ruby 1.9.9")
endif()

View File

@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.17)
project(TestRuby LANGUAGES C)
include(CTest)
find_package(Ruby 1.9.9 REQUIRED)
if (NOT Ruby_FOUND)
message (FATAL_ERROR "Failed to find Ruby >=1.9.9")
endif()
add_executable(ruby_version ruby_version.c)
target_include_directories(ruby_version PRIVATE ${Ruby_INCLUDE_DIRS})
target_link_libraries(ruby_version PRIVATE ${Ruby_LIBRARY})
add_test(NAME ruby_version COMMAND ruby_version)

View File

@ -0,0 +1,7 @@
#include "ruby.h"
int main(void)
{
ruby_show_version();
return 0;
}