summaryrefslogtreecommitdiffstats
path: root/cmake/rnp_tests_discover.cmake
blob: 9f05293762c25ed540dbe8624d60415e3e260406 (plain)
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
set(script)

function(add_command NAME)
  set(_args "")
  foreach(_arg ${ARGN})
    set(_args "${_args} [==[${_arg}]==]")
  endforeach()
  set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
endfunction()

if(NOT EXISTS "${TEST_EXECUTABLE}")
  message(FATAL_ERROR "Executable does not exist: ${TEST_EXECUTABE}")
endif()
execute_process(
  COMMAND "${TEST_EXECUTABLE}" list-tests
  WORKING_DIRECTORY "${TEST_WORKING_DIR}"
  OUTPUT_VARIABLE output
  RESULT_VARIABLE result
)
if(NOT ${result} EQUAL 0)
  message(FATAL_ERROR "Error running executable: ${TEST_EXECUTABE}")
endif()

string(REPLACE "\n" ";" output "${output}")

foreach(line ${output})
  set(test "${line}")
  add_command(add_test
    "rnp_tests-${test}"
    "${TEST_EXECUTABLE}"
    "${test}"
  )
  add_command(set_tests_properties
    "rnp_tests-${test}"
    PROPERTIES ${TEST_PROPERTIES}
  )
endforeach()

file(WRITE "${CTEST_FILE}" "${script}")