Add a means to override CATCH_INTERNAL_LINEINFO and specify a different source location

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

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

首先检查 issue 中描述的 CATCH_INTERNAL_LINEINFO 宏、Catch::SourceLineInfo,以及 FAIL、FAIL_CHECK、WARN 和 INFO 入口点。将所请求的作用域覆盖与现有宏行为以及 std::source_location 风格的参数进行比较。完成的标准是:报告断言可以通过有意设计的公共 API 使用所提供的源位置,同时在该作用域之外保留正常的位置行为。

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

描述

Description
When integrating other reporting into catch2, e.g. https://github.com/rollbear/trompeloeil/blob/main/include/catch2/trompeloeil.hpp or a https://doc.qt.io/qt-6/qtlogging.html#QtMessageHandler-typedef, it's often the case that you already have source_location about where the message really originates from. But right now there's no way to call FAIL, FAIL_CHECK, WARN, etc and tell them this actual origin. The best you can do is format it into the message somehow, but that still leaves IDE hints and such taking you to the wrong point - where the macro was expanded (in the plumbing code between libraries).

It's possible (albeit hacky) to acheive this by doing something like

char const * file = ...;
int line = ...;
#pragma push_macro("CATCH_INTERNAL_LINEINFO")
#define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo(file, line)
FAIL(...)
#pragma pop_macro("CATCH_INTERNAL_LINEINFO")

But redefining the CATCH_INTERNAL_LINEINFO macro is clearly not an intended public API :-).

It would be nice if there was a scoped macro like CATCH_LINEINFO(file, line, column, function) which operated a bit like INFO - while it was in scope, any assertions that report would be attributed to this provided location instead of the site of the actual actual macro expansion. I've chosen those 4 args to align with std::source_location, but you might not always have all 4 - having only file and line is certainly common.

This way error callbacks from other libraries could be routed into FAIL, INFO, WARN, etc and attributed the source of the assertion, rather than the plumbing code between e.g. trompeloeil and catch2.

Additional context
See https://github.com/rollbear/trompeloeil/pull/350 - basically just being mildly annoyed that otherwise-excellent IDE experience (error list, detailed failure inlays) that catch2 and C++ TestMate deliver doesn't work as well when on mesages that originate from trompeloil mocks, qWarning, or other such sources.

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