Exposing `BinaryExpr` members

オープン
#2,982 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
cpp
領域
testing-qa

調査の方向性

src/catch2/internal/catch_decomposer.hpp の BinaryExpr から始めて、Decomposer がオペランドと演算子をどのように保持しているかを確認します。左辺、右辺、演算子を要求された const accessor を通じて公開し、プロジェクトでカバレッジが必要な場合は、関連する既存のテストを更新するか追加すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Currently, Catch only provides string versions of the left- and right-hand side when tests fail. For instance, something like:

  CHECK( v1 == v2 )
with expansion:
  { 1, 2, 3 } == { 1, 3, 4 }

This is a good start, but it isn't enough when comparing more complicated structures, where you want some more information. pytest, for instance, will print a full diff. So you'll get something more like:

  CHECK( v1 == v2 )
with expansion:
  { 1, 2, 3 } == { 1, 3, 4 }
  
  At index 1 diff: 2 != 3
  
  Full diff:
    [
        1,
  -     2,
        3,
  +     4,
    ]

Which is a lot more useful. There doesn't seem to be any way to provide more specific messages for errors. The Matcher API has no relevant hook for this.

We looked into trying to do this on our own — BinaryExpr<T, U> has the T and the U, but they are both private members with no accessors. So in order to attempt to implement something like the above, we would have to either (a) reimplement/copy the Decomposer logic, which is involved or (b) do shenanigans relying on just knowing where in BinaryExpr the T and the U are and just yolo-reinterpret-casting at specific memory locations. Neither of which I actually want to do.

It would be easier to simply add to BinaryExpr these getters:

constexpr auto lhs() const -> auto const& { return m_lhs; }
constexpr auto rhs() const -> auto const& { return m_rhs; }
constexpr auto op() const -> StringRef { return m_op; }

(Returning auto const& instead of LhsT const& since LhsT could be some T& and I'd want to unconditionally return T const& there, and auto const& is just an easier way to achieve that than something like std::remove_reference_t<LhsT> const&).

Would you be open to that addition?

主要言語
C++
スター
21.6k
フォーク
3.4k
平均マージ
3日 12時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

catchorg/Catch2 のほかの issue

catchorg/Catch2 の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。