4

I'm converting some old tests to cmake/ctest and would like a test to fail if the output file contains a specific warning message.

In the past I would search the output file for a specific string. I'm already using execute_process to use the compare_files command. Is there a similar command for searching a file for a string?

Thanks for your help.

ALou
  • 41
  • 1
  • 2

1 Answers1

5

No, but you can read the file into a variable using file. (http://www.cmake.org/cmake/help/v3.0/command/file.html) and then use one of the string subcommands.

file(READ foo TMPTXT)

string(FIND "${TMPTXT}" "needle" matchres)

message(STATUS ${matchres})

if(${matchres} EQUAL -1)
    message(FATAL_ERROR "No match found")
endif ()

and then

${CMAKE_COMMAND} -P findmatch.cmake

Specifics might be a bit different, but that's the general idea.

the_storyteller
  • 2,335
  • 1
  • 26
  • 37
Mark Nunberg
  • 3,551
  • 15
  • 18