mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-14 07:03:44 +01:00
Revise log-testing macros to dump the actual log contents on failure
This commit is contained in:
parent
ae3ea9a7a1
commit
3705ee8fe4
@ -210,3 +210,18 @@ mock_saving_logv(int severity, log_domain_mask_t domain,
|
|||||||
smartlist_add(saved_logs, e);
|
smartlist_add(saved_logs, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mock_dump_saved_logs(void)
|
||||||
|
{
|
||||||
|
if (saved_logs == NULL) {
|
||||||
|
puts(" Captured logs: NULL");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
puts(" Captured logs:");
|
||||||
|
SMARTLIST_FOREACH_BEGIN(saved_logs, const mock_saved_log_entry_t *, m) {
|
||||||
|
printf("% 5d. %s: %s\n", m_sl_idx + 1,
|
||||||
|
log_level_to_string(m->severity),
|
||||||
|
escaped(m->generated_msg));
|
||||||
|
} SMARTLIST_FOREACH_END(m);
|
||||||
|
}
|
||||||
|
@ -26,40 +26,50 @@ int mock_saved_log_has_message(const char *msg);
|
|||||||
int mock_saved_log_has_message_containing(const char *msg);
|
int mock_saved_log_has_message_containing(const char *msg);
|
||||||
int mock_saved_log_has_severity(int severity);
|
int mock_saved_log_has_severity(int severity);
|
||||||
int mock_saved_log_has_entry(void);
|
int mock_saved_log_has_entry(void);
|
||||||
|
void mock_dump_saved_logs(void);
|
||||||
|
|
||||||
|
#define assert_log_predicate(predicate, failure_msg) \
|
||||||
|
do { \
|
||||||
|
if (!(predicate)) { \
|
||||||
|
tt_fail_msg((failure_msg)); \
|
||||||
|
mock_dump_saved_logs(); \
|
||||||
|
TT_EXIT_TEST_FUNCTION; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define expect_log_msg(str) \
|
#define expect_log_msg(str) \
|
||||||
tt_assert_msg(mock_saved_log_has_message(str), \
|
assert_log_predicate(mock_saved_log_has_message(str), \
|
||||||
"expected log to contain " # str);
|
"expected log to contain " # str);
|
||||||
|
|
||||||
#define expect_log_msg_containing(str) \
|
#define expect_log_msg_containing(str) \
|
||||||
tt_assert_msg(mock_saved_log_has_message_containing(str), \
|
assert_log_predicate(mock_saved_log_has_message_containing(str), \
|
||||||
"expected log to contain " # str);
|
"expected log to contain " # str);
|
||||||
|
|
||||||
#define expect_single_log_msg_containing(str) \
|
#define expect_single_log_msg_containing(str) \
|
||||||
do { \
|
do { \
|
||||||
tt_assert_msg(mock_saved_log_has_message_containing(str), \
|
assert_log_predicate(mock_saved_log_has_message_containing(str), \
|
||||||
"expected log to contain " # str); \
|
"expected log to contain " # str); \
|
||||||
tt_int_op(smartlist_len(mock_saved_logs()), OP_EQ, 1); \
|
tt_int_op(smartlist_len(mock_saved_logs()), OP_EQ, 1); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define expect_no_log_msg(str) \
|
#define expect_no_log_msg(str) \
|
||||||
tt_assert_msg(!mock_saved_log_has_message(str), \
|
assert_log_predicate(!mock_saved_log_has_message(str), \
|
||||||
"expected log to not contain " # str);
|
"expected log to not contain " # str);
|
||||||
|
|
||||||
#define expect_log_severity(severity) \
|
#define expect_log_severity(severity) \
|
||||||
tt_assert_msg(mock_saved_log_has_severity(severity), \
|
assert_log_predicate(mock_saved_log_has_severity(severity), \
|
||||||
"expected log to contain severity " # severity);
|
"expected log to contain severity " # severity);
|
||||||
|
|
||||||
#define expect_no_log_severity(severity) \
|
#define expect_no_log_severity(severity) \
|
||||||
tt_assert_msg(!mock_saved_log_has_severity(severity), \
|
assert_log_predicate(!mock_saved_log_has_severity(severity), \
|
||||||
"expected log to not contain severity " # severity);
|
"expected log to not contain severity " # severity);
|
||||||
|
|
||||||
#define expect_log_entry() \
|
#define expect_log_entry() \
|
||||||
tt_assert_msg(mock_saved_log_has_entry(), \
|
assert_log_predicate(mock_saved_log_has_entry(), \
|
||||||
"expected log to contain entries");
|
"expected log to contain entries");
|
||||||
|
|
||||||
#define expect_no_log_entry() \
|
#define expect_no_log_entry() \
|
||||||
tt_assert_msg(!mock_saved_log_has_entry(), \
|
assert_log_predicate(!mock_saved_log_has_entry(), \
|
||||||
"expected log to not contain entries");
|
"expected log to not contain entries");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user