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

First (far from done) implementation for printf style formatting for … #500

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
printf style formatting support for UnityAssertNumbersWithin
  • Loading branch information
alariois committed May 7, 2020
commit 4aec5d9f240e4e00ff258a67708c9eef83dde892
13 changes: 10 additions & 3 deletions src/unity.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,9 @@ void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
void UnityAssertNumbersWithin(const UNITY_UINT delta,
const UNITY_INT expected,
const UNITY_INT actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
const UNITY_DISPLAY_STYLE_T style,
const char* msg VA_ARGS_IF_ENABLED)
{
RETURN_IF_FAIL_OR_IGNORE;

Expand Down Expand Up @@ -1273,7 +1273,14 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta,
UnityPrintNumberByStyle(expected, style);
UnityPrint(UnityStrWas);
UnityPrintNumberByStyle(actual, style);
UnityAddMsgIfSpecified(msg);
#ifdef UNITY_INCLUDE_PRINT_FORMATTED
va_list va;
va_start(va, msg);
UnityAddMsgIfSpecified_TEMPORARY_VA_TEST(msg, va);
va_end(va);
#else
UnityAddMsgIfSpecified_TEMPORARY_VA_TEST(msg);
#endif
UNITY_FAIL_AND_BAIL;
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/unity.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ void verifyTest(void);
#define TEST_ASSERT_LESS_OR_EQUAL_CHAR_MESSAGE(threshold, actual, ...) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_CHAR((threshold), (actual), __LINE__, __VA_ARGS__)
#endif
/* Integer Ranges (of all sizes) */
#ifndef UNITY_INCLUDE_PRINT_FORMATTED
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_INT8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_INT16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT16_WITHIN((delta), (expected), (actual), __LINE__, (message))
Expand All @@ -670,7 +671,25 @@ void verifyTest(void);
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_CHAR_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_CHAR_WITHIN((delta), (expected), (actual), __LINE__, (message))

#else
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_INT8_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_INT16_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_INT16_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_INT32_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_INT32_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_INT64_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_INT64_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_UINT_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_UINT8_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_UINT8_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_UINT16_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_UINT16_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_UINT32_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_UINT32_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_UINT64_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_UINT64_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_size_t_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_UINT_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_HEX8_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_HEX16_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#define TEST_ASSERT_CHAR_WITHIN_MESSAGE(delta, expected, actual, ...) UNITY_TEST_ASSERT_CHAR_WITHIN((delta), (expected), (actual), __LINE__, __VA_ARGS__)
#endif
/* Integer Array Ranges (of all sizes) */
#define TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
Expand Down
Loading