diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 5b03b883ea..0c557f9ff0 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -409,6 +409,9 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs, // now recursively invoke IsTrue to handle the values inside the // parenthetical expression auto const value = this->IsTrue(subExpr, errorString, status); + if (!errorString.empty()) { + return false; + } *arg = cmExpandedCommandArgument(bool2string(value), true); argOpen = std::next(arg); // remove the now evaluated parenthetical expression diff --git a/Tests/RunCMake/if/InvalidArgumentInParenthesis-result.txt b/Tests/RunCMake/if/InvalidArgumentInParenthesis-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/if/InvalidArgumentInParenthesis-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/if/InvalidArgumentInParenthesis-stderr.txt b/Tests/RunCMake/if/InvalidArgumentInParenthesis-stderr.txt new file mode 100644 index 0000000000..1dec50f03e --- /dev/null +++ b/Tests/RunCMake/if/InvalidArgumentInParenthesis-stderr.txt @@ -0,0 +1,8 @@ +^CMake Error at InvalidArgumentInParenthesis\.cmake:1 \(if\): + if given arguments: + + "\(" "A" "B" "\)" "OR" "\(" "" "\)" + + Unknown arguments specified +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\)$ diff --git a/Tests/RunCMake/if/InvalidArgumentInParenthesis.cmake b/Tests/RunCMake/if/InvalidArgumentInParenthesis.cmake new file mode 100644 index 0000000000..7969b7c74f --- /dev/null +++ b/Tests/RunCMake/if/InvalidArgumentInParenthesis.cmake @@ -0,0 +1,5 @@ +if((A B) OR ("$ENV{NOT_AN_ENV_VARIABLE}")) + message(STATUS "Invalid evaluated to TRUE") +else() + message(STATUS "Invalid evaluated to FALSE") +endif() diff --git a/Tests/RunCMake/if/RunCMakeTest.cmake b/Tests/RunCMake/if/RunCMakeTest.cmake index 366e8a3104..ed01091f22 100644 --- a/Tests/RunCMake/if/RunCMakeTest.cmake +++ b/Tests/RunCMake/if/RunCMakeTest.cmake @@ -1,6 +1,7 @@ include(RunCMake) run_cmake(InvalidArgument1) +run_cmake(InvalidArgumentInParenthesis) run_cmake(exists) if(NOT MSYS) # permissions and symbolic links are broken on MSYS diff --git a/Tests/RunCMake/while/InvalidArgument-result.txt b/Tests/RunCMake/while/InvalidArgument-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/while/InvalidArgument-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/while/InvalidArgument-stderr.txt b/Tests/RunCMake/while/InvalidArgument-stderr.txt new file mode 100644 index 0000000000..5ab8ad8e8b --- /dev/null +++ b/Tests/RunCMake/while/InvalidArgument-stderr.txt @@ -0,0 +1,8 @@ +^CMake Error at InvalidArgument\.cmake:2 \(while\): + while\(\) given incorrect arguments: + + "\(" "A" "B" "\)" "OR" "\(" "" "\)" + + Unknown arguments specified +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\)$ diff --git a/Tests/RunCMake/while/InvalidArgument.cmake b/Tests/RunCMake/while/InvalidArgument.cmake new file mode 100644 index 0000000000..13323caa70 --- /dev/null +++ b/Tests/RunCMake/while/InvalidArgument.cmake @@ -0,0 +1,6 @@ +cmake_policy(SET CMP0130 NEW) +while((A B) OR ("$ENV{NOT_AN_ENV_VARIABLE}")) + message(STATUS "Invalid evaluated to TRUE") + return() +endwhile() +message(STATUS "Invalid evaluated to FALSE") diff --git a/Tests/RunCMake/while/RunCMakeTest.cmake b/Tests/RunCMake/while/RunCMakeTest.cmake index d018b16291..315d48956d 100644 --- a/Tests/RunCMake/while/RunCMakeTest.cmake +++ b/Tests/RunCMake/while/RunCMakeTest.cmake @@ -1,6 +1,7 @@ include(RunCMake) run_cmake(MissingArgument) +run_cmake(InvalidArgument) run_cmake(EndMissing) run_cmake(EndMismatch) run_cmake(EndAlone)