mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 16:06:09 +00:00
Merge pull request #3542 from guillon/fix-test-asserts
Problem: test assertions not reporting the right line number
This commit is contained in:
commit
27f9be1125
@ -37,7 +37,8 @@
|
|||||||
|
|
||||||
int test_assert_success_message_errno_helper (int rc_,
|
int test_assert_success_message_errno_helper (int rc_,
|
||||||
const char *msg_,
|
const char *msg_,
|
||||||
const char *expr_)
|
const char *expr_,
|
||||||
|
int line)
|
||||||
{
|
{
|
||||||
if (rc_ == -1) {
|
if (rc_ == -1) {
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
@ -47,14 +48,15 @@ int test_assert_success_message_errno_helper (int rc_,
|
|||||||
"%s failed%s%s%s, errno = %i (%s)", expr_,
|
"%s failed%s%s%s, errno = %i (%s)", expr_,
|
||||||
msg_ ? " (additional info: " : "", msg_ ? msg_ : "",
|
msg_ ? " (additional info: " : "", msg_ ? msg_ : "",
|
||||||
msg_ ? ")" : "", zmq_errno (), zmq_strerror (zmq_errno ()));
|
msg_ ? ")" : "", zmq_errno (), zmq_strerror (zmq_errno ()));
|
||||||
TEST_FAIL_MESSAGE (buffer);
|
UNITY_TEST_FAIL (line, buffer);
|
||||||
}
|
}
|
||||||
return rc_;
|
return rc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_assert_success_message_raw_errno_helper (int rc_,
|
int test_assert_success_message_raw_errno_helper (int rc_,
|
||||||
const char *msg_,
|
const char *msg_,
|
||||||
const char *expr_)
|
const char *expr_,
|
||||||
|
int line)
|
||||||
{
|
{
|
||||||
if (rc_ == -1) {
|
if (rc_ == -1) {
|
||||||
#if defined ZMQ_HAVE_WINDOWS
|
#if defined ZMQ_HAVE_WINDOWS
|
||||||
@ -69,15 +71,13 @@ int test_assert_success_message_raw_errno_helper (int rc_,
|
|||||||
snprintf (buffer, sizeof (buffer) - 1, "%s failed%s%s%s, errno = %i",
|
snprintf (buffer, sizeof (buffer) - 1, "%s failed%s%s%s, errno = %i",
|
||||||
expr_, msg_ ? " (additional info: " : "", msg_ ? msg_ : "",
|
expr_, msg_ ? " (additional info: " : "", msg_ ? msg_ : "",
|
||||||
msg_ ? ")" : "", current_errno);
|
msg_ ? ")" : "", current_errno);
|
||||||
TEST_FAIL_MESSAGE (buffer);
|
UNITY_TEST_FAIL (line, buffer);
|
||||||
}
|
}
|
||||||
return rc_;
|
return rc_;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_assert_failure_message_raw_errno_helper (int rc_,
|
int test_assert_failure_message_raw_errno_helper (
|
||||||
int expected_errno_,
|
int rc_, int expected_errno_, const char *msg_, const char *expr_, int line)
|
||||||
const char *msg_,
|
|
||||||
const char *expr_)
|
|
||||||
{
|
{
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
buffer[sizeof (buffer) - 1] =
|
buffer[sizeof (buffer) - 1] =
|
||||||
@ -88,7 +88,7 @@ int test_assert_failure_message_raw_errno_helper (int rc_,
|
|||||||
"errno = %i, actual return value = %i",
|
"errno = %i, actual return value = %i",
|
||||||
expr_, msg_ ? " (additional info: " : "", msg_ ? msg_ : "",
|
expr_, msg_ ? " (additional info: " : "", msg_ ? msg_ : "",
|
||||||
msg_ ? ")" : "", expected_errno_, rc_);
|
msg_ ? ")" : "", expected_errno_, rc_);
|
||||||
TEST_FAIL_MESSAGE (buffer);
|
UNITY_TEST_FAIL (line, buffer);
|
||||||
} else {
|
} else {
|
||||||
#if defined ZMQ_HAVE_WINDOWS
|
#if defined ZMQ_HAVE_WINDOWS
|
||||||
int current_errno = WSAGetLastError ();
|
int current_errno = WSAGetLastError ();
|
||||||
@ -102,7 +102,7 @@ int test_assert_failure_message_raw_errno_helper (int rc_,
|
|||||||
expr_, msg_ ? " (additional info: " : "",
|
expr_, msg_ ? " (additional info: " : "",
|
||||||
msg_ ? msg_ : "", msg_ ? ")" : "", expected_errno_,
|
msg_ ? msg_ : "", msg_ ? ")" : "", expected_errno_,
|
||||||
current_errno);
|
current_errno);
|
||||||
TEST_FAIL_MESSAGE (buffer);
|
UNITY_TEST_FAIL (line, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rc_;
|
return rc_;
|
||||||
|
@ -40,16 +40,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
int test_assert_success_message_errno_helper (int rc_,
|
int test_assert_success_message_errno_helper (int rc_,
|
||||||
const char *msg_,
|
const char *msg_,
|
||||||
const char *expr_);
|
const char *expr_,
|
||||||
|
int line);
|
||||||
|
|
||||||
int test_assert_success_message_raw_errno_helper (int rc_,
|
int test_assert_success_message_raw_errno_helper (int rc_,
|
||||||
const char *msg_,
|
const char *msg_,
|
||||||
const char *expr_);
|
const char *expr_,
|
||||||
|
int line);
|
||||||
|
|
||||||
int test_assert_failure_message_raw_errno_helper (int rc_,
|
int test_assert_failure_message_raw_errno_helper (
|
||||||
int expected_errno_,
|
int rc_, int expected_errno_, const char *msg_, const char *expr_, int line);
|
||||||
const char *msg_,
|
|
||||||
const char *expr_);
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Macros extending Unity's TEST_ASSERT_* macros in a similar fashion.
|
// Macros extending Unity's TEST_ASSERT_* macros in a similar fashion.
|
||||||
@ -70,7 +70,7 @@ int test_assert_failure_message_raw_errno_helper (int rc_,
|
|||||||
// determined by zmq_errno(), and the additional 'msg'.
|
// determined by zmq_errno(), and the additional 'msg'.
|
||||||
// In case of success, the result of the macro is the result of 'expr'.
|
// In case of success, the result of the macro is the result of 'expr'.
|
||||||
#define TEST_ASSERT_SUCCESS_MESSAGE_ERRNO(expr, msg) \
|
#define TEST_ASSERT_SUCCESS_MESSAGE_ERRNO(expr, msg) \
|
||||||
test_assert_success_message_errno_helper (expr, msg, #expr)
|
test_assert_success_message_errno_helper (expr, msg, #expr, __LINE__)
|
||||||
|
|
||||||
// Asserts that the libzmq API 'expr' is successful. In case of a failure, the
|
// Asserts that the libzmq API 'expr' is successful. In case of a failure, the
|
||||||
// assertion message includes the literal 'expr' and the error code.
|
// assertion message includes the literal 'expr' and the error code.
|
||||||
@ -81,7 +81,7 @@ int test_assert_failure_message_raw_errno_helper (int rc_,
|
|||||||
// If an additional message should be displayed in case of a failure, use
|
// If an additional message should be displayed in case of a failure, use
|
||||||
// TEST_ASSERT_SUCCESS_MESSAGE_ERRNO.
|
// TEST_ASSERT_SUCCESS_MESSAGE_ERRNO.
|
||||||
#define TEST_ASSERT_SUCCESS_ERRNO(expr) \
|
#define TEST_ASSERT_SUCCESS_ERRNO(expr) \
|
||||||
test_assert_success_message_errno_helper (expr, NULL, #expr)
|
test_assert_success_message_errno_helper (expr, NULL, #expr, __LINE__)
|
||||||
|
|
||||||
// Asserts that the socket API 'expr' is successful. In case of a failure, the
|
// Asserts that the socket API 'expr' is successful. In case of a failure, the
|
||||||
// assertion message includes the literal 'expr' and the error code.
|
// assertion message includes the literal 'expr' and the error code.
|
||||||
@ -89,14 +89,15 @@ int test_assert_failure_message_raw_errno_helper (int rc_,
|
|||||||
// TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd, buffer, 64, 0));
|
// TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd, buffer, 64, 0));
|
||||||
// In case of success, the result of the macro is the result of 'expr'.
|
// In case of success, the result of the macro is the result of 'expr'.
|
||||||
#define TEST_ASSERT_SUCCESS_RAW_ERRNO(expr) \
|
#define TEST_ASSERT_SUCCESS_RAW_ERRNO(expr) \
|
||||||
test_assert_success_message_raw_errno_helper (expr, NULL, #expr)
|
test_assert_success_message_raw_errno_helper (expr, NULL, #expr, __LINE__)
|
||||||
|
|
||||||
// Asserts that the socket API 'expr' is not successful, and the error code is
|
// Asserts that the socket API 'expr' is not successful, and the error code is
|
||||||
// 'error_code'. In case of an unexpected succces, or a failure with an
|
// 'error_code'. In case of an unexpected succces, or a failure with an
|
||||||
// unexpected error code, the assertion message includes the literal 'expr'
|
// unexpected error code, the assertion message includes the literal 'expr'
|
||||||
// and, in case of a failure, the actual error code.
|
// and, in case of a failure, the actual error code.
|
||||||
#define TEST_ASSERT_FAILURE_RAW_ERRNO(error_code, expr) \
|
#define TEST_ASSERT_FAILURE_RAW_ERRNO(error_code, expr) \
|
||||||
test_assert_failure_message_raw_errno_helper (expr, error_code, NULL, #expr)
|
test_assert_failure_message_raw_errno_helper (expr, error_code, NULL, \
|
||||||
|
#expr, __LINE__)
|
||||||
|
|
||||||
// Asserts that the libzmq API 'expr' is not successful, and the error code is
|
// Asserts that the libzmq API 'expr' is not successful, and the error code is
|
||||||
// 'error_code'. In case of an unexpected succces, or a failure with an
|
// 'error_code'. In case of an unexpected succces, or a failure with an
|
||||||
|
Loading…
x
Reference in New Issue
Block a user