Wrong result when comparing directories using 'cmake -E compare_files'

38 Views Asked by At

I am trying to write a CTest test that compares an output directory with another directory that is known to be correct (golden).

I used the tool cmake -E compare_files <file1> <file2>, which is supposed to also work on directories from the little I've gathered online.

add_test("cmp_to_golden_${test_name}" "${CMAKE_COMMAND}" -E compare_files 
    "${output_path}"
    "${golden_path}"
)

I didn't find anything useful online and the command itself doesn't print anything, so I have no idea why it returns 1 (meaning it thinks they are different). I am certain the directories are the same as I copy pasted the output to the golden directory and it still doesn't work. It only works if I put the same path as both arguments.

What am I missing? I might be that the tool really isn't made for directories, but I'd like some confirmation on that.

1

There are 1 best solutions below

1
Osyotr On

It's not supposed to work with directories. Here's the code that handles compare_files command: https://gitlab.kitware.com/cmake/cmake/-/blob/a3f76a4e4dc15997f22306b002fbc452af1259a6/Source/cmcmd.cxx#L771

The cmSystemTools::FilesDiffer that is used underneath does not work with directories: https://gitlab.kitware.com/cmake/cmake/-/blob/a3f76a4e4dc15997f22306b002fbc452af1259a6/Source/kwsys/SystemTools.cxx#L2308

What you might want to use is file(GLOB_RECURSE) + "${CMAKE_COMMAND}" -E compare_files ....