Search code examples
testingcmakefortran

How to force cmake to write test output after make test


I'm building fortran project with cmake and I can't find solution to print to console FRUIT test results, they look something like these:

Test module initialized

    . : successful assert,   F : failed assert 

    7.00000000000000       -3.60000000000000        7.00000000000000     
FFF

     Start of FRUIT summary: 

 Some tests failed!

   -- Failed assertion messages:
   [_not_set_]:Expected [7.00000000000000], Got [1.00000000000000]
   [_not_set_]:Expected [-3.60000000000000], Got [2.00000000000000]
   [_not_set_]:Expected [7.00000000000000], Got [6.00000000000000]
   -- end of failed assertion messages.

 Total asserts :              3
 Successful    :              0
 Failed        :              3 
 Successful rate:     0.00%

 Successful asserts / total asserts : [            0 /           3  ]
 Successful cases   / total cases   : [            0 /           0  ]
   -- end of FRUIT summary

The output I'm getting with make test looks like:

make test
Running tests...
Test project /home/konrad/Desktop/fortran
    Start 1: unit_tests
1/1 Test #1: unit_tests .......................   Passed    0.01 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.01 sec

And since passing cmake tests doesn't mean passing FRUIT ones, I want to print FRUIT file everytime I run tests (just for the sake of making it work). I've tried adding printing commands at the end of test command (like this less), adding

-P ${CMAKE_TEST_DIR}/unit_tests.txt

at the end of add_test, building custom after build commands (which I can't make to run after make test so if you knew how to do that would solve it as well, seems like make test or test is not really a target)

Last part of my cmake file with all the testing code:

add_executable(task ${TASK_SOURCES})
add_executable(tests ${TEST_SOURCES})



enable_testing() 

set(run_command "${CMAKE_BINARY_DIR}/tests")
set(UNIT_TEST_NAME "unit_tests.txt")


file(MAKE_DIRECTORY ${CMAKE_TEST_DIR})

add_test( NAME unit_tests
      COMMAND sh -c
     "rm -f ${CMAKE_TEST_DIR}/${UNIT_TEST_NAME} \
      && ${run_command} \
      >> ${CMAKE_TEST_DIR}/${UNIT_TEST_NAME} \
      && less ${CMAKE_TEST_DIR}/${UNIT_TEST_NAME}"
      )

Solution

  • I have solved a lack of tests output with custom CMake target that will invoke ctest in verbose mode etc. e.g.

    enable_testing()
    
    add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
         --force-new-ctest-process
         --verbose
          --output-on-failure
    )