Add string escape function or escape functionality built into CAPTURE macro

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

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
cpp
领域
testing-qa

调研方向

首先检查 CAPTURE 宏以及 issue 中关于控制字符输出的示例。比较提议的 escape() 函数、CAPTURE 的内置行为和 CAPTURE_ESCAPED() 替代方案,然后确定哪种方法应生成可读的转义输出,同时避免回车符导致消息乱码。

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

描述

The problem

This:

const auto asciiControlsString =
  "null \0 tab \t carriage return \r line feed \n whatever this is \xf quotation mark \" chars"sv;
CAPTURE(asciiControlsString);

results in a message like this:

with message:
 line feed rolsString := "null  tab      carriage return
   whatever this is  quotation mark " chars"

Notice that because of carriage return \r character it garbles up the message:

 line feed rolsString := "null  tab      carriage return
 ^         ^
text       remnants of the variable name
after \r

Proposed solution

Having an escape() function to escape non-printable and some special characters (like carriage return) provided by Catch2 would be wonderful so people don't have to reinvent the wheel every time.

The result of code like this:

CAPTURE(escape(asciiControlsString));

can look like this:

with message:
  escape(asciiControlsString) := "null \0 tab \t carriage return \r
  line feed \n whatever this is  quotation mark " chars"

Alternatively CAPTURE() macro can incorporate this functionality, or Catch2 can provide additional macro with such functionality, e.g. CAPTURE_ESCAPED().

主要语言
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 摘要。