Added g_test_bug() and related API.

* gtester.c: handle G_TEST_LOG_MESSAGE and test test message API.

* gtestframework.h, gtestframework.c: added test message API and convenience
API to send test messages about bug URLs.

svn path=/trunk/; revision=5906
This commit is contained in:
Tim Janik 2007-11-20 15:00:56 +00:00
parent a0409304dc
commit 515c53474a
4 changed files with 71 additions and 9 deletions

View File

@ -1249,6 +1249,8 @@ g_assertion_message_expr
g_strcmp0 g_strcmp0
g_test_add_func g_test_add_func
g_test_add_vtable g_test_add_vtable
g_test_bug
g_test_bug_base
g_test_config_vars g_test_config_vars
g_test_create_case g_test_create_case
g_test_create_suite g_test_create_suite
@ -1261,6 +1263,7 @@ g_test_log_buffer_push
g_test_log_msg_free g_test_log_msg_free
g_test_log_type_name g_test_log_type_name
g_test_maximized_result g_test_maximized_result
g_test_message
g_test_minimized_result g_test_minimized_result
g_test_queue_free g_test_queue_free
g_test_rand_double g_test_rand_double

View File

@ -166,6 +166,9 @@ test_log_msg (GTestLogMsg *msg)
test_log_printfe ("%s%s\n", sindent (log_indent + 2), msg->strings[0]); test_log_printfe ("%s%s\n", sindent (log_indent + 2), msg->strings[0]);
test_log_printfe ("%s</performance>\n", sindent (log_indent)); test_log_printfe ("%s</performance>\n", sindent (log_indent));
break; break;
case G_TEST_LOG_MESSAGE:
test_log_printfe ("%s<message>\n%s\n%s</message>\n", sindent (log_indent), msg->strings[0], sindent (log_indent));
break;
} }
} }
@ -616,6 +619,11 @@ static void
fixture_test (guint *fix) fixture_test (guint *fix)
{ {
g_assert_cmphex (*fix, ==, 0xdeadbeef); g_assert_cmphex (*fix, ==, 0xdeadbeef);
g_test_message ("This is a test message API test message.");
g_test_bug_base ("http://www.example.com/bugtracker/");
g_test_bug ("123");
g_test_bug_base ("http://www.example.com/bugtracker?bugnum=%s;cmd=showbug");
g_test_bug ("456");
} }
static void static void
fixture_teardown (guint *fix) fixture_teardown (guint *fix)

View File

@ -73,6 +73,7 @@ static int test_trap_last_status = 0;
static int test_trap_last_pid = 0; static int test_trap_last_pid = 0;
static char *test_trap_last_stdout = NULL; static char *test_trap_last_stdout = NULL;
static char *test_trap_last_stderr = NULL; static char *test_trap_last_stderr = NULL;
static char *test_uri_base = NULL;
static gboolean test_debug_log = FALSE; static gboolean test_debug_log = FALSE;
const GTestConfig *g_test_config_vars = NULL; const GTestConfig *g_test_config_vars = NULL;
static GTestConfig mutable_test_config_vars = { static GTestConfig mutable_test_config_vars = {
@ -88,14 +89,18 @@ g_test_log_type_name (GTestLogType log_type)
{ {
switch (log_type) switch (log_type)
{ {
case G_TEST_LOG_NONE: return "none";
case G_TEST_LOG_ERROR: return "error";
case G_TEST_LOG_START_BINARY: return "binary"; case G_TEST_LOG_START_BINARY: return "binary";
case G_TEST_LOG_LIST_CASE: return "list"; case G_TEST_LOG_LIST_CASE: return "list";
case G_TEST_LOG_SKIP_CASE: return "skip";
case G_TEST_LOG_START_CASE: return "start"; case G_TEST_LOG_START_CASE: return "start";
case G_TEST_LOG_STOP_CASE: return "stop"; case G_TEST_LOG_STOP_CASE: return "stop";
case G_TEST_LOG_MIN_RESULT: return "minperf"; case G_TEST_LOG_MIN_RESULT: return "minperf";
case G_TEST_LOG_MAX_RESULT: return "maxperf"; case G_TEST_LOG_MAX_RESULT: return "maxperf";
default: return "???"; case G_TEST_LOG_MESSAGE: return "message";
} }
return "???";
} }
static void static void
@ -164,6 +169,10 @@ g_test_log (GTestLogType lbit,
if (g_test_verbose()) if (g_test_verbose())
g_print ("(MAXPERF:%s)\n", string1); g_print ("(MAXPERF:%s)\n", string1);
break; break;
case G_TEST_LOG_MESSAGE:
if (g_test_verbose())
g_print ("(MSG: %s)\n", string1);
break;
default: ; default: ;
} }
@ -479,6 +488,45 @@ g_test_maximized_result (double maximized_quantity,
g_free (buffer); g_free (buffer);
} }
void
g_test_message (const char *format,
...)
{
gchar *buffer;
va_list args;
va_start (args, format);
buffer = g_strdup_vprintf (format, args);
va_end (args);
g_test_log (G_TEST_LOG_MESSAGE, buffer, NULL, 0, NULL);
g_free (buffer);
}
void
g_test_bug_base (const char *uri_pattern)
{
g_free (test_uri_base);
test_uri_base = g_strdup (uri_pattern);
}
void
g_test_bug (const char *bug_uri_snippet)
{
char *c;
g_return_if_fail (test_uri_base != NULL);
g_return_if_fail (bug_uri_snippet != NULL);
c = strstr (test_uri_base, "%s");
if (c)
{
char *b = g_strndup (test_uri_base, c - test_uri_base);
char *s = g_strconcat (b, bug_uri_snippet, c + 2, NULL);
g_free (b);
g_test_message ("Bug Reference: %s", s);
g_free (s);
}
else
g_test_message ("Bug Reference: %s%s", test_uri_base, bug_uri_snippet);
}
GTestSuite* GTestSuite*
g_test_get_root (void) g_test_get_root (void)
{ {
@ -606,15 +654,11 @@ g_test_queue_free (gpointer gfree_pointer)
static int static int
test_case_run (GTestCase *tc) test_case_run (GTestCase *tc)
{ {
gchar *old_name; gchar *old_name = test_run_name, *old_base = g_strdup (test_uri_base);
old_name = test_run_name;
test_run_name = g_strconcat (old_name, "/", tc->name, NULL); test_run_name = g_strconcat (old_name, "/", tc->name, NULL);
if (++test_run_count <= test_skip_count) if (++test_run_count <= test_skip_count)
{ g_test_log (G_TEST_LOG_SKIP_CASE, test_run_name, NULL, 0, NULL);
g_test_log (G_TEST_LOG_SKIP_CASE, test_run_name, NULL, 0, NULL); else if (test_run_list)
return 0;
}
if (test_run_list)
{ {
g_print ("%s\n", test_run_name); g_print ("%s\n", test_run_name);
g_test_log (G_TEST_LOG_LIST_CASE, test_run_name, NULL, 0, NULL); g_test_log (G_TEST_LOG_LIST_CASE, test_run_name, NULL, 0, NULL);
@ -650,7 +694,8 @@ test_case_run (GTestCase *tc)
} }
g_free (test_run_name); g_free (test_run_name);
test_run_name = old_name; test_run_name = old_name;
/* FIXME: need reporting here */ g_free (test_uri_base);
test_uri_base = old_base;
return 0; return 0;
} }

View File

@ -83,6 +83,11 @@ void g_test_add_func (const char *testpath,
void (*) (Fixture*))) \ void (*) (Fixture*))) \
(void*) g_test_add_vtable) \ (void*) g_test_add_vtable) \
(testpath, sizeof (Fixture), fsetup, ftest, fteardown) (testpath, sizeof (Fixture), fsetup, ftest, fteardown)
/* add test messages to the test report */
void g_test_message (const char *format,
...) G_GNUC_PRINTF (1, 2);
void g_test_bug_base (const char *uri_pattern);
void g_test_bug (const char *bug_uri_snippet);
/* measure test timings */ /* measure test timings */
void g_test_timer_start (void); void g_test_timer_start (void);
double g_test_timer_elapsed (void); // elapsed seconds double g_test_timer_elapsed (void); // elapsed seconds
@ -190,6 +195,7 @@ typedef enum {
G_TEST_LOG_STOP_CASE, // d:status d:nforks d:elapsed G_TEST_LOG_STOP_CASE, // d:status d:nforks d:elapsed
G_TEST_LOG_MIN_RESULT, // s:blurb d:result G_TEST_LOG_MIN_RESULT, // s:blurb d:result
G_TEST_LOG_MAX_RESULT, // s:blurb d:result G_TEST_LOG_MAX_RESULT, // s:blurb d:result
G_TEST_LOG_MESSAGE, // s:blurb
} GTestLogType; } GTestLogType;
typedef struct { typedef struct {