Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tidying a bit xbt/cunit.c
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 2 Mar 2016 10:54:16 +0000 (11:54 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 2 Mar 2016 11:02:17 +0000 (12:02 +0100)
include/xbt/cunit.h
src/xbt/cunit.c

index 219a42a..9233bd6 100644 (file)
@@ -118,10 +118,8 @@ XBT_PUBLIC(void) _xbt_test_log(const char *file, int line, const char *fmt, ...)
 #define xbt_test_assert(...)    _XBT_IF_ONE_ARG(_xbt_test_assert_ARG1,  \
                                                 _xbt_test_assert_ARGN,  \
                                                 __VA_ARGS__)(__VA_ARGS__)
 #define xbt_test_assert(...)    _XBT_IF_ONE_ARG(_xbt_test_assert_ARG1,  \
                                                 _xbt_test_assert_ARGN,  \
                                                 __VA_ARGS__)(__VA_ARGS__)
-#define _xbt_test_assert_ARG1(cond)      _xbt_test_assert_CHECK(cond,   \
-                                                                "%s", #cond)
-#define _xbt_test_assert_ARGN(cond, ...) _xbt_test_assert_CHECK(cond,   \
-                                                                __VA_ARGS__)
+#define _xbt_test_assert_ARG1(cond)      _xbt_test_assert_CHECK(cond, "%s", #cond)
+#define _xbt_test_assert_ARGN(cond, ...) _xbt_test_assert_CHECK(cond, __VA_ARGS__)
 #define _xbt_test_assert_CHECK(cond, ...)                       \
   do { if (!(cond)) xbt_test_fail(__VA_ARGS__); } while (0)
 /** @brief Report some details to help debugging when the test fails (shown only on failure)
 #define _xbt_test_assert_CHECK(cond, ...)                       \
   do { if (!(cond)) xbt_test_fail(__VA_ARGS__); } while (0)
 /** @brief Report some details to help debugging when the test fails (shown only on failure)
index 58e7fc7..b8353b4 100644 (file)
@@ -480,7 +480,6 @@ static void apply_selection(char *selection)
 {
   /* for the parsing */
   char *sel = selection;
 {
   /* for the parsing */
   char *sel = selection;
-  char *p;
   int done = 0;
   char dir[1024];               /* the directive */
   /* iterators */
   int done = 0;
   char dir[1024];               /* the directive */
   /* iterators */
@@ -501,7 +500,7 @@ static void apply_selection(char *selection)
   while (!done) {
     int enabling = 1;
 
   while (!done) {
     int enabling = 1;
 
-    p = strchr(sel, ',');
+    char *p = strchr(sel, ',');
     if (p) {
       strncpy(dir, sel, p - sel);
       dir[p - sel] = '\0';
     if (p) {
       strncpy(dir, sel, p - sel);
       dir[p - sel] = '\0';
@@ -529,16 +528,10 @@ static void apply_selection(char *selection)
       strcpy(suitename, dir);
       unitname[0] = '\0';
     }
       strcpy(suitename, dir);
       unitname[0] = '\0';
     }
-    /*fprintf(stderr,"Seen %s (%s; suite=%s; unit=%s)\n",
-       dir,enabling?"enabling":"disabling", suitename, unitname); */
 
     /* Deal with the specific case of 'all' pseudo serie */
     if (!strcmp("all", suitename)) {
 
     /* Deal with the specific case of 'all' pseudo serie */
     if (!strcmp("all", suitename)) {
-      if (unitname[0] != '\0') {
-        fprintf(stderr,
-                "The 'all' pseudo-suite does not accept any unit specification\n");
-        exit(1);
-      }
+      xbt_assert(unitname[0] == '\0', "The 'all' pseudo-suite does not accept any unit specification\n");
 
       xbt_dynar_foreach(_xbt_test_suites, it_suite, suite) {
         xbt_dynar_foreach(suite->units, it_unit, unit) {
 
       xbt_dynar_foreach(_xbt_test_suites, it_suite, suite) {
         xbt_dynar_foreach(suite->units, it_unit, unit) {
@@ -566,31 +559,20 @@ static void apply_selection(char *selection)
             for (it2_unit = 0;
                  it2_unit < xbt_dynar_length(thissuite->units);
                  it2_unit++) {
             for (it2_unit = 0;
                  it2_unit < xbt_dynar_length(thissuite->units);
                  it2_unit++) {
-              xbt_test_unit_t thisunit =
-                  xbt_dynar_get_as(thissuite->units, it2_unit,
-                                   xbt_test_unit_t);
+              xbt_test_unit_t thisunit = xbt_dynar_get_as(thissuite->units, it2_unit, xbt_test_unit_t);
               if (!strcmp(thisunit->name, unitname)) {
                 thisunit->enabled = enabling;
                 break;
               }
             }                   /* search relevant unit */
               if (!strcmp(thisunit->name, unitname)) {
                 thisunit->enabled = enabling;
                 break;
               }
             }                   /* search relevant unit */
-            if (it2_unit == xbt_dynar_length(thissuite->units)) {
-              fprintf(stderr,
-                      "Suite '%s' has no unit of name '%s'. Cannot apply the selection\n",
-                      suitename, unitname);
-              exit(1);
-            }
+            xbt_assert(it2_unit != xbt_dynar_length(thissuite->units),
+                "Suite '%s' has no unit of name '%s'. Cannot apply the selection\n", suitename, unitname);
           }                     /* act on childs (either all or one) */
 
           break;                /* found the relevant serie. We are happy */
         }
       }                         /* search relevant series */
           }                     /* act on childs (either all or one) */
 
           break;                /* found the relevant serie. We are happy */
         }
       }                         /* search relevant series */
-      if (it == xbt_dynar_length(_xbt_test_suites)) {
-        fprintf(stderr,
-                "No suite of name '%s' found. Cannot apply the selection\n",
-                suitename);
-        exit(1);
-      }
+      xbt_assert(it != xbt_dynar_length(_xbt_test_suites), "No suite of name '%s' found. Cannot apply the selection\n", suitename);
     }
 
   }
     }
 
   }
@@ -632,19 +614,16 @@ int xbt_test_run(char *selection, int verbosity)
                 (double) _xbt_test_nb_suites) * 100.0)
             : 100.0, _xbt_test_nb_suites);
     if (_xbt_test_nb_suites != _xbt_test_suite_failed) {
                 (double) _xbt_test_nb_suites) * 100.0)
             : 100.0, _xbt_test_nb_suites);
     if (_xbt_test_nb_suites != _xbt_test_suite_failed) {
-      fprintf(stderr, "%d ok",
-              _xbt_test_nb_suites - _xbt_test_suite_failed);
+      fprintf(stderr, "%d ok", _xbt_test_nb_suites - _xbt_test_suite_failed);
       first = 0;
     }
     if (_xbt_test_suite_failed) {
       first = 0;
     }
     if (_xbt_test_suite_failed) {
-      fprintf(stderr, "%s%d failed", (first ? "" : ", "),
-              _xbt_test_suite_failed);
+      fprintf(stderr, "%s%d failed", (first ? "" : ", "), _xbt_test_suite_failed);
       first = 0;
     }
 
     if (_xbt_test_suite_ignore) {
       first = 0;
     }
 
     if (_xbt_test_suite_ignore) {
-      fprintf(stderr, "%s%d ignored", (first ? "" : ", "),
-              _xbt_test_suite_ignore);
+      fprintf(stderr, "%s%d ignored", (first ? "" : ", "), _xbt_test_suite_ignore);
     }
     fprintf(stderr, ")\n        Units:  %.0f%% ok (%d units: ",
             _xbt_test_nb_units
     }
     fprintf(stderr, ")\n        Units:  %.0f%% ok (%d units: ",
             _xbt_test_nb_units
@@ -654,18 +633,15 @@ int xbt_test_run(char *selection, int verbosity)
             _xbt_test_nb_units);
     first = 1;
     if (_xbt_test_nb_units != _xbt_test_unit_failed) {
             _xbt_test_nb_units);
     first = 1;
     if (_xbt_test_nb_units != _xbt_test_unit_failed) {
-      fprintf(stderr, "%s%d ok", (first ? "" : ", "),
-              _xbt_test_nb_units - _xbt_test_unit_failed);
+      fprintf(stderr, "%s%d ok", (first ? "" : ", "), _xbt_test_nb_units - _xbt_test_unit_failed);
       first = 0;
     }
     if (_xbt_test_unit_failed) {
       first = 0;
     }
     if (_xbt_test_unit_failed) {
-      fprintf(stderr, "%s%d failed", (first ? "" : ", "),
-              _xbt_test_unit_failed);
+      fprintf(stderr, "%s%d failed", (first ? "" : ", "), _xbt_test_unit_failed);
       first = 0;
     }
     if (_xbt_test_unit_ignore) {
       first = 0;
     }
     if (_xbt_test_unit_ignore) {
-      fprintf(stderr, "%s%d ignored", (first ? "" : ", "),
-              _xbt_test_unit_ignore);
+      fprintf(stderr, "%s%d ignored", (first ? "" : ", "), _xbt_test_unit_ignore);
     }
     fprintf(stderr, ")\n        Tests:  %.0f%% ok (%d tests: ",
             _xbt_test_nb_tests
     }
     fprintf(stderr, ")\n        Tests:  %.0f%% ok (%d tests: ",
             _xbt_test_nb_tests
@@ -675,23 +651,19 @@ int xbt_test_run(char *selection, int verbosity)
             _xbt_test_nb_tests);
     first = 1;
     if (_xbt_test_nb_tests != _xbt_test_test_failed) {
             _xbt_test_nb_tests);
     first = 1;
     if (_xbt_test_nb_tests != _xbt_test_test_failed) {
-      fprintf(stderr, "%s%d ok", (first ? "" : ", "),
-              _xbt_test_nb_tests - _xbt_test_test_failed);
+      fprintf(stderr, "%s%d ok", (first ? "" : ", "), _xbt_test_nb_tests - _xbt_test_test_failed);
       first = 0;
     }
     if (_xbt_test_test_failed) {
       first = 0;
     }
     if (_xbt_test_test_failed) {
-      fprintf(stderr, "%s%d failed", (first ? "" : ", "),
-              _xbt_test_test_failed);
+      fprintf(stderr, "%s%d failed", (first ? "" : ", "), _xbt_test_test_failed);
       first = 0;
     }
     if (_xbt_test_test_ignore) {
       first = 0;
     }
     if (_xbt_test_test_ignore) {
-      fprintf(stderr, "%s%d ignored", (first ? "" : ", "),
-              _xbt_test_test_ignore);
+      fprintf(stderr, "%s%d ignored", (first ? "" : ", "), _xbt_test_test_ignore);
       first = 0;
     }
     if (_xbt_test_test_expect) {
       first = 0;
     }
     if (_xbt_test_test_expect) {
-      fprintf(stderr, "%s%d expected to fail", (first ? "" : ", "),
-              _xbt_test_test_expect);
+      fprintf(stderr, "%s%d expected to fail", (first ? "" : ", "), _xbt_test_test_expect);
     }
 
     fprintf(stderr, ")\n");
     }
 
     fprintf(stderr, ")\n");
@@ -711,13 +683,10 @@ void xbt_test_exit(void)
 void _xbt_test_add(const char *file, int line, const char *fmt, ...)
 {
   xbt_test_unit_t unit = _xbt_test_current_unit;
 void _xbt_test_add(const char *file, int line, const char *fmt, ...)
 {
   xbt_test_unit_t unit = _xbt_test_current_unit;
-  xbt_test_test_t test;
-  va_list ap;
-
   xbt_assert(unit);
   xbt_assert(unit);
-  xbt_assert(fmt);
 
 
-  test = xbt_new0(struct s_xbt_test_test, 1);
+  va_list ap;
+  xbt_test_test_t test = xbt_new0(struct s_xbt_test_test, 1);
   va_start(ap, fmt);
   test->title = bvprintf(fmt, ap);
   va_end(ap);
   va_start(ap, fmt);
   test->title = bvprintf(fmt, ap);
   va_end(ap);
@@ -735,25 +704,19 @@ void _xbt_test_add(const char *file, int line, const char *fmt, ...)
 void _xbt_test_fail(const char *file, int line, const char *fmt, ...)
 {
   xbt_test_unit_t unit = _xbt_test_current_unit;
 void _xbt_test_fail(const char *file, int line, const char *fmt, ...)
 {
   xbt_test_unit_t unit = _xbt_test_current_unit;
-  xbt_test_test_t test;
-  xbt_test_log_t log;
-  va_list ap;
-
   xbt_assert(unit);
   xbt_assert(unit);
-  xbt_assert(fmt);
-
   xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests),
   xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests),
-              "Test failed even before being declared (broken unit: %s)",
-              unit->title);
+      "Test failed even before being declared (broken unit: %s)", unit->title);
 
 
-  log = xbt_new(struct s_xbt_test_log, 1);
+  va_list ap;
+  xbt_test_log_t log = xbt_new(struct s_xbt_test_log, 1);
   va_start(ap, fmt);
   log->text = bvprintf(fmt, ap);
   va_end(ap);
   log->file = file;
   log->line = line;
 
   va_start(ap, fmt);
   log->text = bvprintf(fmt, ap);
   va_end(ap);
   log->file = file;
   log->line = line;
 
-  test = xbt_dynar_getlast_as(unit->tests, xbt_test_test_t);
+  xbt_test_test_t test = xbt_dynar_getlast_as(unit->tests, xbt_test_test_t);
   xbt_dynar_push(test->logs, &log);
 
   test->failed = 1;
   xbt_dynar_push(test->logs, &log);
 
   test->failed = 1;
@@ -761,31 +724,22 @@ void _xbt_test_fail(const char *file, int line, const char *fmt, ...)
 
 void xbt_test_exception(xbt_ex_t e)
 {
 
 void xbt_test_exception(xbt_ex_t e)
 {
-  _xbt_test_fail(e.file, e.line, "Exception %s raised: %s",
-                 xbt_ex_catname(e.category), e.msg);
+  _xbt_test_fail(e.file, e.line, "Exception %s raised: %s", xbt_ex_catname(e.category), e.msg);
 }
 
 void xbt_test_expect_failure(void)
 {
 }
 
 void xbt_test_expect_failure(void)
 {
-  xbt_test_test_t test;
   xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests),
   xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests),
-              "Cannot expect the failure of a test before declaring it (broken unit: %s)",
-              _xbt_test_current_unit->title);
-  test =
-      xbt_dynar_getlast_as(_xbt_test_current_unit->tests, xbt_test_test_t);
+      "Cannot expect the failure of a test before declaring it (broken unit: %s)", _xbt_test_current_unit->title);
+  xbt_test_test_t test = xbt_dynar_getlast_as(_xbt_test_current_unit->tests, xbt_test_test_t);
   test->expected_failure = 1;
 }
 
 void xbt_test_skip(void)
 {
   test->expected_failure = 1;
 }
 
 void xbt_test_skip(void)
 {
-  xbt_test_test_t test;
-
   xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests),
   xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests),
-              "Test skiped even before being declared (broken unit: %s)",
-              _xbt_test_current_unit->title);
-
-  test =
-      xbt_dynar_getlast_as(_xbt_test_current_unit->tests, xbt_test_test_t);
+      "Test skiped even before being declared (broken unit: %s)", _xbt_test_current_unit->title);
+  xbt_test_test_t test = xbt_dynar_getlast_as(_xbt_test_current_unit->tests, xbt_test_test_t);
   test->ignored = 1;
 }
 
   test->ignored = 1;
 }
 
@@ -793,31 +747,23 @@ void xbt_test_skip(void)
 void _xbt_test_log(const char *file, int line, const char *fmt, ...)
 {
   xbt_test_unit_t unit = _xbt_test_current_unit;
 void _xbt_test_log(const char *file, int line, const char *fmt, ...)
 {
   xbt_test_unit_t unit = _xbt_test_current_unit;
-  xbt_test_test_t test;
-  xbt_test_log_t log;
-  va_list ap;
-
   xbt_assert(unit);
   xbt_assert(unit);
-  xbt_assert(fmt);
-
   xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests),
   xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests),
-              "Test logged into even before being declared (broken test unit: %s)",
-              unit->title);
+      "Test logged into even before being declared (broken test unit: %s)", unit->title);
 
 
-  log = xbt_new(struct s_xbt_test_log, 1);
+  va_list ap;
+  xbt_test_log_t log = xbt_new(struct s_xbt_test_log, 1);
   va_start(ap, fmt);
   log->text = bvprintf(fmt, ap);
   va_end(ap);
   log->file = file;
   log->line = line;
 
   va_start(ap, fmt);
   log->text = bvprintf(fmt, ap);
   va_end(ap);
   log->file = file;
   log->line = line;
 
-  test = xbt_dynar_getlast_as(unit->tests, xbt_test_test_t);
+  xbt_test_test_t test = xbt_dynar_getlast_as(unit->tests, xbt_test_test_t);
   xbt_dynar_push(test->logs, &log);
 }
 
 
   xbt_dynar_push(test->logs, &log);
 }
 
 
-
-
 #ifdef SIMGRID_TEST
 
 XBT_TEST_SUITE("cunit", "Testsuite mechanism autotest");
 #ifdef SIMGRID_TEST
 
 XBT_TEST_SUITE("cunit", "Testsuite mechanism autotest");