summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmStringCommand.cxx8
-rw-r--r--Tests/CMakeTests/CMakeLists.txt1
-rw-r--r--Tests/CMakeTests/StringTest.cmake.in74
-rw-r--r--Tests/CMakeTests/StringTestScript.cmake131
4 files changed, 210 insertions, 4 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 134f9ea..2313853 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -381,7 +381,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
{
std::string e = "sub-command REGEX, mode REPLACE: Unknown escape \"";
e += replace.substr(r, 2);
- e += "\"in replace-expression.";
+ e += "\" in replace-expression.";
this->SetError(e.c_str());
return false;
}
@@ -559,7 +559,7 @@ bool cmStringCommand::HandleReplaceCommand(std::vector<std::string> const&
{
if(args.size() < 5)
{
- this->SetError("sub-command REPLACE requires four arguments.");
+ this->SetError("sub-command REPLACE requires at least four arguments.");
return false;
}
@@ -586,7 +586,7 @@ bool cmStringCommand::HandleSubstringCommand(std::vector<std::string> const&
{
if(args.size() != 5)
{
- this->SetError("sub-command REPLACE requires four arguments.");
+ this->SetError("sub-command SUBSTRING requires four arguments.");
return false;
}
@@ -647,7 +647,7 @@ bool cmStringCommand::HandleStripCommand(
{
if(args.size() != 3)
{
- this->SetError("sub-command LENGTH requires two arguments.");
+ this->SetError("sub-command STRIP requires two arguments.");
return false;
}
diff --git a/Tests/CMakeTests/CMakeLists.txt b/Tests/CMakeTests/CMakeLists.txt
index 34ac12c..25996de 100644
--- a/Tests/CMakeTests/CMakeLists.txt
+++ b/Tests/CMakeTests/CMakeLists.txt
@@ -22,6 +22,7 @@ AddCMakeTest(ConfigureFile "")
AddCMakeTest(SeparateArguments "")
AddCMakeTest(ImplicitLinkInfo "")
AddCMakeTest(ModuleNotices "")
+AddCMakeTest(String "")
SET(GetPrerequisites_PreArgs
"-DCTEST_CONFIGURATION_TYPE:STRING=\\\${CTEST_CONFIGURATION_TYPE}"
diff --git a/Tests/CMakeTests/StringTest.cmake.in b/Tests/CMakeTests/StringTest.cmake.in
new file mode 100644
index 0000000..7e9756c
--- /dev/null
+++ b/Tests/CMakeTests/StringTest.cmake.in
@@ -0,0 +1,74 @@
+function(test_string_command testname expected_result)
+ message("testname=[${testname}]")
+
+ execute_process(
+ COMMAND ${CMAKE_COMMAND}
+ -D "testname:STRING=${testname}"
+ -P "@CMAKE_CURRENT_SOURCE_DIR@/StringTestScript.cmake"
+ 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 "StringTestScript 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 "StringTestScript failed: testname='${testname}' [${result}] actually failed, but expected to pass...")
+ endif()
+ endif()
+
+ message("")
+endfunction()
+
+
+test_string_command(empty fail)
+test_string_command(bogus fail)
+test_string_command(random pass)
+test_string_command(toupper_no_variable fail)
+test_string_command(ascii_no_variable fail)
+test_string_command(ascii_bad_code fail)
+test_string_command(configure_no_input fail)
+test_string_command(configure_no_variable fail)
+test_string_command(configure_escape_quotes pass)
+test_string_command(configure_bogus fail)
+test_string_command(regex_no_mode fail)
+test_string_command(regex_match_not_enough_args fail)
+test_string_command(regex_matchall_not_enough_args fail)
+test_string_command(regex_replace_not_enough_args fail)
+test_string_command(regex_bogus_mode fail)
+test_string_command(regex_match_multiple_inputs pass)
+test_string_command(regex_match_bad_regex fail)
+test_string_command(regex_match_empty_string fail)
+test_string_command(regex_matchall_multiple_inputs pass)
+test_string_command(regex_matchall_bad_regex fail)
+test_string_command(regex_matchall_empty_string fail)
+test_string_command(regex_replace_ends_with_backslash fail)
+test_string_command(regex_replace_ends_with_escaped_backslash pass)
+test_string_command(regex_replace_has_linefeed pass)
+test_string_command(regex_replace_has_bogus_escape fail)
+test_string_command(regex_replace_bad_regex fail)
+test_string_command(regex_replace_empty_string fail)
+test_string_command(compare_no_mode fail)
+test_string_command(compare_bogus_mode fail)
+test_string_command(compare_not_enough_args fail)
+test_string_command(replace_not_enough_args fail)
+test_string_command(replace_multiple_inputs pass)
+test_string_command(substring_not_enough_args fail)
+test_string_command(substring_bad_begin fail)
+test_string_command(substring_bad_end fail)
+test_string_command(length_not_enough_args fail)
+
+
+test_string_command(no_such_testname fail)
diff --git a/Tests/CMakeTests/StringTestScript.cmake b/Tests/CMakeTests/StringTestScript.cmake
new file mode 100644
index 0000000..8233113
--- /dev/null
+++ b/Tests/CMakeTests/StringTestScript.cmake
@@ -0,0 +1,131 @@
+message(STATUS "testname='${testname}'")
+
+
+if(testname STREQUAL empty)
+ string()
+
+elseif(testname STREQUAL bogus)
+ string(BOGUS)
+
+elseif(testname STREQUAL random)
+ string(RANDOM r)
+ message(STATUS "r='${r}'")
+
+elseif(testname STREQUAL toupper_no_variable)
+ string(TOUPPER)
+
+elseif(testname STREQUAL ascii_no_variable)
+ string(ASCII)
+
+elseif(testname STREQUAL ascii_bad_code)
+ string(ASCII 288 bummer)
+
+elseif(testname STREQUAL configure_no_input)
+ string(CONFIGURE)
+
+elseif(testname STREQUAL configure_no_variable)
+ string(CONFIGURE "this is @testname@")
+
+elseif(testname STREQUAL configure_escape_quotes)
+ string(CONFIGURE "this is @testname@" v ESCAPE_QUOTES)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL configure_bogus)
+ string(CONFIGURE "this is @testname@" v ESCAPE_QUOTES BOGUS)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_no_mode)
+ string(REGEX)
+
+elseif(testname STREQUAL regex_match_not_enough_args)
+ string(REGEX MATCH)
+
+elseif(testname STREQUAL regex_matchall_not_enough_args)
+ string(REGEX MATCHALL)
+
+elseif(testname STREQUAL regex_replace_not_enough_args)
+ string(REGEX REPLACE)
+
+elseif(testname STREQUAL regex_bogus_mode)
+ string(REGEX BOGUS)
+
+elseif(testname STREQUAL regex_match_multiple_inputs)
+ string(REGEX MATCH ".*" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_match_bad_regex)
+ string(REGEX MATCH "(.*" v input)
+
+elseif(testname STREQUAL regex_match_empty_string)
+ string(REGEX MATCH "x*" v "")
+
+elseif(testname STREQUAL regex_matchall_multiple_inputs)
+ string(REGEX MATCHALL "input" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_matchall_bad_regex)
+ string(REGEX MATCHALL "(.*" v input)
+
+elseif(testname STREQUAL regex_matchall_empty_string)
+ string(REGEX MATCHALL "x*" v "")
+
+elseif(testname STREQUAL regex_replace_ends_with_backslash)
+ string(REGEX REPLACE "input" "output\\" v input1 input2 input3 input4)
+
+elseif(testname STREQUAL regex_replace_ends_with_escaped_backslash)
+ string(REGEX REPLACE "input" "output\\\\" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_replace_has_linefeed)
+ string(REGEX REPLACE "input" "output\\n" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL regex_replace_has_bogus_escape)
+ string(REGEX REPLACE "input" "output\\a" v input1 input2 input3 input4)
+
+elseif(testname STREQUAL regex_replace_bad_regex)
+ string(REGEX REPLACE "this (.*" "with that" v input)
+
+elseif(testname STREQUAL regex_replace_empty_string)
+ string(REGEX REPLACE "x*" "that" v "")
+
+elseif(testname STREQUAL regex_replace_out_of_range)
+ string(REGEX REPLACE "^this (.*)$" "with \\1 \\2" v "this input")
+
+elseif(testname STREQUAL compare_no_mode)
+ string(COMPARE)
+
+elseif(testname STREQUAL compare_bogus_mode)
+ string(COMPARE BOGUS)
+
+elseif(testname STREQUAL compare_not_enough_args)
+ string(COMPARE EQUAL)
+
+elseif(testname STREQUAL replace_not_enough_args)
+ string(REPLACE)
+
+elseif(testname STREQUAL replace_multiple_inputs)
+ string(REPLACE "input" "output" v input1 input2 input3 input4)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL substring_not_enough_args)
+ string(SUBSTRING)
+
+elseif(testname STREQUAL substring_bad_begin)
+ string(SUBSTRING "abcdefg" 25 100 v)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL substring_bad_end)
+ string(SUBSTRING "abcdefg" 1 100 v)
+ message(STATUS "v='${v}'")
+
+elseif(testname STREQUAL length_not_enough_args)
+ string(LENGTH)
+
+elseif(testname STREQUAL strip_not_enough_args)
+ string(STRIP)
+
+else()
+ message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'")
+
+endif()