mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
added g_test_trap_assert_stdout_unmatched() and
2007-12-18 13:45:23 Tim Janik <timj@imendio.com> * glib/gtestutils.[hc]: added g_test_trap_assert_stdout_unmatched() and g_test_trap_assert_stderr_unmatched(), based on a suggestion by Mathias Hasselmann. reworked g_test_trap_assertions() to use flags to encode assertion semantics, fixes #504227. svn path=/trunk/; revision=6151
This commit is contained in:
parent
2df62bf0ed
commit
ac1723ea97
@ -1,3 +1,10 @@
|
||||
2007-12-18 13:45:23 Tim Janik <timj@imendio.com>
|
||||
|
||||
* glib/gtestutils.[hc]: added g_test_trap_assert_stdout_unmatched() and
|
||||
g_test_trap_assert_stderr_unmatched(), based on a suggestion by Mathias
|
||||
Hasselmann. reworked g_test_trap_assertions() to use flags to encode
|
||||
assertion semantics, fixes #504227.
|
||||
|
||||
2007-12-16 Mathias Hasselmann <mathias@openismus.com>
|
||||
|
||||
* glib/gutils.c:
|
||||
|
@ -1526,11 +1526,15 @@ g_test_trap_assertions (const char *domain,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
gboolean must_pass,
|
||||
gboolean must_fail,
|
||||
const char *stdout_pattern,
|
||||
const char *stderr_pattern)
|
||||
guint64 assertion_flags, /* 0-pass, 1-fail, 2-outpattern, 4-errpattern */
|
||||
const char *pattern)
|
||||
{
|
||||
gboolean must_pass = assertion_flags == 0;
|
||||
gboolean must_fail = assertion_flags == 1;
|
||||
gboolean match_result = 0 == (assertion_flags & 1);
|
||||
const char *stdout_pattern = (assertion_flags & 2) ? pattern : NULL;
|
||||
const char *stderr_pattern = (assertion_flags & 4) ? pattern : NULL;
|
||||
const char *match_error = match_result ? "failed to match" : "contains invalid match";
|
||||
if (test_trap_last_pid == 0)
|
||||
g_error ("child process failed to exit after g_test_trap_fork() and before g_test_trap_assert*()");
|
||||
if (must_pass && !g_test_trap_has_passed())
|
||||
@ -1545,15 +1549,15 @@ g_test_trap_assertions (const char *domain,
|
||||
g_assertion_message (domain, file, line, func, msg);
|
||||
g_free (msg);
|
||||
}
|
||||
if (stdout_pattern && !g_pattern_match_simple (stdout_pattern, test_trap_last_stdout))
|
||||
if (stdout_pattern && match_result == !g_pattern_match_simple (stdout_pattern, test_trap_last_stdout))
|
||||
{
|
||||
char *msg = g_strdup_printf ("stdout of child process (%d) failed to match: %s", test_trap_last_pid, stdout_pattern);
|
||||
char *msg = g_strdup_printf ("stdout of child process (%d) %s: %s", test_trap_last_pid, match_error, stdout_pattern);
|
||||
g_assertion_message (domain, file, line, func, msg);
|
||||
g_free (msg);
|
||||
}
|
||||
if (stderr_pattern && !g_pattern_match_simple (stderr_pattern, test_trap_last_stderr))
|
||||
if (stderr_pattern && match_result == !g_pattern_match_simple (stderr_pattern, test_trap_last_stderr))
|
||||
{
|
||||
char *msg = g_strdup_printf ("stderr of child process (%d) failed to match: %s", test_trap_last_pid, stderr_pattern);
|
||||
char *msg = g_strdup_printf ("stderr of child process (%d) %s: %s", test_trap_last_pid, match_error, stderr_pattern);
|
||||
g_assertion_message (domain, file, line, func, msg);
|
||||
g_free (msg);
|
||||
}
|
||||
|
@ -124,10 +124,12 @@ gboolean g_test_trap_fork (guint64 usec_timeout,
|
||||
GTestTrapFlags test_trap_flags);
|
||||
gboolean g_test_trap_has_passed (void);
|
||||
gboolean g_test_trap_reached_timeout (void);
|
||||
#define g_test_trap_assert_passed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 1, 0, 0, 0)
|
||||
#define g_test_trap_assert_failed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 0, 1, 0, 0)
|
||||
#define g_test_trap_assert_stdout(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 0, 0, soutpattern, 0)
|
||||
#define g_test_trap_assert_stderr(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 0, 0, 0, serrpattern)
|
||||
#define g_test_trap_assert_passed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 0, 0)
|
||||
#define g_test_trap_assert_failed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 1, 0)
|
||||
#define g_test_trap_assert_stdout(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 2, soutpattern)
|
||||
#define g_test_trap_assert_stdout_unmatched(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 3, soutpattern)
|
||||
#define g_test_trap_assert_stderr(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 4, serrpattern)
|
||||
#define g_test_trap_assert_stderr_unmatched(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 5, serrpattern)
|
||||
|
||||
/* provide seed-able random numbers for tests */
|
||||
#define g_test_rand_bit() (0 != (g_test_rand_int() & (1 << 15)))
|
||||
@ -158,10 +160,8 @@ void g_test_trap_assertions (const char *domain,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
gboolean must_pass,
|
||||
gboolean must_fail,
|
||||
const char *stdout_pattern,
|
||||
const char *stderr_pattern);
|
||||
guint64 assertion_flags, /* 0-pass, 1-fail, 2-outpattern, 4-errpattern */
|
||||
const char *pattern);
|
||||
void g_assertion_message (const char *domain,
|
||||
const char *file,
|
||||
int line,
|
||||
|
Loading…
Reference in New Issue
Block a user