M
M
Moric2013-01-07 20:03:26
C++ / C#
Moric, 2013-01-07 20:03:26

CMake/CTest, stdout/stderr output to separate files for each test

There is a large C/C++/Fortran project built in CMake (code changes are problematic)
The result of the build is a binary file that calculates and outputs a large number of intermediate data to standard streams.
There is a constantly changing set of tests.

Purpose : when creating a test, specify that the output be redirected to a separate file for this test. So that when you call the run of all tests, the result (output to streams) can be viewed separately for all tests.

Currently the test is added with the following

add_test command ( NAME "${test_name}"
WORKING_DIRECTORY "${test_dir}"
COMMAND ${APP_NAME} ${test_args}
)

If something like 1>out.txt is added to test_args, then when the test is called, the parameter is surrounded by quotes and is regarded as a string command.

If you call ctest with the -VV parameter (ctest -VV > out.txt), then the resulting output will contain a combined hodgepodge from all tests, however, which can be parsed by an external script. But I don't think this is the right solution.

What other solutions are there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kpeo, 2013-01-18
@kpeo

you can wrap it as a bash/python script, for example:
my_test.sh:
#!/bin/sh
./$1 > $2 2>&1
and run it in tests with an argument (for a given command):
add_test ( NAME "${test_name}"
WORKING_DIRECTORY "${test_dir}"
COMMAND ${APP_NAME} ${test_dir}/my_test.sh ${APP_NAME} ${test_args}
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question