mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 03:02:10 +01:00
Added API to access test framework configuration.
* gtestframework.h, gtestframework.c: export testing configuration to test programs with g_test_quick(), g_test_perf(), g_test_verbose(), g_test_quiet(). svn path=/trunk/; revision=5905
This commit is contained in:
parent
a46a52941b
commit
a0409304dc
@ -1249,6 +1249,7 @@ 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_config_vars
|
||||||
g_test_create_case
|
g_test_create_case
|
||||||
g_test_create_suite
|
g_test_create_suite
|
||||||
g_test_get_root
|
g_test_get_root
|
||||||
|
@ -55,13 +55,8 @@ static guint8* g_test_log_dump (GTestLogMsg *msg,
|
|||||||
|
|
||||||
/* --- variables --- */
|
/* --- variables --- */
|
||||||
static int test_log_fd = -1;
|
static int test_log_fd = -1;
|
||||||
static gboolean test_mode_quick = TRUE;
|
|
||||||
static gboolean test_mode_perf = FALSE;
|
|
||||||
static gboolean test_mode_fatal = TRUE;
|
static gboolean test_mode_fatal = TRUE;
|
||||||
static gboolean g_test_initialized = FALSE;
|
|
||||||
static gboolean g_test_run_once = TRUE;
|
static gboolean g_test_run_once = TRUE;
|
||||||
static gboolean test_run_quiet = FALSE;
|
|
||||||
static gboolean test_run_verbose = FALSE;
|
|
||||||
static gboolean test_run_list = FALSE;
|
static gboolean test_run_list = FALSE;
|
||||||
static gchar *test_run_seedstr = NULL;
|
static gchar *test_run_seedstr = NULL;
|
||||||
static GRand *test_run_rand = NULL;
|
static GRand *test_run_rand = NULL;
|
||||||
@ -79,6 +74,13 @@ 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 gboolean test_debug_log = FALSE;
|
static gboolean test_debug_log = FALSE;
|
||||||
|
const GTestConfig *g_test_config_vars = NULL;
|
||||||
|
static GTestConfig mutable_test_config_vars = {
|
||||||
|
TRUE, /* test_quick */
|
||||||
|
FALSE, /* test_perf */
|
||||||
|
FALSE, /* test_verbose */
|
||||||
|
FALSE, /* test_quiet */
|
||||||
|
};
|
||||||
|
|
||||||
/* --- functions --- */
|
/* --- functions --- */
|
||||||
const char*
|
const char*
|
||||||
@ -149,17 +151,17 @@ g_test_log (GTestLogType lbit,
|
|||||||
switch (lbit)
|
switch (lbit)
|
||||||
{
|
{
|
||||||
case G_TEST_LOG_STOP_CASE:
|
case G_TEST_LOG_STOP_CASE:
|
||||||
if (!test_run_quiet)
|
if (!g_test_quiet())
|
||||||
g_print ("%s\n", fail ? "FAIL" : "OK");
|
g_print ("%s\n", fail ? "FAIL" : "OK");
|
||||||
if (fail && test_mode_fatal)
|
if (fail && test_mode_fatal)
|
||||||
abort();
|
abort();
|
||||||
break;
|
break;
|
||||||
case G_TEST_LOG_MIN_RESULT:
|
case G_TEST_LOG_MIN_RESULT:
|
||||||
if (test_run_verbose)
|
if (g_test_verbose())
|
||||||
g_print ("(MINPERF:%s)\n", string1);
|
g_print ("(MINPERF:%s)\n", string1);
|
||||||
break;
|
break;
|
||||||
case G_TEST_LOG_MAX_RESULT:
|
case G_TEST_LOG_MAX_RESULT:
|
||||||
if (test_run_verbose)
|
if (g_test_verbose())
|
||||||
g_print ("(MAXPERF:%s)\n", string1);
|
g_print ("(MAXPERF:%s)\n", string1);
|
||||||
break;
|
break;
|
||||||
default: ;
|
default: ;
|
||||||
@ -179,7 +181,7 @@ g_test_log (GTestLogType lbit,
|
|||||||
switch (lbit)
|
switch (lbit)
|
||||||
{
|
{
|
||||||
case G_TEST_LOG_START_CASE:
|
case G_TEST_LOG_START_CASE:
|
||||||
if (!test_run_quiet)
|
if (!g_test_quiet())
|
||||||
g_print ("%s: ", string1);
|
g_print ("%s: ", string1);
|
||||||
break;
|
break;
|
||||||
default: ;
|
default: ;
|
||||||
@ -262,13 +264,13 @@ parse_args (gint *argc_p,
|
|||||||
mode = argv[i];
|
mode = argv[i];
|
||||||
}
|
}
|
||||||
if (strcmp (mode, "perf") == 0)
|
if (strcmp (mode, "perf") == 0)
|
||||||
test_mode_perf = TRUE;
|
mutable_test_config_vars.test_perf = TRUE;
|
||||||
else if (strcmp (mode, "slow") == 0)
|
else if (strcmp (mode, "slow") == 0)
|
||||||
test_mode_quick = FALSE;
|
mutable_test_config_vars.test_quick = FALSE;
|
||||||
else if (strcmp (mode, "quick") == 0)
|
else if (strcmp (mode, "quick") == 0)
|
||||||
{
|
{
|
||||||
test_mode_quick = TRUE;
|
mutable_test_config_vars.test_quick = TRUE;
|
||||||
test_mode_perf = FALSE;
|
mutable_test_config_vars.test_perf = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
g_error ("unknown test mode: -m %s", mode);
|
g_error ("unknown test mode: -m %s", mode);
|
||||||
@ -276,14 +278,14 @@ parse_args (gint *argc_p,
|
|||||||
}
|
}
|
||||||
else if (strcmp ("-q", argv[i]) == 0 || strcmp ("--quiet", argv[i]) == 0)
|
else if (strcmp ("-q", argv[i]) == 0 || strcmp ("--quiet", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
test_run_quiet = TRUE;
|
mutable_test_config_vars.test_quiet = TRUE;
|
||||||
test_run_verbose = FALSE;
|
mutable_test_config_vars.test_verbose = FALSE;
|
||||||
argv[i] = NULL;
|
argv[i] = NULL;
|
||||||
}
|
}
|
||||||
else if (strcmp ("--verbose", argv[i]) == 0)
|
else if (strcmp ("--verbose", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
test_run_quiet = FALSE;
|
mutable_test_config_vars.test_quiet = FALSE;
|
||||||
test_run_verbose = TRUE;
|
mutable_test_config_vars.test_verbose = TRUE;
|
||||||
argv[i] = NULL;
|
argv[i] = NULL;
|
||||||
}
|
}
|
||||||
else if (strcmp ("-l", argv[i]) == 0)
|
else if (strcmp ("-l", argv[i]) == 0)
|
||||||
@ -326,8 +328,8 @@ g_test_init (int *argc,
|
|||||||
gpointer vararg1;
|
gpointer vararg1;
|
||||||
g_return_if_fail (argc != NULL);
|
g_return_if_fail (argc != NULL);
|
||||||
g_return_if_fail (argv != NULL);
|
g_return_if_fail (argv != NULL);
|
||||||
g_return_if_fail (g_test_initialized == FALSE);
|
g_return_if_fail (g_test_config_vars == NULL);
|
||||||
g_test_initialized = TRUE;
|
g_test_config_vars = &mutable_test_config_vars;
|
||||||
|
|
||||||
va_start (args, argv);
|
va_start (args, argv);
|
||||||
vararg1 = va_arg (args, gpointer); /* reserved for future extensions */
|
vararg1 = va_arg (args, gpointer); /* reserved for future extensions */
|
||||||
@ -696,7 +698,7 @@ int
|
|||||||
g_test_run_suite (GTestSuite *suite)
|
g_test_run_suite (GTestSuite *suite)
|
||||||
{
|
{
|
||||||
guint n_bad = 0;
|
guint n_bad = 0;
|
||||||
g_return_val_if_fail (g_test_initialized == TRUE, -1);
|
g_return_val_if_fail (g_test_config_vars != NULL, -1);
|
||||||
g_return_val_if_fail (g_test_run_once == TRUE, -1);
|
g_return_val_if_fail (g_test_run_once == TRUE, -1);
|
||||||
g_test_run_once = FALSE;
|
g_test_run_once = FALSE;
|
||||||
if (!test_paths)
|
if (!test_paths)
|
||||||
|
@ -64,6 +64,11 @@ void g_test_maximized_result (double maximized_quantity,
|
|||||||
void g_test_init (int *argc,
|
void g_test_init (int *argc,
|
||||||
char ***argv,
|
char ***argv,
|
||||||
...);
|
...);
|
||||||
|
/* query testing framework config */
|
||||||
|
#define g_test_quick() (g_test_config_vars->test_quick)
|
||||||
|
#define g_test_perf() (g_test_config_vars->test_perf)
|
||||||
|
#define g_test_verbose() (g_test_config_vars->test_verbose)
|
||||||
|
#define g_test_quiet() (g_test_config_vars->test_quiet)
|
||||||
/* run all tests under toplevel suite (path: /) */
|
/* run all tests under toplevel suite (path: /) */
|
||||||
int g_test_run (void);
|
int g_test_run (void);
|
||||||
/* hook up a simple test function under test path */
|
/* hook up a simple test function under test path */
|
||||||
@ -166,6 +171,13 @@ void g_test_add_vtable (const char *testpath,
|
|||||||
void (*data_setup) (void),
|
void (*data_setup) (void),
|
||||||
void (*data_test) (void),
|
void (*data_test) (void),
|
||||||
void (*data_teardown) (void));
|
void (*data_teardown) (void));
|
||||||
|
typedef struct {
|
||||||
|
gboolean test_quick; /* disable thorough tests */
|
||||||
|
gboolean test_perf; /* run performance tests */
|
||||||
|
gboolean test_verbose; /* extra info */
|
||||||
|
gboolean test_quiet; /* reduce output */
|
||||||
|
} GTestConfig;
|
||||||
|
GLIB_VAR const GTestConfig *g_test_config_vars;
|
||||||
|
|
||||||
/* internal logging API */
|
/* internal logging API */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user