diff options
author | David Cole <david.cole@kitware.com> | 2009-10-03 16:01:10 (GMT) |
---|---|---|
committer | David Cole <david.cole@kitware.com> | 2009-10-03 16:01:10 (GMT) |
commit | 517e1e3c0f90712c1234ef03086e4a7d43be3be2 (patch) | |
tree | 672f58a9f2ebe11b864d41040f14a0ba7ee83ba4 /Tests/CMakeTests/ExecuteScriptTests.cmake | |
parent | eb91859d6fa9ef2784977568fc43052fbc1084d9 (diff) | |
download | CMake-517e1e3c0f90712c1234ef03086e4a7d43be3be2.zip CMake-517e1e3c0f90712c1234ef03086e4a7d43be3be2.tar.gz CMake-517e1e3c0f90712c1234ef03086e4a7d43be3be2.tar.bz2 |
Add a few more cases to the new StringTest for even better coverage. Re-factor the scripts to make it easier to add new cases to this test. Re-factoring also enables the test driver in ExecuteScriptTests to be re-used when adding new tests in the future.
Diffstat (limited to 'Tests/CMakeTests/ExecuteScriptTests.cmake')
-rw-r--r-- | Tests/CMakeTests/ExecuteScriptTests.cmake | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/Tests/CMakeTests/ExecuteScriptTests.cmake b/Tests/CMakeTests/ExecuteScriptTests.cmake new file mode 100644 index 0000000..415614f --- /dev/null +++ b/Tests/CMakeTests/ExecuteScriptTests.cmake @@ -0,0 +1,62 @@ +# This function calls the ${scriptname} file to execute one test case: +# +function(execute_one_script_test scriptname testname expected_result) + message("execute_one_script_test") + message("testname=[${testname}]") + + execute_process( + COMMAND ${CMAKE_COMMAND} + -D "testname:STRING=${testname}" + -P "${scriptname}" + OUTPUT_VARIABLE out + ERROR_VARIABLE err + RESULT_VARIABLE result + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE + ) + + message("out=[${out}]") + message("err=[${err}]") + + if(expected_result STREQUAL "fail") + # case expected to fail, result should be non-0... + # error if it's 0 + if("${result}" STREQUAL "0") + message(SEND_ERROR "script failed: testname='${testname}' [${result}] actually passed, but expected to fail...") + endif() + else() + # case expected to pass, result should be 0... + # error if it's non-0 + if(NOT "${result}" STREQUAL "0") + message(SEND_ERROR "script failed: testname='${testname}' [${result}] actually failed, but expected to pass...") + endif() + endif() + + message("") +endfunction() + + +# This function reads the script file and calls execute_one_script_test for +# each testname case listed in the script. To add new cases, simply edit the +# script file and add an elseif() clause that matches 'regex' below. +# +function(execute_all_script_tests scriptname result) + file(READ "${scriptname}" script) + + string(REPLACE ";" "\\\\;" script "${script}") + string(REPLACE "\n" "E;" script "${script}") + + set(count 0) + set(regex "^ *(if|elseif) *\\( *testname +STREQUAL +\\\"*([^\\\"\\)]+)\\\"* *\\) *# *(fail|pass) *E$") + + foreach(line ${script}) + if(line MATCHES "${regex}") + math(EXPR count "${count} + 1") + string(REGEX REPLACE "${regex}" "\\2" testname "${line}") + string(REGEX REPLACE "${regex}" "\\3" expected_result "${line}") + execute_one_script_test(${scriptname} ${testname} ${expected_result}) + endif() + endforeach() + + set(${result} ${count} PARENT_SCOPE) +endfunction() |