Browse Source

FindRuby: Add dedicated tests

Issue: #20370
Julien Marrec 5 years ago
parent
commit
b00d736a0b

+ 4 - 0
Tests/CMakeLists.txt

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

+ 44 - 0
Tests/FindRuby/CMakeLists.txt

@@ -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()

+ 5 - 0
Tests/FindRuby/Fail/CMakeLists.txt

@@ -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)

+ 8 - 0
Tests/FindRuby/FailExact/CMakeLists.txt

@@ -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()

+ 14 - 0
Tests/FindRuby/Test/CMakeLists.txt

@@ -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)

+ 7 - 0
Tests/FindRuby/Test/ruby_version.c

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