Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question/proposal: print execution context #653

Open
tim-ist opened this issue Jan 21, 2023 · 1 comment
Open

Question/proposal: print execution context #653

tim-ist opened this issue Jan 21, 2023 · 1 comment

Comments

@tim-ist
Copy link

tim-ist commented Jan 21, 2023

Hi, I am new to Unity so I might be inventing a wheel here.

The idea is to be able to print some variables together with the assertion message, e.g., if an assertion is inside a loop, it would be handy to know the loop iteration when it fails:

TEST_ASSERT_EQUAL_UINT32_MESSAGE(exp, val, CONTEXT_MSG("i=%d", i));

A simplistic implementation is as follows. Of course it assumes that there's only one assertion reported per test.

#define CONTEXT_STRING_LEN 256
char test_context_msg[CONTEXT_STRING_LEN];

#define CONTEXT_MSG(format, ...) (snprintf(test_context_msg, CONTEXT_STRING_LEN, "[context]: " format __VA_OPT__(,) __VA_ARGS__), test_context_msg)

Update: Here it was proposed to add __VA_ARGS__ directly to all _MESSAGE macros. That approach is definitely much better than my proposal above. Is anyone working on that? If not, I could try implementing it.

@AndersonMartins1
Copy link

É uma excelente ideia buscar melhorias na funcionalidade de mensagens de assert no Unity, especialmente para incluir informações de contexto úteis, como o número de iteração de um loop. A proposta de adicionar VA_ARGS diretamente a todas as macros _MESSAGE parece ser uma abordagem mais elegante e eficiente do que a proposta inicial de usar snprintf em uma macro personalizada. Se ninguém está trabalhando nisso atualmente, você certamente poderia tentar implementar essa melhoria. Seria ótimo ver essa funcionalidade aprimorada no Unity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants