提交 95435afa 编写于 作者: M Mark VanderVoord 提交者: GitHub

Merge pull request #214 from jsalling/feature/c-strings

Print escapes for C strings
...@@ -106,6 +106,7 @@ void UnityPrint(const char* string) ...@@ -106,6 +106,7 @@ void UnityPrint(const char* string)
else else
{ {
UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('x');
UnityPrintNumberHex((_U_UINT)*pch, 2); UnityPrintNumberHex((_U_UINT)*pch, 2);
} }
pch++; pch++;
...@@ -143,6 +144,7 @@ void UnityPrintLen(const char* string, const _UU32 length) ...@@ -143,6 +144,7 @@ void UnityPrintLen(const char* string, const _UU32 length)
else else
{ {
UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('x');
UnityPrintNumberHex((_U_UINT)*pch, 2); UnityPrintNumberHex((_U_UINT)*pch, 2);
} }
pch++; pch++;
...@@ -163,6 +165,8 @@ void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T s ...@@ -163,6 +165,8 @@ void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T s
} }
else else
{ {
UNITY_OUTPUT_CHAR('0');
UNITY_OUTPUT_CHAR('x');
UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1)); UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1));
} }
} }
...@@ -207,8 +211,6 @@ void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print) ...@@ -207,8 +211,6 @@ void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
{ {
_U_UINT nibble; _U_UINT nibble;
char nibbles = nibbles_to_print; char nibbles = nibbles_to_print;
UNITY_OUTPUT_CHAR('0');
UNITY_OUTPUT_CHAR('x');
while (nibbles > 0) while (nibbles > 0)
{ {
......
...@@ -1381,7 +1381,7 @@ void testNotEqualString4(void) ...@@ -1381,7 +1381,7 @@ void testNotEqualString4(void)
void testNotEqualStringLen4(void) void testNotEqualStringLen4(void)
{ {
EXPECT_ABORT_BEGIN EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN("\r\x16", "bar\n", 4); TEST_ASSERT_EQUAL_STRING_LEN("ba\r\x16", "ba\r\n", 4);
VERIFY_FAILS_END VERIFY_FAILS_END
} }
...@@ -2283,6 +2283,14 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void) ...@@ -2283,6 +2283,14 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void)
TEST_ASSERT_EQUAL(1, failures); TEST_ASSERT_EQUAL(1, failures);
} }
void testCstringsEscapeSequence(void)
{
startPutcharSpy();
UnityPrint("\x16\x10");
endPutcharSpy();
TEST_ASSERT_EQUAL_STRING("\\x16\\x10", getBufferPutcharSpy());
}
#define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) { \ #define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) { \
startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \ startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \
TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \ TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册