I got it working based on an amalgamation of the udemy course info and the example you linked . Here's my working code which produced the very nice error message :
At line (11): "Expected PTRESULT_BUSY Was PTRESULT_ERROR"
#ifndef _TESTHELPERPTRESULT_H
#define _TESTHELPERPTRESULT_H
#include <string.h>
#include "header_with_ptresult_t_defined.h"
static char * HelperPTResultNames[] = {
"PTRESULT_IDLE",
"PTRESULT_BUSY",
"PTRESULT_OK",
"PTRESULT_ERROR",
"PTRESULT_INVALID"
};
char HelperPTResultFailMsg[100];
static inline void AssertEqualPTResult(const ptresult_t expected, const ptresult_t actual, const UNITY_LINE_TYPE linenum, const char * msg)
{
if ( expected != actual )
{
HelperPTResultFailMsg[0] = 0;
strcat( HelperPTResultFailMsg, "Expected " );
if ( expected <= PTRESULT_MAX ) strcat( HelperPTResultFailMsg, HelperPTResultNames[expected] );
else sprintf( &HelperPTResultFailMsg[strlen( HelperPTResultFailMsg )], "%u", expected );
strcat( HelperPTResultFailMsg, " Was " );
if ( expected <= PTRESULT_MAX ) strcat( HelperPTResultFailMsg, HelperPTResultNames[actual] );
else sprintf( &HelperPTResultFailMsg[strlen( HelperPTResultFailMsg )], "%u", actual );
UNITY_TEST_FAIL( linenum, HelperPTResultFailMsg );
}
}
#define UNITY_TEST_ASSERT_EQUAL_PTRESULT_T(e, a, l, m) AssertEqualPTResult(e, a, l, m);
#define TEST_ASSERT_EQUAL_PTRESULT_T(e, a) UNITY_TEST_ASSERT_EQUAL_PTRESULT(e, a, __LINE__, NULL);
#define TEST_ASSERT_EQUAL_PTRESULT_T_MESSAGE( e, a ) UNITY_TEST_ASSERT_EQUAL_PTRESULT(e, a, __LINE__, NULL);
#endif // _TESTHELPERPTRESULT_H
I opted to break these into multiple files for each type (or closely related types) in order to remind myself what was in the file , rather than having one large "UnityHelpers.h" file depend on a lot of outside header files which would start to intermingle the tests in a way that I don't want .
I'll probably refactor out the error message character array into a generic unity_helper.h file .
Finally , as I noted , there was a difference between example 3 and the udemy example . Example 3 used a combination of a .h and a .c source file , while
the udemy example used just a .h with static inline functions as above
in my code . Can you comment on the differences between these two
approaches ?
Thanks again !
--David