JSON failed parsing json string

未关闭
#2,999 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
cmake, cpp

调研方向

从 lib/cmake/Catch2/CatchAddTests.cmake 开始,重点关注第 138 行和第 235 行附近的 JSON 解析,以及 commit 7d7b2f89f24cbd277f6eb6912705e5e13c68a3c7 的变更。在 CMake 3.22.1 或 3.25.1 上使用报告中的 Catch 输出复现测试发现,并在解析前检查 listing_output。在报告的平台上,catch_discover_tests 能够在不出现 JSON 解析错误的情况下完成,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

I am recently getting the following error with latest devel release (ceed2684):

CMake Error at /path/to/Catch2/lib/cmake/Catch2/CatchAddTests.cmake:138 (string):
  string sub-command JSON failed parsing json string: * Line 1, Column 6

    Missing ',' or ']' in array declaration

  .
Call Stack (most recent call first):
  /path/to/Catch2/lib/cmake/Catch2/CatchAddTests.cmake:235 (catch_discover_tests_impl)

Line 138 of CatchAddTests.cmake is:

string(JSON version GET "${listing_output}" "version")

adding a CMake message just before the line for the value listing_output yields:

{
  "version": 1,
  "metadata": {
    "name": "ut_saccades_frameworkd",
    "rng-seed": 994172703,
    "catch2-version": "3.8.1"
  },
  "listings": {
    "tests": [
      {

Expected behavior

I've isolated the commit which causes the error:

7d7b2f89f24cbd277f6eb6912705e5e13c68a3c7
Support adding test tags as CTest labels in catch_discover_tests

which does indeed add those lines to CatchAddTests.cmake.:

-  # Parse output
-  foreach(line ${output})
-    set(test "${line}")
+  # Parse JSON output for list of tests/class names/tags
+  string(JSON version GET "${listing_output}" "version")
+  if (NOT version STREQUAL "1")
+    message(FATAL_ERROR "Unsupported catch output version: '${version}'")
+  endif()
+
+  # Speed-up reparsing by cutting away unneeded parts of JSON.
+  string(JSON test_listing GET "${listing_output}" "listings" "tests")
+  string(JSON num_tests LENGTH "${test_listing}")
+  # CMake's foreach-RANGE is inclusive, so we have to subtract 1
+  math(EXPR num_tests "${num_tests} - 1")

Reproduction steps

Haven't done this yet but will try to reproduce with small example if necessary.

Platform information:

  • Windows 11:
    • Visual Studio Community 17.4.3
    • CMake: 3.25.1
  • Ubuntu 22.04:
    • gcc: 11.4
    • CMake: 3.22.1
  • Catch: ceed2684

Additional context
.

主要语言
C++
星标
21.6k
派生
3.4k
平均合并
3 天 12 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

catchorg/Catch2 的其他 Issue

查看 catchorg/Catch2 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。