diff options
author | Thomas Haller <thaller@redhat.com> | 2016-02-03 12:16:07 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-02-03 12:41:35 +0100 |
commit | 123747963a6d76fcc1d2813db5707493af1b5e84 (patch) | |
tree | de2ae763d44fdb54fe8bfad38edfba62ddafba3b /shared | |
parent | c510323368b342c500f012a67891aaec39e8fa52 (diff) | |
download | NetworkManager-123747963a6d76fcc1d2813db5707493af1b5e84.tar.gz |
nmtst: improve test macros FAIL() and ASSERT()
Fail only printed a message to stderr and exited.
Instead, print it with g_error(), which also breaks
in the debugger and produces a core-dump.
Also, it constructed the message based on an unchecked
format string and constructed a format string dynamically.
Just don't do that.
Also add a comment that these macros are discouraged because
they are cumbersome to write (requiring a test-name and a failure
message).
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-test-utils.h | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h index 0402201c28..e926c51659 100644 --- a/shared/nm-test-utils.h +++ b/shared/nm-test-utils.h @@ -962,25 +962,19 @@ _nmtst_assert_ip6_address (const char *file, int line, const struct in6_addr *ad } #define nmtst_assert_ip6_address(addr, str_expected) _nmtst_assert_ip6_address (__FILE__, __LINE__, addr, str_expected) -inline static void -FAIL(const char *test_name, const char *fmt, ...) -{ - va_list args; - char buf[500]; - - g_snprintf (buf, 500, "FAIL: (%s) %s\n", test_name, fmt); - - va_start (args, fmt); - vfprintf (stderr, buf, args); - va_end (args); - _exit (1); -} +/* Deprecated: don't use this overly verbose macro. */ +#define FAIL(test_name, fmt, ...) \ + G_STMT_START { \ + g_error ("%s:%d: FAIL[%s]: " fmt, __FILE__, __LINE__, test_name, ## __VA_ARGS__); \ + } G_STMT_END +/* Deprecated: don't use this overly verbose macro. */ #define ASSERT(x, test_name, fmt, ...) \ - if (!(x)) { \ - FAIL (test_name, fmt, ## __VA_ARGS__); \ - } - + G_STMT_START { \ + if (!(x)) { \ + FAIL (test_name, fmt, ## __VA_ARGS__); \ + } \ + } G_STMT_END #define nmtst_spawn_sync(working_directory, standard_out, standard_err, assert_exit_status, ...) \ __nmtst_spawn_sync (working_directory, standard_out, standard_err, assert_exit_status, ##__VA_ARGS__, NULL) |