Exposing `BinaryExpr` members

Abierto
#2,982 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
cpp
Área
testing-qa

Línea de trabajo

Comienza en BinaryExpr en src/catch2/internal/catch_decomposer.hpp y revisa cómo Decomposer almacena los operandos y el operador. Se considera terminado cuando el lado izquierdo, el lado derecho y el operador se exponen mediante los const accessors solicitados, actualizando o añadiendo las pruebas existentes relevantes si el proyecto requiere cobertura.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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?

Lenguaje dominante
C++
Estrellas
21.6k
Forks
3.4k
Merge medio
3 d 12 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de catchorg/Catch2

Todos los issues de catchorg/Catch2

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.