Add unittesting macro

This commit is contained in:
Jens K. Mueller 2010-10-03 01:32:53 +02:00
parent 71fc5e54e2
commit 79f451031b
6 changed files with 61 additions and 0 deletions

View file

@ -22,6 +22,7 @@ SET (MOD_SRCS
UseDDoc.cmake UseDDoc.cmake
UseDDeps.cmake UseDDeps.cmake
dependencies.cmake dependencies.cmake
UseDUnittest.cmake
) )
SET (PLAT_SRCS SET (PLAT_SRCS

37
cmaked/UseDUnittest.cmake Normal file
View file

@ -0,0 +1,37 @@
# Adding D unittests
#
# Copyright (c) 2010 Jens Mueller <jens.k.mueller@gmx.de>
#
# All rights reserved.
#
# See Copyright.txt for details.
#
macro(add_unittests _sourcefile)
set(_testname "${_sourcefile}")
set(main_unittest "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/unittest.d")
set(_source_file "${CMAKE_CURRENT_SOURCE_DIR}/${_sourcefile}")
#message("main_unittest ${main_unittest}")
#message("testname ${_testname}")
#message("_sourcefile ${_source_file}")
if(NOT EXISTS ${main_unittest})
file(WRITE ${main_unittest} "// Generated by UseDUnittest.cmake\nint main() { return 0; }")
endif()
# TODO
# better way to get the included directories
get_directory_property(include_dirs INCLUDE_DIRECTORIES)
set(INCLUDES )
foreach(include_dir IN LISTS include_dirs)
list(APPEND INCLUDES "${CMAKE_INCLUDE_FLAG_D}${include_dir}")
endforeach()
separate_arguments(CMAKE_D_FLAGS)
add_test(NAME ${_testname}
COMMAND ${CMAKE_D_COMPILER} ${CMAKE_D_FLAGS} ${INCLUDES} ${main_unittest} -unittest -run ${_source_file})
endmacro(add_unittests)

View file

@ -30,3 +30,4 @@ ADD_SUBDIRECTORY (app_4)
ADD_SUBDIRECTORY (app_6) ADD_SUBDIRECTORY (app_6)
ADD_SUBDIRECTORY (app_7) ADD_SUBDIRECTORY (app_7)
ADD_SUBDIRECTORY (app_8) ADD_SUBDIRECTORY (app_8)
ADD_SUBDIRECTORY (app_9)

View file

@ -0,0 +1,14 @@
include(UseDUnittest)
# TODO
# how to rerun cmake if a new file is created
# I don't want to miss new unittests
# add all files
file(GLOB files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.d")
foreach(file IN LISTS files)
add_unittests(${file})
endforeach()
#add_unittests(moduleA.d)
#add_unittests(moduleB.d)

4
tests/app_9/moduleA.d Normal file
View file

@ -0,0 +1,4 @@
unittest {
assert(true);
//assert(false);
}

4
tests/app_9/moduleB.d Normal file
View file

@ -0,0 +1,4 @@
unittest {
assert(true);
//assert(false);
}