summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy <51220084+jeremy-rifkin@users.noreply.github.com>2023-08-02 00:29:58 (GMT)
committerBrad King <brad.king@kitware.com>2023-08-02 14:07:56 (GMT)
commit20c23518d9947325198c727c77860d3877f61de5 (patch)
tree3bb5210f61a3bde80872d2063f8580ea896ff926
parent17dcd9424aefdfa10b72ad3d3bfe35e186cad02b (diff)
downloadCMake-20c23518d9947325198c727c77860d3877f61de5.zip
CMake-20c23518d9947325198c727c77860d3877f61de5.tar.gz
CMake-20c23518d9947325198c727c77860d3877f61de5.tar.bz2
set: Improve diagnostics for CACHE mode
Improve `set()` diagnostics to be more specific than given invalid arguments for CACHE mode
-rw-r--r--Source/cmSetCommand.cxx16
-rw-r--r--Tests/RunCMake/set/CacheErrors-result.txt1
-rw-r--r--Tests/RunCMake/set/CacheErrors-stderr.txt19
-rw-r--r--Tests/RunCMake/set/CacheErrors.cmake4
-rw-r--r--Tests/RunCMake/set/RunCMakeTest.cmake1
5 files changed, 37 insertions, 4 deletions
diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx
index c4bb949..c98745a 100644
--- a/Source/cmSetCommand.cxx
+++ b/Source/cmSetCommand.cxx
@@ -115,10 +115,18 @@ bool cmSetCommand(std::vector<std::string> const& args,
// we should be nice and try to catch some simple screwups if the last or
// next to last args are CACHE then they screwed up. If they used FORCE
// without CACHE they screwed up
- if ((args.back() == "CACHE") ||
- (args.size() > 1 && args[args.size() - 2] == "CACHE") ||
- (force && !cache)) {
- status.SetError("given invalid arguments for CACHE mode.");
+ if (args.back() == "CACHE") {
+ status.SetError(
+ "given invalid arguments for CACHE mode: missing type and docstring");
+ return false;
+ }
+ if (args.size() > 1 && args[args.size() - 2] == "CACHE") {
+ status.SetError(
+ "given invalid arguments for CACHE mode: missing type or docstring");
+ return false;
+ }
+ if (force && !cache) {
+ status.SetError("given invalid arguments: FORCE specified without CACHE");
return false;
}
diff --git a/Tests/RunCMake/set/CacheErrors-result.txt b/Tests/RunCMake/set/CacheErrors-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/set/CacheErrors-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/set/CacheErrors-stderr.txt b/Tests/RunCMake/set/CacheErrors-stderr.txt
new file mode 100644
index 0000000..9983160
--- /dev/null
+++ b/Tests/RunCMake/set/CacheErrors-stderr.txt
@@ -0,0 +1,19 @@
+^CMake Error at CacheErrors\.cmake:1 \(set\):
+ set given invalid arguments for CACHE mode: missing type and docstring
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at CacheErrors\.cmake:2 \(set\):
+ set given invalid arguments for CACHE mode: missing type or docstring
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at CacheErrors\.cmake:3 \(set\):
+ set given invalid arguments for CACHE mode: missing type or docstring
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at CacheErrors\.cmake:4 \(set\):
+ set given invalid arguments: FORCE specified without CACHE
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/set/CacheErrors.cmake b/Tests/RunCMake/set/CacheErrors.cmake
new file mode 100644
index 0000000..d177474
--- /dev/null
+++ b/Tests/RunCMake/set/CacheErrors.cmake
@@ -0,0 +1,4 @@
+set (var val CACHE)
+set (var val CACHE STRING)
+set (var val CACHE "")
+set (var val CACH3 STRING "" FORCE)
diff --git a/Tests/RunCMake/set/RunCMakeTest.cmake b/Tests/RunCMake/set/RunCMakeTest.cmake
index b3bd0a4..c785450 100644
--- a/Tests/RunCMake/set/RunCMakeTest.cmake
+++ b/Tests/RunCMake/set/RunCMakeTest.cmake
@@ -1,5 +1,6 @@
include(RunCMake)
+run_cmake(CacheErrors)
run_cmake(ParentScope)
run_cmake(ParentPulling)
run_cmake(ParentPullingRecursive)