Description
Currently there are only two hardcoded "slots" for detail, which are generally used for "Function" and "Argument" by CMock.
The details are also inside unity_internals.h
, so mostly hidden to regular users.
I was thinking of submitting a PR expanding this to be a public-facing, stack-based API, to avoid having to pre-construct long strings (to use as message) when wanting to locate an error further, e.g. Section first_iteration, Function do_stuff, Argument list_of_structs, Element 4, Member value
.
In addition to UnityAssertEqual_
implementations allowing more granular information than "some HEX16 in that argument is wrong", I see this also being useful a variety of other applications, like labeling parametrized tests and sections (not just inside the test itself, but also setup/teardown), and simplifying some of the existing functions (e.g. UnityAssertEqual*Array
).
Implementation thoughts:
- Implement an array of strings, mapping "detail id" to human-readable, with the default value being
{UNITY_DETAIL1_NAME, UNITY_DETAIL2_NAME}
(i.e. "Function", "Argument"). Additional id strings may be "Element", "Member", "Byte", "Bit", "File", "Line", "Section", "Case". - Limit the number of stack entries to keep
UNITY_STORAGE_T
size low (configured with define, with 2 being the default) - Stack should store "detail id" (uint8_t should be enough) and value (char*). For maximum memory efficiency, this could be two arrays in
UNITY_STORAGE_T
, and one counter. In the default settings with 2 slots, this would only increase the size ofUNITY_STORAGE_T
by 3-6 bytes (1-4 for stack counter (UNITY_COUNTER_TYPE
), 2x1 for detail-ids. The pointers already exist for the current slots). - Potentially some way to mark some details as numeric (with value being interpreted as uintptr_t instead of char*), to support array/line numbers without string-conversion. Maybe end the string with a
#
or some other marker? - To retain backwards-compatiblity,
UNITY_SET_DETAIL
,UNITY_SET_DETAILS
should keep their current functionality, but pushing to the detail stack instead of using hardcoded slots, andUNITY_CLR_DETAILS
should be able to pop either the single "detail1", or both.
Please let me know if you would consider accepting such a PR (and a potential follow-up to CMock for better integration there), or have any feedback.