[glib] Add undefined/no-undefined mode options to GTester



commit 993de34a77bdbfc37e210a85382e5f34f604efe9
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Wed Dec 14 17:31:23 2011 +0000

    Add undefined/no-undefined mode options to GTester
    
    https://bugzilla.gnome.org/show_bug.cgi?id=666116

 docs/reference/glib/gtester.xml |   33 ++++++++++++++++++++++++++++++++-
 glib/gtester.c                  |   10 ++++++++++
 glib/gtestutils.c               |   33 ++++++++++++++++++++++++++++++++-
 glib/gtestutils.h               |    2 ++
 4 files changed, 76 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/glib/gtester.xml b/docs/reference/glib/gtester.xml
index dcaae7d..75a1cea 100644
--- a/docs/reference/glib/gtester.xml
+++ b/docs/reference/glib/gtester.xml
@@ -70,7 +70,38 @@ list paths of available test cases
 <varlistentry>
 <term><option>-m=<replaceable>MODE</replaceable></option></term>
 <listitem><para>
-run test cases in <replaceable>MODE</replaceable>, which can be perf, slow, thorough or quick. The default mode is quick.
+    run test cases in <replaceable>MODE</replaceable>, which can be one of:
+
+    <variablelist>
+      <term><option>perf</option></term>
+      <listitem><para>
+          run performance tests
+      </para></listitem>
+
+      <term><option>slow</option>, <option>thorough</option></term>
+      <listitem><para>
+          run slow tests, or repeat non-deterministic tests more often
+      </para></listitem>
+
+      <term><option>quick</option></term>
+      <listitem><para>
+          do not run slow or performance tests, or do extra repeats
+          of non-deterministic tests (default)
+      </para></listitem>
+
+      <term><option>undefined</option></term>
+      <listitem><para>
+          run test cases that deliberately provoke checks or assertion
+          failures, if implemented (default)
+      </para></listitem>
+
+      <term><option>no-undefined</option></term>
+      <listitem><para>
+          do not run test cases that deliberately provoke checks or
+          assertion failures
+      </para></listitem>
+    </variablelist>
+
 </para></listitem>
 </varlistentry>
 
diff --git a/glib/gtester.c b/glib/gtester.c
index df9d665..e9d695f 100644
--- a/glib/gtester.c
+++ b/glib/gtester.c
@@ -50,6 +50,7 @@ static gboolean     subtest_verbose = FALSE;
 static gboolean     subtest_mode_fatal = TRUE;
 static gboolean     subtest_mode_perf = FALSE;
 static gboolean     subtest_mode_quick = TRUE;
+static gboolean     subtest_mode_undefined = TRUE;
 static const gchar *subtest_seedstr = NULL;
 static gchar       *subtest_last_seed = NULL;
 static GSList      *subtest_paths = NULL;
@@ -307,6 +308,8 @@ launch_test_binary (const char *binary,
     argc++;
   if (subtest_mode_perf)
     argc++;
+  if (!subtest_mode_undefined)
+    argc++;
   if (gtester_list_tests)
     argc++;
   if (subtest_seedstr)
@@ -337,6 +340,8 @@ launch_test_binary (const char *binary,
     argv[i++] = "-m=slow";
   if (subtest_mode_perf)
     argv[i++] = "-m=perf";
+  if (!subtest_mode_undefined)
+    argv[i++] = "-m=no-undefined";
   if (gtester_list_tests)
     argv[i++] = "-l";
   if (subtest_seedstr)
@@ -479,6 +484,7 @@ usage (gboolean just_version)
   g_print ("  -l                          list paths of available test cases\n");
   g_print ("  -m=perf, -m=slow, -m=quick -m=thorough\n");
   g_print ("                              run test cases in mode perf, slow/thorough or quick (default)\n");
+  g_print ("  -m=no-undefined             don't run test cases that provoke assertions\n");
   g_print ("  -p=TESTPATH                 only start test cases matching TESTPATH\n");
   g_print ("  -s=TESTPATH                 skip test cases matching TESTPATH\n");
   g_print ("  --seed=SEEDSTRING           start all tests with random number seed SEEDSTRING\n");
@@ -596,6 +602,10 @@ parse_args (gint    *argc_p,
               subtest_mode_quick = TRUE;
               subtest_mode_perf = FALSE;
             }
+          else if (strcmp (mode, "undefined") == 0)
+            subtest_mode_undefined = TRUE;
+          else if (strcmp (mode, "no-undefined") == 0)
+            subtest_mode_undefined = FALSE;
           else
             g_error ("unknown test mode: -m %s", mode);
           argv[i] = NULL;
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index b7f3223..3406d43 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -141,6 +141,17 @@
  */
 
 /**
+ * g_test_undefined:
+ *
+ * Returns %TRUE if tests may provoke assertions and other formally-undefined
+ * behaviour under g_test_trap_fork(), to verify that appropriate warnings
+ * are given. It can be useful to turn this off if running tests under
+ * valgrind.
+ *
+ * Returns: %TRUE if tests may provoke programming errors
+ */
+
+/**
  * g_test_verbose:
  *
  * Returns %TRUE if tests are run in verbose mode.
@@ -496,6 +507,7 @@ static GTestConfig mutable_test_config_vars = {
   FALSE,        /* test_perf */
   FALSE,        /* test_verbose */
   FALSE,        /* test_quiet */
+  TRUE,         /* test_undefined */
 };
 const GTestConfig * const g_test_config_vars = &mutable_test_config_vars;
 
@@ -722,6 +734,10 @@ parse_args (gint    *argc_p,
               mutable_test_config_vars.test_quick = TRUE;
               mutable_test_config_vars.test_perf = FALSE;
             }
+          else if (strcmp (mode, "undefined") == 0)
+            mutable_test_config_vars.test_undefined = TRUE;
+          else if (strcmp (mode, "no-undefined") == 0)
+            mutable_test_config_vars.test_undefined = FALSE;
           else
             g_error ("unknown test mode: -m %s", mode);
           argv[i] = NULL;
@@ -770,6 +786,7 @@ parse_args (gint    *argc_p,
                   "  -p TESTPATH                    execute all tests matching TESTPATH\n"
                   "  -s TESTPATH                    skip all tests matching TESTPATH\n"
                   "  -m {perf|slow|thorough|quick}  Execute tests according modes\n"
+                  "  -m {undefined|no-undefined}    Execute tests according modes\n"
                   "  --debug-log                    debug test logging output\n"
                   "  -k, --keep-going               gtester-specific argument\n"
                   "  --GTestLogFD=N                 gtester-specific argument\n"
@@ -830,7 +847,7 @@ parse_args (gint    *argc_p,
  *       </para></listitem>
  *     </varlistentry>
  *     <varlistentry>
- *       <term><option>-m {perf|slow|thorough|quick}</option></term>
+ *       <term><option>-m {perf|slow|thorough|quick|undefined|no-undefined}</option></term>
  *       <listitem><para>
  *         execute tests according to these test modes:
  *         <variablelist>
@@ -853,6 +870,20 @@ parse_args (gint    *argc_p,
  *               quick tests, should run really quickly and give good coverage.
  *             </para></listitem>
  *           </varlistentry>
+ *           <varlistentry>
+ *             <term>undefined</term>
+ *             <listitem><para>
+ *               tests for undefined behaviour, may provoke programming errors
+ *               under g_test_trap_fork() to check that appropriate assertions
+ *               or warnings are given
+ *             </para></listitem>
+ *           </varlistentry>
+ *           <varlistentry>
+ *             <term>no-undefined</term>
+ *             <listitem><para>
+ *               avoid tests for undefined behaviour
+ *             </para></listitem>
+ *           </varlistentry>
  *         </variablelist>
  *       </para></listitem>
  *     </varlistentry>
diff --git a/glib/gtestutils.h b/glib/gtestutils.h
index 0184c7c..3cd173c 100644
--- a/glib/gtestutils.h
+++ b/glib/gtestutils.h
@@ -98,6 +98,7 @@ void    g_test_init                     (int            *argc,
 #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)
+#define g_test_undefined()              (g_test_config_vars->test_undefined)
 /* run all tests under toplevel suite (path: /) */
 int     g_test_run                      (void);
 /* hook up a test functions under test path */
@@ -234,6 +235,7 @@ typedef struct {
   gboolean      test_perf;      /* run performance tests */
   gboolean      test_verbose;   /* extra info */
   gboolean      test_quiet;     /* reduce output */
+  gboolean      test_undefined; /* run tests that are meant to assert */
 } GTestConfig;
 GLIB_VAR const GTestConfig * const g_test_config_vars;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]