gtestutils: improve non-TAP output, fix handling of incomplete tests

In non-TAP mode, tests that used g_test_skip() were labelled "OK", and
tests that used g_test_incomplete() were labelled "FAIL". Explicitly
show them as "SKIP" and "TODO" instead, like in the TAP case.

Also, incomplete/TODO tests are not supposed to be treated as
failures, so fix that too.

https://bugzilla.gnome.org/show_bug.cgi?id=754286
This commit is contained in:
Dan Winship 2014-02-01 18:23:13 +01:00
parent 6e382208f7
commit 123ea70d74

View File

@ -645,6 +645,12 @@ typedef enum {
G_TEST_RUN_FAILURE, G_TEST_RUN_FAILURE,
G_TEST_RUN_INCOMPLETE G_TEST_RUN_INCOMPLETE
} GTestResult; } GTestResult;
static const char * const g_test_result_names[] = {
"OK",
"SKIP",
"FAIL",
"TODO"
};
/* --- variables --- */ /* --- variables --- */
static int test_log_fd = -1; static int test_log_fd = -1;
@ -765,6 +771,7 @@ g_test_log (GTestLogType lbit,
guint n_args, guint n_args,
long double *largs) long double *largs)
{ {
GTestResult result;
gboolean fail; gboolean fail;
GTestLogMsg msg; GTestLogMsg msg;
gchar *astrings[3] = { NULL, NULL, NULL }; gchar *astrings[3] = { NULL, NULL, NULL };
@ -796,28 +803,29 @@ g_test_log (GTestLogType lbit,
} }
break; break;
case G_TEST_LOG_STOP_CASE: case G_TEST_LOG_STOP_CASE:
fail = largs[0] != G_TEST_RUN_SUCCESS && largs[0] != G_TEST_RUN_SKIPPED; result = largs[0];
fail = result == G_TEST_RUN_FAILURE;
if (test_tap_log) if (test_tap_log)
{ {
g_print ("%s %d %s", fail ? "not ok" : "ok", test_run_count, string1); g_print ("%s %d %s", fail ? "not ok" : "ok", test_run_count, string1);
if (largs[0] == G_TEST_RUN_INCOMPLETE) if (result == G_TEST_RUN_INCOMPLETE)
g_print (" # TODO %s\n", string2 ? string2 : ""); g_print (" # TODO %s\n", string2 ? string2 : "");
else if (largs[0] == G_TEST_RUN_SKIPPED) else if (result == G_TEST_RUN_SKIPPED)
g_print (" # SKIP %s\n", string2 ? string2 : ""); g_print (" # SKIP %s\n", string2 ? string2 : "");
else else
g_print ("\n"); g_print ("\n");
} }
else if (g_test_verbose()) else if (g_test_verbose())
g_print ("GTest: result: %s\n", fail ? "FAIL" : "OK"); g_print ("GTest: result: %s\n", g_test_result_names[result]);
else if (!g_test_quiet()) else if (!g_test_quiet())
g_print ("%s\n", fail ? "FAIL" : "OK"); g_print ("%s\n", g_test_result_names[result]);
if (fail && test_mode_fatal) if (fail && test_mode_fatal)
{ {
if (test_tap_log) if (test_tap_log)
g_print ("Bail out!\n"); g_print ("Bail out!\n");
abort(); abort();
} }
if (largs[0] == G_TEST_RUN_SKIPPED) if (result == G_TEST_RUN_SKIPPED)
test_skipped_count++; test_skipped_count++;
break; break;
case G_TEST_LOG_MIN_RESULT: case G_TEST_LOG_MIN_RESULT: