From 23e6720605c9572eb59fbe4175f28c639ce36335 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 30 Sep 2012 03:28:47 +0200 Subject: [PATCH] Build druntime/Phobos unit tests on make test. --- CMakeLists.txt | 20 +++++++++----------- runtime/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++ runtime/emptymain.d | 2 ++ 3 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 runtime/emptymain.d diff --git a/CMakeLists.txt b/CMakeLists.txt index 58ead6e0..df1a21b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -319,12 +319,19 @@ set_target_properties(${LDMD_EXE} PROPERTIES # GNU ld. target_link_libraries(${LDMD_EXE} "${LLVM_LDFLAGS}" ${LLVM_LIBRARIES} "${LLVM_LDFLAGS}") +# +# Test and runtime targets. Note that enable_testing() is order-sensitive! +# +enable_testing() +add_subdirectory(runtime) +if(D_VERSION EQUAL 2) + add_subdirectory(tests/d2) +endif() + # # Install target. # -add_subdirectory(runtime) - install(TARGETS ${LDC_EXE} ${LDMD_EXE} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) if(${BUILD_SHARED}) # For now, only install libldc if explicitely building the shared library. @@ -338,12 +345,3 @@ install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}_install.rebuild.conf DESTINAT if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") install(DIRECTORY bash_completion.d DESTINATION ${CONF_INST_DIR}) endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - - -# -# Test targets. -# -enable_testing() -if(D_VERSION EQUAL 2) - add_subdirectory(tests/d2) -endif() diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index ed60599c..bd595f94 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -398,3 +398,37 @@ if(PHOBOS2_DIR) endif(PHOBOS2_DIR) install(FILES ${RUNTIME_DIR}/src/object.di DESTINATION ${INCLUDE_INSTALL_DIR}/ldc) install(DIRECTORY ${RUNTIME_DIR}/import/ldc DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.di") + + +# +# Test targets. +# +function(add_tests module_files) + foreach(file ${module_files}) + string(REPLACE ${PROJECT_SOURCE_DIR}/ "" stripped ${file}) + string(REPLACE ".d" "" stripped ${stripped}) + string(REPLACE "/" "_" testroot ${stripped}) + + function(testcase name flags) + # -singleobj to avoid output file clashes when test are run in parallel. + add_test(NAME ${testroot}_${name}_build + COMMAND ${LDC_LOC} + -of${PROJECT_BINARY_DIR}/${testroot}_${name} + -unittest -d -w -singleobj ${flags} + ${file} ${PROJECT_SOURCE_DIR}/emptymain.d + ) + add_test(NAME ${testroot}_${name}_run COMMAND ${PROJECT_BINARY_DIR}/${testroot}_${name}) + set_tests_properties(${testroot}_${name}_run PROPERTIES DEPENDS ${testroot}_${name}_build) + endfunction() + + testcase(debug -g -debug) + testcase(release -O -release) + endforeach() +endfunction() + +add_tests("${CORE_D}") +add_tests("${DCRT_D}") +add_tests("${GC_D}") +if(PHOBOS2_DIR) + add_tests("${PHOBOS2_D}") +endif() diff --git a/runtime/emptymain.d b/runtime/emptymain.d new file mode 100644 index 00000000..3894697f --- /dev/null +++ b/runtime/emptymain.d @@ -0,0 +1,2 @@ +// Stub used for building runtime unit tests. +void main() {}