Warning, /geant4/examples/extended/exoticphysics/phonon/ComparePhonon.cmake is written in an unsupported language. File is not indexed.
0001 # - Compare test to reference file
0002 #
0003 # Run as:
0004 #
0005 # $ cmake -Dtest_file=<output> -Dreference_file=<ref> -P CompareFiles.cmake
0006 #
0007 # - Both files are checked for existence.
0008 # - Comparison is via cmake -E compare_files
0009 # - If comparison fails, print test file to stdout
0010 #
0011
0012 # CL checks
0013 set(__CF_USAGE "usage: cmake -Dtest_file=<input> -Dreference_file=<ref> -P CompareFiles.cmake")
0014
0015 if(NOT test_file)
0016 message(FATAL_ERROR "No test_file argument\n${__CF_USAGE}")
0017 endif()
0018
0019 if(NOT reference_file)
0020 message(FATAL_ERROR "No reference file argument\n${__CF_USAGE}")
0021 endif()
0022
0023 # File existence checks
0024 # Assume relative paths are relative to cwd
0025 if(NOT (IS_ABSOLUTE "${test_file}"))
0026 set(test_file "${CMAKE_CURRENT_SOURCE_DIR}/${test_file}")
0027 endif()
0028
0029 if(NOT (IS_ABSOLUTE "${reference_file}"))
0030 set(reference_file "${CMAKE_CURRENT_SOURCE_DIR}/${reference_file}")
0031 endif()
0032
0033 if(NOT EXISTS "${test_file}")
0034 message(FATAL_ERROR "test_file '${test_file}' does not exist")
0035 endif()
0036
0037 if(NOT (EXISTS "${reference_file}"))
0038 message(FATAL_ERROR "reference_file '${reference_file}' does not exist")
0039 endif()
0040
0041 # File comparison
0042 execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files ${test_file} ${reference_file}
0043 RESULT_VARIABLE __cf_result_var
0044 OUTPUT_QUIET
0045 ERROR_QUIET
0046 )
0047
0048 if(__cf_result_var)
0049 # Comparison failed, print contents of test_file and exit with an error
0050 file(READ ${test_file} __cf_test_contents)
0051 message("-- Test output '${test_file}' does not match reference '${reference_file}'")
0052 message("-- Contents of test output '${test_file}' (unformatted):")
0053 message("${__cf_test_contents}")
0054 message(FATAL_ERROR "TEST FAILED")
0055 else()
0056 message(STATUS "Test output '${test_file}' matches reference '${reference_file}'")
0057 endif()
0058