[CMake] How to add a test and compare its output to a reference file ?

Judicaël Bedouet j.bedouet at infonie.fr
Thu Sep 11 18:07:32 EDT 2008


Hi,

I 'm converting a project to CMake. Tests in this project print messages to
cout and these output traces are compared to reference files. If output and
its reference are different, the corresponding test is considered as failed.
I can't see how to make these tests work with CMake.

I try to run a complex command in ADD_TEST like
ADD_TEST (Test test --arg_test > output && ${DIFF_COMMAND} output
reference_file).
DIFF_COMMAND is equal to diff under Unix and fc under Windows. But CMake
interprets test commands and '>' is passed as an argument to test ("test"
"--arg_test" ">" "output" "&&" "diff" "output" "reference_file").

I try to set property PASS_REGULAR_EXPRESSION to contents of reference file.
It works for little files but it's difficult for large files :
  - All characters * . ( ) ^ $ ... must be backslashed.
  - In this project, generated files are encoded in UTF-8 and I'm not sure
that CMake regular expressions support UTF-8.
  - When there is a difference, I can't see where it is. I understand that
PASS_REGULAR_EXPRESSION wasn't thought in terms of matching whole file.

I could modify source of program tests by redirecting std::cout to a file
and comparing this file to the reference file. But before doing this, I
would like to know if there is a way to make a test with command like `test
args > file && diff` or if it's possible to add a test property which
compare output of the program to a no regular expression.

Thanks,

J. Bedouet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080912/36eab7b4/attachment.htm>


More information about the CMake mailing list