Newer
Older
Russell Taylor
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# - Find CxxTest
# Find the CxxTest suite and declare a helper macro for creating unit tests
# and integrating them with CTest.
# For more details on CxxTest see http://cxxtest.tigris.org
#
# INPUT Variables
#
# CXXTEST_USE_PYTHON
# If true, the CXXTEST_ADD_TEST macro will use
# the Python test generator instead of Perl.
#
# OUTPUT Variables
#
# CXXTEST_FOUND
# True if the CxxTest framework was found
# CXXTEST_INCLUDE_DIR
# Where to find the CxxTest include directory
# CXXTEST_PERL_TESTGEN_EXECUTABLE
# The perl-based test generator.
# CXXTEST_PYTHON_TESTGEN_EXECUTABLE
# The python-based test generator.
#
# MACROS for optional use by CMake users:
#
# CXXTEST_ADD_TEST(<test_name> <gen_source_file> <input_files_to_testgen...>)
# Creates a CxxTest runner and adds it to the CTest testing suite
# Parameters:
# test_name The name of the test
# gen_source_file The generated source filename to be generated by CxxTest
# input_files_to_testgen The list of header files containing the
# CxxTest::TestSuite's to be included in this runner
#
# #==============
# Example Usage:
#
# find_package(CxxTest)
# if(CXXTEST_FOUND)
# include_directories(${CXXTEST_INCLUDE_DIR})
# enable_testing()
#
# CXXTEST_ADD_TEST(unittest_foo foo_test.cc
# ${CMAKE_CURRENT_SOURCE_DIR}/foo_test.h)
# target_link_libraries(unittest_foo foo) # as needed
# endif()
#
# This will (if CxxTest is found):
# 1. Invoke the testgen executable to autogenerate foo_test.cc in the
# binary tree from "foo_test.h" in the current source directory.
# 2. Create an executable and test called unittest_foo.
#
# #=============
# Example foo_test.h:
#
# #include <cxxtest/TestSuite.h>
#
# class MyTestSuite : public CxxTest::TestSuite
# {
# public:
# void testAddition( void )
# {
# TS_ASSERT( 1 + 1 > 1 );
# TS_ASSERT_EQUALS( 1 + 1, 2 );
# }
# };
#
#=============================================================================
# Copyright 2008-2009 Kitware, Inc.
# Copyright 2008-2009 Philip Lowman <philip@yhbt.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distributed this file outside of CMake, substitute the full
# License text for the above reference.)
# Version 1.2 (3/2/08)
# Included patch from Tyler Roscoe to have the perl & python binaries
# detected based on CXXTEST_INCLUDE_DIR
# Version 1.1 (2/9/08)
# Clarified example to illustrate need to call target_link_libraries()
# Changed commands to lowercase
# Added licensing info
# Version 1.0 (1/8/08)
# Fixed CXXTEST_INCLUDE_DIRS so it will work properly
# Eliminated superfluous CXXTEST_FOUND assignment
# Cleaned up and added more documentation
#=============================================================
# CXXTEST_ADD_TEST (public macro)
#=============================================================
macro(CXXTEST_ADD_TEST _cxxtest_testname)
# determine the cpp filename
Peterson, Peter
committed
set(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_testname}_runner.cpp)
add_custom_command(
OUTPUT ${_cxxtest_real_outfname}
Russell Taylor
committed
DEPENDS ${PATH_FILES}
Peterson, Peter
committed
COMMAND python ${CXXTEST_TESTGEN_EXECUTABLE} --root
Russell Taylor
committed
--xunit-printer --world ${_cxxtest_testname} -o ${_cxxtest_real_outfname}
Peterson, Peter
committed
)
set_source_files_properties(${_cxxtest_real_outfname} PROPERTIES GENERATED true)
# convert the header files to have full path
Peterson, Peter
committed
set (_cxxtest_cpp_files "${_cxxtest_real_outfname}")
Russell Taylor
committed
foreach (part ${ARGN})
Peterson, Peter
committed
get_filename_component(_cxxtest_cpp ${part} NAME)
string ( REPLACE ".h" ".cpp" _cxxtest_cpp ${_cxxtest_cpp} )
set ( _cxxtest_cpp "${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_cpp}" )
set ( _cxxtest_h "${CMAKE_CURRENT_SOURCE_DIR}/${part}" )
add_custom_command(
OUTPUT ${_cxxtest_cpp}
Russell Taylor
committed
DEPENDS ${_cxxtest_h}
Peterson, Peter
committed
COMMAND python ${CXXTEST_TESTGEN_EXECUTABLE} --part
Russell Taylor
committed
--world ${_cxxtest_testname} -o ${_cxxtest_cpp} ${_cxxtest_h}
Peterson, Peter
committed
)
set_source_files_properties(${_cxxtest_cpp} PROPERTIES GENERATED true)
set (_cxxtest_cpp_files ${_cxxtest_cpp} ${_cxxtest_cpp_files})
Russell Taylor
committed
endforeach (part ${ARGN})
# define the test executable and exclude it from the all target
Peterson, Peter
committed
add_executable(${_cxxtest_testname} EXCLUDE_FROM_ALL ${_cxxtest_cpp_files} ${ARGN})
Russell Taylor
committed
# only the package wide test is added to check
Russell Taylor
committed
add_dependencies(check ${_cxxtest_testname})
Peterson, Peter
committed
if (CXXTEST_SINGLE_LOGFILE)
# add the whole suite as a single test so the output xml doesn't overwrite itself
add_test ( NAME ${_cxxtest_testname}
Peterson, Peter
committed
COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_BINARY_DIR}/bin/Testing"
$<TARGET_FILE:${_cxxtest_testname}> )
Peterson, Peter
committed
else (CXXTEST_SINGLE_LOGFILE)
# THE FOLLOWING DESTROYS THE OUTPUT XML FILE
# add each separate test to ctest
foreach ( part ${ARGN} )
get_filename_component(_suitename ${part} NAME_WE )
set( _cxxtest_separate_name "${_cxxtest_testname}_${_suitename}")
add_test ( NAME ${_cxxtest_separate_name}
Peterson, Peter
committed
COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_BINARY_DIR}/bin/Testing"
$<TARGET_FILE:${_cxxtest_testname}> ${_suitename} )
Peterson, Peter
committed
endforeach ( part ${ARGN} )
endif (CXXTEST_SINGLE_LOGFILE)
Russell Taylor
committed
endmacro(CXXTEST_ADD_TEST)
#=============================================================
# main()
#=============================================================
find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h
PATHS ${PROJECT_SOURCE_DIR}/TestingTools/cxxtest
${PROJECT_SOURCE_DIR}/../TestingTools/cxxtest )
Peterson, Peter
committed
find_program(CXXTEST_TESTGEN_EXECUTABLE python/scripts/cxxtestgen
PATHS ${CXXTEST_INCLUDE_DIR})
Russell Taylor
committed
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG CXXTEST_INCLUDE_DIR)
set(CXXTEST_INCLUDE_DIRS ${CXXTEST_INCLUDE_DIR})