From cdac01abe2bff167a82f749c8bf7a2d2bcd69498 Mon Sep 17 00:00:00 2001 From: Mathias Preiner Date: Fri, 24 Aug 2018 15:11:03 -0700 Subject: [PATCH] cmake: Compile Java tests and add to ctest if Java bindings are enabled. --- CMakeLists.txt | 4 +++- cmake/FindHamcrest.cmake | 13 +++++++++++++ cmake/FindJUnit.cmake | 26 ++++++++++++++++++++++++++ test/java/CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 cmake/FindHamcrest.cmake create mode 100644 cmake/FindJUnit.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 81bbaf533..81e9a0e30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -519,7 +519,9 @@ add_subdirectory(src) if(BUILD_BINDINGS) add_subdirectory(src/bindings) endif() -add_subdirectory(test/java) +if(BUILD_BINDINGS_JAVA) + add_subdirectory(test/java) +endif() add_subdirectory(test/regress) add_subdirectory(test/system) if(ENABLE_UNIT_TESTING) diff --git a/cmake/FindHamcrest.cmake b/cmake/FindHamcrest.cmake new file mode 100644 index 000000000..96fde96ba --- /dev/null +++ b/cmake/FindHamcrest.cmake @@ -0,0 +1,13 @@ +# Find Hamcrest +# Hamcrest_FOUND - system has Hamcrest lib +# Hamcrest_JAR - the Hamcrest jar file + +find_package(Java REQUIRED) +include(UseJava) + +find_jar(Hamcrest_JAR hamcrest-core) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Hamcrest DEFAULT_MSG Hamcrest_JAR) + +mark_as_advanced(Hamcrest_JAR) diff --git a/cmake/FindJUnit.cmake b/cmake/FindJUnit.cmake new file mode 100644 index 000000000..1fd4ebb2d --- /dev/null +++ b/cmake/FindJUnit.cmake @@ -0,0 +1,26 @@ +# Find JUnit +# JUnit_FOUND - system has JUnit lib +# JUnit_JAR - JUnit jar file +# JUnit_JAR_DEPS - JUnit jar dependencies + +find_package(Java REQUIRED) +include(UseJava) +find_package(Hamcrest REQUIRED) + +find_jar(JUnit_JAR NAMES junit junit4) + +if(JUnit_JAR) + set(JUnit_JAR_DEPS ${Hamcrest_JAR}) + # Determine version of JUnit + execute_process( + COMMAND ${Java_JAVA_EXECUTABLE} -cp ${JUnit_JAR} junit.runner.Version + OUTPUT_VARIABLE JUnit_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(JUnit + REQUIRED_VARS JUnit_JAR JUnit_JAR_DEPS + VERSION_VAR JUnit_VERSION) + +mark_as_advanced(JUnit_JAR JUnit_JAR_DEPS) diff --git a/test/java/CMakeLists.txt b/test/java/CMakeLists.txt index e69de29bb..0139c5672 100644 --- a/test/java/CMakeLists.txt +++ b/test/java/CMakeLists.txt @@ -0,0 +1,38 @@ +find_package(Java REQUIRED) +find_package(JUnit REQUIRED) +include(UseJava) + +set(java_test_src_files + BitVectors.java + BitVectorsAndArrays.java + Combination.java + HelloWorld.java + LinearArith.java +) + +add_jar(cvc4javatests + SOURCES ${java_test_src_files} + INCLUDE_JARS + ${CMAKE_BINARY_DIR}/src/bindings/java/CVC4.jar + ${JUnit_JAR} +) +add_dependencies(cvc4javatests cvc4jar) + +# Add java tests to ctest +set(classpath "${CMAKE_CURRENT_BINARY_DIR}/cvc4javatests.jar") +set(classpath "${classpath}:${CMAKE_BINARY_DIR}/src/bindings/java/CVC4.jar") +set(classpath "${classpath}:${JUnit_JAR}:${JUnit_JAR_DEPS}") + +foreach(src_file ${java_test_src_files}) + string(REPLACE ".java" "" name ${src_file}) + add_test( + NAME ${name} + COMMAND + java + -Djava.library.path=${CMAKE_BINARY_DIR}/src/bindings/java/ + -cp ${classpath} + org.junit.runner.JUnitCore + ${name} + ) + set_tests_properties(${name} PROPERTIES LABELS "java") +endforeach() -- 2.30.2