summaryrefslogtreecommitdiffstats
path: root/config/cmake_ext_mod/grepTest.cmake
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2015-08-27 17:06:54 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2015-08-27 17:06:54 (GMT)
commitc365b9a59fb706f1943edf851586bb6f67688368 (patch)
tree2fbe7d176f9a36bc689a05b11451e8a59daf239b /config/cmake_ext_mod/grepTest.cmake
parent3c5a088df0afced706a07c92df46494741a2c9ae (diff)
parenta9c28bac4e6822321c8a7a81784526201a2d6b09 (diff)
downloadhdf5-c365b9a59fb706f1943edf851586bb6f67688368.zip
hdf5-c365b9a59fb706f1943edf851586bb6f67688368.tar.gz
hdf5-c365b9a59fb706f1943edf851586bb6f67688368.tar.bz2
[svn-r27593] Merge revisions 27453 through 27592 from trunk to vds branch.
Tested: ummon
Diffstat (limited to 'config/cmake_ext_mod/grepTest.cmake')
-rw-r--r--config/cmake_ext_mod/grepTest.cmake64
1 files changed, 64 insertions, 0 deletions
diff --git a/config/cmake_ext_mod/grepTest.cmake b/config/cmake_ext_mod/grepTest.cmake
new file mode 100644
index 0000000..5f07134
--- /dev/null
+++ b/config/cmake_ext_mod/grepTest.cmake
@@ -0,0 +1,64 @@
+# grepTest.cmake executes a command and captures the output in a file. File is then compared
+# against a reference file. Exit status of command can also be compared.
+
+# arguments checking
+if (NOT TEST_PROGRAM)
+ message (FATAL_ERROR "Require TEST_PROGRAM to be defined")
+endif (NOT TEST_PROGRAM)
+#if (NOT TEST_ARGS)
+# message (STATUS "Require TEST_ARGS to be defined")
+#endif (NOT TEST_ARGS)
+if (NOT TEST_FOLDER)
+ message ( FATAL_ERROR "Require TEST_FOLDER to be defined")
+endif (NOT TEST_FOLDER)
+if (NOT TEST_OUTPUT)
+ message (FATAL_ERROR "Require TEST_OUTPUT to be defined")
+endif (NOT TEST_OUTPUT)
+#if (NOT TEST_EXPECT)
+# message (STATUS "Require TEST_EXPECT to be defined")
+#endif (NOT TEST_EXPECT)
+if (NOT TEST_FILTER)
+ message (STATUS "Require TEST_FILTER to be defined")
+endif (NOT TEST_FILTER)
+if (NOT TEST_REFERENCE)
+ message (FATAL_ERROR "Require TEST_REFERENCE to be defined")
+endif (NOT TEST_REFERENCE)
+
+message (STATUS "COMMAND: ${TEST_PROGRAM} ${TEST_ARGS}")
+
+# run the test program, capture the stdout/stderr and the result var
+execute_process (
+ COMMAND ${TEST_PROGRAM} ${TEST_ARGS}
+ WORKING_DIRECTORY ${TEST_FOLDER}
+ RESULT_VARIABLE TEST_RESULT
+ OUTPUT_FILE ${TEST_OUTPUT}
+ ERROR_FILE ${TEST_OUTPUT}.err
+ OUTPUT_VARIABLE TEST_ERROR
+ ERROR_VARIABLE TEST_ERROR
+)
+
+message (STATUS "COMMAND Result: ${TEST_RESULT}")
+message (STATUS "COMMAND Error: ${TEST_ERROR}")
+
+# now grep the output with the reference
+file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM)
+
+# TEST_REFERENCE should always be matched
+string (REGEX MATCH "${TEST_REFERENCE}" TEST_MATCH ${TEST_STREAM})
+string (COMPARE EQUAL "${TEST_REFERENCE}" "${TEST_MATCH}" TEST_RESULT)
+if (${TEST_RESULT} STREQUAL "0")
+ message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did not contain ${TEST_REFERENCE}")
+endif (${TEST_RESULT} STREQUAL "0")
+
+string (REGEX MATCH "${TEST_FILTER}" TEST_MATCH ${TEST_STREAM})
+if (${TEST_EXPECT} STREQUAL "1")
+ # TEST_EXPECT (1) interperts TEST_FILTER as NOT to match
+ string (LENGTH "${TEST_MATCH}" TEST_RESULT)
+ if (NOT ${TEST_RESULT} STREQUAL "0")
+ message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did contain ${TEST_FILTER}")
+ endif (NOT ${TEST_RESULT} STREQUAL "0")
+endif (${TEST_EXPECT} STREQUAL "1")
+
+# everything went fine...
+message ("Passed: The output of ${TEST_PROGRAM} matched")
+