2008-12-12 06:05:30 +03:00
|
|
|
# - Find CxxTest
|
|
|
|
# Find the CxxTest suite and declare a helper macro for creating unit tests
|
2009-01-08 12:47:40 +03:00
|
|
|
# and integrating them with CTest.
|
2008-12-12 06:05:30 +03:00
|
|
|
# For more details on CxxTest see http://cxxtest.tigris.org
|
|
|
|
#
|
|
|
|
# INPUT Variables
|
|
|
|
#
|
|
|
|
# CXXTEST_USE_PYTHON
|
2009-01-08 12:47:40 +03:00
|
|
|
# If true, the CXXTEST_ADD_TEST macro will use
|
|
|
|
# the Python test generator instead of Perl.
|
2008-12-12 06:05:30 +03:00
|
|
|
#
|
|
|
|
# OUTPUT Variables
|
|
|
|
#
|
|
|
|
# CXXTEST_FOUND
|
|
|
|
# True if the CxxTest framework was found
|
2009-01-08 12:47:40 +03:00
|
|
|
# CXXTEST_INCLUDE_DIR
|
|
|
|
# Where to find the CxxTest include directory
|
2008-12-12 06:05:30 +03:00
|
|
|
# CXXTEST_PERL_TESTGEN_EXECUTABLE
|
|
|
|
# The perl-based test generator.
|
|
|
|
# CXXTEST_PYTHON_TESTGEN_EXECUTABLE
|
|
|
|
# The python-based test generator.
|
|
|
|
#
|
2009-02-10 07:05:38 +03:00
|
|
|
# MACROS for optional use by CMake users:
|
2008-12-12 06:05:30 +03:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2009-01-08 12:47:40 +03:00
|
|
|
# #==============
|
|
|
|
# Example Usage:
|
|
|
|
#
|
2009-02-10 07:05:38 +03:00
|
|
|
# find_package(CxxTest)
|
|
|
|
# if(CXXTEST_FOUND)
|
|
|
|
# include_directories(${CXXTEST_INCLUDE_DIR})
|
|
|
|
# enable_testing()
|
2009-01-08 12:47:40 +03:00
|
|
|
#
|
2009-02-10 07:05:38 +03:00
|
|
|
# CXXTEST_ADD_TEST(unittest_foo foo_test.cc
|
|
|
|
# ${CMAKE_CURRENT_SOURCE_DIR}/foo_test.h)
|
|
|
|
# target_link_libraries(unittest_foo foo) # as needed
|
|
|
|
# endif()
|
2008-12-12 06:05:30 +03:00
|
|
|
#
|
2009-02-10 07:05:38 +03:00
|
|
|
# This will (if CxxTest is found):
|
2008-12-12 06:05:30 +03:00
|
|
|
# 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.
|
|
|
|
#
|
2009-01-08 12:47:40 +03:00
|
|
|
# #=============
|
|
|
|
# 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 );
|
|
|
|
# }
|
|
|
|
# };
|
|
|
|
#
|
2009-09-22 06:38:12 +04:00
|
|
|
|
2009-10-02 01:21:28 +04:00
|
|
|
#=============================================================================
|
|
|
|
# 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.)
|
|
|
|
|
2009-03-03 04:29:38 +03:00
|
|
|
# Version 1.2 (3/2/08)
|
|
|
|
# Included patch from Tyler Roscoe to have the perl & python binaries
|
|
|
|
# detected based on CXXTEST_INCLUDE_DIR
|
2009-02-10 07:05:38 +03:00
|
|
|
# Version 1.1 (2/9/08)
|
|
|
|
# Clarified example to illustrate need to call target_link_libraries()
|
|
|
|
# Changed commands to lowercase
|
|
|
|
# Added licensing info
|
2009-01-08 12:47:40 +03:00
|
|
|
# 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
|
2008-12-12 06:05:30 +03:00
|
|
|
|
2009-01-08 12:47:40 +03:00
|
|
|
#=============================================================
|
|
|
|
# CXXTEST_ADD_TEST (public macro)
|
|
|
|
#=============================================================
|
2009-02-10 07:05:38 +03:00
|
|
|
macro(CXXTEST_ADD_TEST _cxxtest_testname _cxxtest_outfname)
|
|
|
|
set(_cxxtest_real_outfname ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_outfname})
|
|
|
|
if(CXXTEST_USE_PYTHON)
|
|
|
|
set(_cxxtest_executable ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE})
|
|
|
|
else()
|
|
|
|
set(_cxxtest_executable ${CXXTEST_PERL_TESTGEN_EXECUTABLE})
|
|
|
|
endif()
|
2008-12-12 06:05:30 +03:00
|
|
|
|
2009-02-10 07:05:38 +03:00
|
|
|
add_custom_command(
|
2008-12-12 06:05:30 +03:00
|
|
|
OUTPUT ${_cxxtest_real_outfname}
|
|
|
|
DEPENDS ${ARGN}
|
|
|
|
COMMAND ${_cxxtest_executable}
|
|
|
|
--error-printer -o ${_cxxtest_real_outfname} ${ARGN}
|
|
|
|
)
|
|
|
|
|
2009-02-10 07:05:38 +03:00
|
|
|
set_source_files_properties(${_cxxtest_real_outfname} PROPERTIES GENERATED true)
|
|
|
|
add_executable(${_cxxtest_testname} ${_cxxtest_real_outfname})
|
2008-12-12 06:05:30 +03:00
|
|
|
|
2009-02-10 07:05:38 +03:00
|
|
|
if(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
|
|
|
|
add_test(${_cxxtest_testname} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_cxxtest_testname})
|
|
|
|
elseif(EXECUTABLE_OUTPUT_PATH)
|
|
|
|
add_test(${_cxxtest_testname} ${EXECUTABLE_OUTPUT_PATH}/${_cxxtest_testname})
|
|
|
|
else()
|
|
|
|
add_test(${_cxxtest_testname} ${CMAKE_CURRENT_BINARY_DIR}/${_cxxtest_testname})
|
|
|
|
endif()
|
2008-12-12 06:05:30 +03:00
|
|
|
|
2009-02-10 07:05:38 +03:00
|
|
|
endmacro(CXXTEST_ADD_TEST)
|
2008-12-12 06:05:30 +03:00
|
|
|
|
2009-01-08 12:47:40 +03:00
|
|
|
#=============================================================
|
|
|
|
# main()
|
|
|
|
#=============================================================
|
2008-12-12 06:05:30 +03:00
|
|
|
|
2009-02-10 07:05:38 +03:00
|
|
|
find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h)
|
2009-03-03 04:29:38 +03:00
|
|
|
find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl
|
|
|
|
PATHS ${CXXTEST_INCLUDE_DIR})
|
|
|
|
find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE cxxtestgen.py
|
|
|
|
PATHS ${CXXTEST_INCLUDE_DIR})
|
2008-12-12 06:05:30 +03:00
|
|
|
|
2009-02-10 07:05:38 +03:00
|
|
|
include(FindPackageHandleStandardArgs)
|
2008-12-12 06:05:30 +03:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG CXXTEST_INCLUDE_DIR)
|
2009-02-10 07:05:38 +03:00
|
|
|
|
|
|
|
set(CXXTEST_INCLUDE_DIRS ${CXXTEST_INCLUDE_DIR})
|