Skip to content

Commit 95435af

Browse files
authored
Merge pull request #214 from jsalling/feature/c-strings
Print escapes for C strings
2 parents 68a43b8 + de39186 commit 95435af

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/unity.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ void UnityPrint(const char* string)
106106
else
107107
{
108108
UNITY_OUTPUT_CHAR('\\');
109+
UNITY_OUTPUT_CHAR('x');
109110
UnityPrintNumberHex((_U_UINT)*pch, 2);
110111
}
111112
pch++;
@@ -143,6 +144,7 @@ void UnityPrintLen(const char* string, const _UU32 length)
143144
else
144145
{
145146
UNITY_OUTPUT_CHAR('\\');
147+
UNITY_OUTPUT_CHAR('x');
146148
UnityPrintNumberHex((_U_UINT)*pch, 2);
147149
}
148150
pch++;
@@ -163,6 +165,8 @@ void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T s
163165
}
164166
else
165167
{
168+
UNITY_OUTPUT_CHAR('0');
169+
UNITY_OUTPUT_CHAR('x');
166170
UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1));
167171
}
168172
}
@@ -207,8 +211,6 @@ void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
207211
{
208212
_U_UINT nibble;
209213
char nibbles = nibbles_to_print;
210-
UNITY_OUTPUT_CHAR('0');
211-
UNITY_OUTPUT_CHAR('x');
212214

213215
while (nibbles > 0)
214216
{

test/tests/testunity.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ void testNotEqualString4(void)
13811381
void testNotEqualStringLen4(void)
13821382
{
13831383
EXPECT_ABORT_BEGIN
1384-
TEST_ASSERT_EQUAL_STRING_LEN("\r\x16", "bar\n", 4);
1384+
TEST_ASSERT_EQUAL_STRING_LEN("ba\r\x16", "ba\r\n", 4);
13851385
VERIFY_FAILS_END
13861386
}
13871387

@@ -2283,6 +2283,14 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void)
22832283
TEST_ASSERT_EQUAL(1, failures);
22842284
}
22852285

2286+
void testCstringsEscapeSequence(void)
2287+
{
2288+
startPutcharSpy();
2289+
UnityPrint("\x16\x10");
2290+
endPutcharSpy();
2291+
TEST_ASSERT_EQUAL_STRING("\\x16\\x10", getBufferPutcharSpy());
2292+
}
2293+
22862294
#define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) { \
22872295
startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \
22882296
TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \

0 commit comments

Comments
 (0)