[CMake] Fwd: generating CTest tests
John Drescher
drescherjm at gmail.com
Fri Aug 28 13:53:33 EDT 2009
---------- Forwarded message ----------
From: John Drescher <drescherjm at gmail.com>
Date: Fri, Aug 28, 2009 at 1:53 PM
Subject: Re: [CMake] generating CTest tests
To: Alex H <aditya15417 at hotmail.com>
On Fri, Aug 28, 2009 at 1:38 PM, Alex H<aditya15417 at hotmail.com> wrote:
> Hello,
> In the ADD_TEST command in the example below I mentioned the test name is
> test1, is this only a naming thing or does it mean
> that I have to have an actual file called test1 in the system to be run by
> the executable? Sorry, I read the documentation several times and
> still don't understand as somewhere on the documentation it also mentions
> test files, I am not sure what to put inside this test file though.
> Should I put this ADD_TEST inside the test file or the CMakeLists.txt?
> Thanks
> Alex
>
You make a separate target for this. Here is an example.
I have a main project Called QtBasicUtils in that main project I have
in the main application CMakeLists.txt
option (BUILD_TESTING "Build Tests" ON)
IF(BUILD_TESTING)
ENABLE_TESTING()
add_subdirectory(Testing)
ENDIF(BUILD_TESTING)
And then in the CMakeLists.txt file in QtBasicUtils/Testing
#This file contains the automated unit testing for QtBasicUtils
LINK_LIBRARIES(BasicTest QtBasicUtils ${QT_LIBRARIES})
include_directories( ${PROJECT_BINARY_DIR} ${PROJECT_BINARY_DIR}/..
${PROJECT_SOURCE_DIR}/include ./include)
set(TEST_SRCS
./src/basic.cxx
./src/testxml.cxx
./src/testUserProps.cxx
)
set(TEST_HDRS
./include/testxml.h
./include/testUserProps.h
)
add_executable(BasicTest ${TEST_SRCS} ${TEST_HDRS})
add_dependencies(BasicTest QtBasicUtils)
file(WRITE ${EXECUTABLE_OUTPUT_PATH}/test0.txt "+FLOATARGS 1.0 2.0 2.0
2.0 2.0 -S9.0")
add_test(FileCMD0 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
@${EXECUTABLE_OUTPUT_PATH}/test0.txt)
#This will fail because the file should not exist.
add_test(FileCMD1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
@${EXECUTABLE_OUTPUT_PATH}/../test111111111111111111.txt)
SET_TESTS_PROPERTIES(FileCMD1 PROPERTIES WILL_FAIL TRUE)
ADD_TEST(Test0 ${EXECUTABLE_OUTPUT_PATH}/BasicTest +?)
ADD_TEST(Test1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest +Test 1.0)
ADD_TEST(StringListArg0 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+STRLSTARG 1 2 3 4 . -S10)
ADD_TEST(StringListArg1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+STRLSTARG 1 2 3 . -S6)
ADD_TEST(StringListOpt0 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+STRLSTOPT -I1 2 3 . -S6)
ADD_TEST(StringListOpt1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+STRLSTOPT -I1 2 3 4 . -S10)
ADD_TEST(BoolOpt1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+BOOLOPT -B)
ADD_TEST(BoolOpt2 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+BOOLOPT -B-)
SET_TESTS_PROPERTIES(BoolOpt2 PROPERTIES WILL_FAIL TRUE)
ADD_TEST(ExtBoolOpt1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+EXTBOOLOPT --use_extended=+)
ADD_TEST(ExtBoolOpt2 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+EXTBOOLOPT --use_extended=-)
ADD_TEST(ExtBoolOpt3 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+EXTBOOLOPT --use_extended+)
ADD_TEST(ExtBoolOpt4 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+EXTBOOLOPT --use_extended-)
ADD_TEST(ExtBoolOpt5 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+EXTBOOLOPT --use_extended)
SET_TESTS_PROPERTIES(ExtBoolOpt2 PROPERTIES WILL_FAIL TRUE)
SET_TESTS_PROPERTIES(ExtBoolOpt4 PROPERTIES WILL_FAIL TRUE)
ADD_TEST(FloatArgs0 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+FLOATARGS 1.0 -S5.0)
ADD_TEST(FloatArgs1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+FLOATARGS 2.0 -S6.0)
ADD_TEST(FloatArgs2 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+FLOATARGS 1.0 1.0 -S5.0)
ADD_TEST(FloatArgs3 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+FLOATARGS 1.0 2.0 -S6.0)
ADD_TEST(FloatArgs4 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+FLOATARGS 1.0 1.0 1.0 1.0 1.0 -S5.0)
ADD_TEST(FloatArgs5 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+FLOATARGS 2.0 2.0 2.0 2.0 2.0 -S10.0)
ADD_TEST(FloatArgs6 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+FLOATARGS -2.0 2.0 2.0 2.0 2.0 -S6.0)
ADD_TEST(FloatArgs7 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+FLOATARGS 1.0 2.0 2.0 2.0 2.0 -S10.0)
SET_TESTS_PROPERTIES(FloatArgs7 PROPERTIES WILL_FAIL TRUE)
ADD_TEST(FloatArgs8 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+FLOATARGS 1.0 2.0 2.0 2.0 2.0 1.0 -S10.0)
SET_TESTS_PROPERTIES(FloatArgs8 PROPERTIES WILL_FAIL TRUE)
ADD_TEST(DoubleArgs0 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+DOUBLEARGS 1.0 -S5.0)
ADD_TEST(DoubleArgs1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+DOUBLEARGS 2.0 -S6.0)
ADD_TEST(DoubleArgs2 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+DOUBLEARGS 1.0 1.0 -S5.0)
ADD_TEST(DoubleArgs3 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+DOUBLEARGS 1.0 2.0 -S6.0)
ADD_TEST(DoubleArgs4 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+DOUBLEARGS 1.0 1.0 1.0 1.0 1.0 -S5.0)
ADD_TEST(DoubleArgs5 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+DOUBLEARGS 2.0 2.0 2.0 2.0 2.0 -S10.0)
ADD_TEST(DoubleArgs6 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+DOUBLEARGS -2.0 2.0 2.0 2.0 2.0 -S6.0)
ADD_TEST(DoubleArgs7 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+DOUBLEARGS 1.0 2.0 2.0 2.0 2.0 -S10.0)
SET_TESTS_PROPERTIES(DoubleArgs7 PROPERTIES WILL_FAIL TRUE)
ADD_TEST(DoubleArgs8 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+DOUBLEARGS 1.0 2.0 2.0 2.0 2.0 1.0 -S10.0)
SET_TESTS_PROPERTIES(DoubleArgs8 PROPERTIES WILL_FAIL TRUE)
ADD_TEST(XMLExport0 ${EXECUTABLE_OUTPUT_PATH}/BasicTest +XMLEXP 0)
ADD_TEST(XMLExport1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest +XMLEXP 1)
ADD_TEST(XMLExport2 ${EXECUTABLE_OUTPUT_PATH}/BasicTest +XMLEXP 2)
ADD_TEST(XMLExport3 ${EXECUTABLE_OUTPUT_PATH}/BasicTest +XMLEXP 3)
ADD_TEST(XMLExport4 ${EXECUTABLE_OUTPUT_PATH}/BasicTest +XMLEXP 4)
ADD_TEST(XMLExport5 ${EXECUTABLE_OUTPUT_PATH}/BasicTest +XMLEXP 5)
ADD_TEST(XMLExport6 ${EXECUTABLE_OUTPUT_PATH}/BasicTest +XMLEXP 6)
ADD_TEST(UserProp0 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+USERPROP 0)
ADD_TEST(UserProp1 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+USERPROP 1)
ADD_TEST(UserProp2 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+USERPROP 2)
ADD_TEST(UserProp3 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+USERPROP 3)
SET_TESTS_PROPERTIES(UserProp3 PROPERTIES WILL_FAIL TRUE)
ADD_TEST(UserProp4 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+USERPROP 4)
SET_TESTS_PROPERTIES(UserProp4 PROPERTIES WILL_FAIL TRUE)
ADD_TEST(UserProp5 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+USERPROP 5)
ADD_TEST(UserProp6 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+USERPROP 6)
ADD_TEST(UserProp7 ${EXECUTABLE_OUTPUT_PATH}/BasicTest
+USERPROP 7)
I hope this helps.
John
--
John M. Drescher
More information about the CMake
mailing list