2
# Find the CxxTest suite and declare a helper macro for creating unit tests
3
# and integrating them with CTest.
4
# For more details on CxxTest see http://cxxtest.tigris.org
9
# If true, the CXXTEST_ADD_TEST macro will use
10
# the Python test generator instead of Perl.
15
# True if the CxxTest framework was found
17
# Where to find the CxxTest include directory
18
# CXXTEST_PERL_TESTGEN_EXECUTABLE
19
# The perl-based test generator.
20
# CXXTEST_PYTHON_TESTGEN_EXECUTABLE
21
# The python-based test generator.
23
# MACROS for optional use by CMake users:
25
# CXXTEST_ADD_TEST(<test_name> <gen_source_file> <input_files_to_testgen...>)
26
# Creates a CxxTest runner and adds it to the CTest testing suite
28
# test_name The name of the test
29
# gen_source_file The generated source filename to be generated by CxxTest
30
# input_files_to_testgen The list of header files containing the
31
# CxxTest::TestSuite's to be included in this runner
36
# find_package(CxxTest)
38
# include_directories(${CXXTEST_INCLUDE_DIR})
41
# CXXTEST_ADD_TEST(unittest_foo foo_test.cc
42
# ${CMAKE_CURRENT_SOURCE_DIR}/foo_test.h other.cpp)
43
# target_link_libraries(unittest_foo foo) # as needed
46
# This will (if CxxTest is found):
47
# 1. Invoke the testgen executable to autogenerate foo_test.cc in the
48
# binary tree from "foo_test.h" in the current source directory.
49
# 2. Create an executable and test called unittest_foo.
50
# 3. Link additionally against other.cpp
55
# #include <cxxtest/TestSuite.h>
57
# class MyTestSuite : public CxxTest::TestSuite
60
# void testAddition( void )
62
# TS_ASSERT( 1 + 1 > 1 );
63
# TS_ASSERT_EQUALS( 1 + 1, 2 );
68
# Version 1.2 (3/2/08)
69
# Included patch from Tyler Roscoe to have the perl & python binaries
70
# detected based on CXXTEST_INCLUDE_DIR
71
# Version 1.1 (2/9/08)
72
# Clarified example to illustrate need to call target_link_libraries()
73
# Changed commands to lowercase
74
# Added licensing info
75
# Version 1.0 (1/8/08)
76
# Fixed CXXTEST_INCLUDE_DIRS so it will work properly
77
# Eliminated superfluous CXXTEST_FOUND assignment
78
# Cleaned up and added more documentation
81
# Copyright (c) 2008-2009
82
# Philip Lowman <philip@yhbt.com>
84
# Redistribution AND use is allowed according to the terms of the New
86
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
88
#=============================================================
89
# CXXTEST_ADD_TEST (public macro)
90
#=============================================================
91
macro( CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname _cxxtest_testsuite )
92
set(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_outfname})
93
if(CXXTEST_USE_PYTHON)
94
set(_cxxtest_executable ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE})
96
set(_cxxtest_executable ${CXXTEST_PERL_TESTGEN_EXECUTABLE})
100
OUTPUT ${_cxxtest_real_outfname}
101
DEPENDS ${_cxxtest_testsuite} ${ARGN}
102
COMMAND ${_cxxtest_executable}
103
--error-printer -o ${_cxxtest_real_outfname} ${_cxxtest_testsuite}
106
set_source_files_properties(${_cxxtest_real_outfname} PROPERTIES GENERATED true)
107
add_executable(${_cxxtest_testname} ${_cxxtest_real_outfname} ${ARGN})
109
if(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
110
add_test(${_cxxtest_testname} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_cxxtest_testname})
111
elseif(EXECUTABLE_OUTPUT_PATH)
112
add_test(${_cxxtest_testname} ${EXECUTABLE_OUTPUT_PATH}/${_cxxtest_testname})
114
add_test(${_cxxtest_testname} ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_testname})
117
endmacro(CXXTEST_ADD_TEST)
119
#=============================================================
120
# CXXTEST_ADD_TEST_FROM_LIST (public macro)
121
#=============================================================
124
# CXXTEST_ADD_TESTS_FROM_LIST( A, B, ... )
126
# 1. A is a list of cpp and/or h files where the class name is stripped of
127
# 2. then out of the class name the test targets and testsuite names are generated
128
# 3. finally they are linked with all libs present in parameter B
129
# 4. If there are more arguments (ARGN) then they are exclude from A before 1-3 starts)
131
FUNCTION( CXXTEST_ADD_TESTS_FROM_LIST _SourceList _TestLibs )
132
# remove unwanted tests
133
IF( ${ARGC} GREATER 2 )
134
FOREACH( fname ${ARGN} )
135
LIST( REMOVE_ITEM _SourceList ${CMAKE_CURRENT_SOURCE_DIR}/${fname} )
139
# extract class names from source files
140
FOREACH( _File ${_SourceList} )
141
STRING( REGEX REPLACE "^.*/" "" _StrippedPath "${_File}" )
142
STRING( REGEX REPLACE "\\..*$" "" _StrippedExtension "${_StrippedPath}" )
143
STRING( REGEX MATCH ".*\\.h" _IsHeader "${_File}" ) #Match Header Files
144
IF( NOT _IsHeader ) # Do not generate test for header files
145
LIST( APPEND _TestList ${_StrippedExtension} )
149
# generate for each class a unit test if there is a testsiute for it
150
FOREACH( _ClassName ${_TestList} )
151
SET( _TestName ${_ClassName}_test )
152
SET( _TestTarget unittest_${_ClassName} )
153
SET( _TestSuitePath "${CMAKE_CURRENT_SOURCE_DIR}/test/${_TestName}.h" )
155
# check if testsuite is present and generate code if true
156
IF( EXISTS ${_TestSuitePath} )
157
CXXTEST_ADD_TEST( ${_TestTarget}
162
TARGET_LINK_LIBRARIES( ${_TestTarget} ${_TestLibs} )
164
MESSAGE( STATUS "WARNING: Skipping ${_ClassName}, no unit test available." )
166
ENDFOREACH( _ClassName )
167
ENDFUNCTION( CXXTEST_ADD_TESTS_FROM_LIST )
169
#=============================================================
171
#=============================================================
173
find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h)
174
find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl
175
PATHS ${CXXTEST_INCLUDE_DIR})
176
find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE cxxtestgen.py
177
PATHS ${CXXTEST_INCLUDE_DIR})
179
include(FindPackageHandleStandardArgs)
180
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG CXXTEST_INCLUDE_DIR)
182
set(CXXTEST_INCLUDE_DIRS ${CXXTEST_INCLUDE_DIR})