diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 85c60c9405..85721a3c92 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -1059,7 +1059,8 @@ Json::Value ReadJson(std::string const& jsonstr) std::string error; if (!jsonReader->parse(jsonstr.data(), jsonstr.data() + jsonstr.size(), &json, &error)) { - throw json_error(cmStrCat("failed parsing json string: "_s, error)); + throw json_error( + cmStrCat("failed parsing json string:\n"_s, jsonstr, '\n', error)); } return json; } diff --git a/Tests/RunCMake/Instrumentation/hook.cmake b/Tests/RunCMake/Instrumentation/hook.cmake index a139a37d37..09b1ecb6e0 100644 --- a/Tests/RunCMake/Instrumentation/hook.cmake +++ b/Tests/RunCMake/Instrumentation/hook.cmake @@ -53,24 +53,26 @@ foreach(i RANGE ${length}) endforeach() has_key_index(staticSystemInformation "${contents}" ${hasStaticInfo}) -has_key_index(OSName "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(OSPlatform "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(OSRelease "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(OSVersion "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(familyId "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(hostname "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(is64Bits "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(modelId "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(numberOfLogicalCPU "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(numberOfPhysicalCPU "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(processorAPICID "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(processorCacheSize "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(processorClockFrequency "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(processorName "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(totalPhysicalMemory "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(totalVirtualMemory "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(vendorID "${staticSystemInformation}" ${hasStaticInfo}) -has_key_index(vendorString "${staticSystemInformation}" ${hasStaticInfo}) +if (NOT hasStaticInfo STREQUAL UNEXPECTED) + has_key_index(OSName "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(OSPlatform "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(OSRelease "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(OSVersion "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(familyId "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(hostname "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(is64Bits "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(modelId "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(numberOfLogicalCPU "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(numberOfPhysicalCPU "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(processorAPICID "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(processorCacheSize "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(processorClockFrequency "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(processorName "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(totalPhysicalMemory "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(totalVirtualMemory "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(vendorID "${staticSystemInformation}" ${hasStaticInfo}) + has_key_index(vendorString "${staticSystemInformation}" ${hasStaticInfo}) +endif() get_filename_component(dataDir ${index} DIRECTORY) get_filename_component(v1 ${dataDir} DIRECTORY) diff --git a/Tests/RunCMake/string/JSONBadJson-result.txt b/Tests/RunCMake/string/JSONBadJson-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/string/JSONBadJson-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/string/JSONBadJson-stderr.txt b/Tests/RunCMake/string/JSONBadJson-stderr.txt new file mode 100644 index 0000000000..ba055497ae --- /dev/null +++ b/Tests/RunCMake/string/JSONBadJson-stderr.txt @@ -0,0 +1,26 @@ +CMake Error at JSONBadJson.cmake:1 \(string\): + string sub-command JSON failed parsing json string: + + invalid + + \* Line 1, Column 1 + + Syntax error: value, object or array expected. + + . +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) + + +CMake Error at JSONBadJson.cmake:2 \(string\): + string sub-command JSON failed parsing json string: + + value + + \* Line 1, Column 1 + + Syntax error: value, object or array expected. + + . +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/string/JSONBadJson.cmake b/Tests/RunCMake/string/JSONBadJson.cmake new file mode 100644 index 0000000000..8daa9f4bcc --- /dev/null +++ b/Tests/RunCMake/string/JSONBadJson.cmake @@ -0,0 +1,3 @@ +string(JSON badInput SET invalid key \"value\") +string(JSON badValue SET {} key value) +string(JSON good SET {} key \"value\") diff --git a/Tests/RunCMake/string/RunCMakeTest.cmake b/Tests/RunCMake/string/RunCMakeTest.cmake index 6baf6214fc..455b7d5ddb 100644 --- a/Tests/RunCMake/string/RunCMakeTest.cmake +++ b/Tests/RunCMake/string/RunCMakeTest.cmake @@ -6,6 +6,7 @@ run_cmake(JSONNoJson) run_cmake(JSONWrongMode) run_cmake(JSONOneArg) run_cmake(JSONNoArgs) +run_cmake(JSONBadJson) run_cmake(Append) run_cmake(AppendNoArgs)