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

Aperta
#2,985 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
testing-qa

Direzione di ricerca

Inizia esaminando la macro CATCH_INTERNAL_LINEINFO, Catch::SourceLineInfo e gli entry point FAIL, FAIL_CHECK, WARN e INFO descritti nell’issue. Confronta l’override limitato all’ambito richiesto con il comportamento esistente della macro e con gli argomenti in stile std::source_location. Il lavoro è completato quando le assertion di segnalazione possono usare una posizione del sorgente fornita tramite un’API pubblica intenzionale, preservando il normale comportamento della posizione al di fuori di tale ambito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
21.6k
Fork
3.4k
Merge medio
3g 12h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di catchorg/Catch2

Tutte le issue di catchorg/Catch2

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.