X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4a201b7ceece70d2bc461ac48c8b746a36d07243..2652a7d2c9ebb969683d8fd94b11c96489327912:/src/xbt/cunit.c diff --git a/src/xbt/cunit.c b/src/xbt/cunit.c index 8b9204c0d5..a3015fe86c 100644 --- a/src/xbt/cunit.c +++ b/src/xbt/cunit.c @@ -1,15 +1,18 @@ /* cunit - A little C Unit facility */ -/* Copyright (c) 2005 Martin Quinson. All rights reserved. */ +/* Copyright (c) 2005-2014. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ /* This is partially inspirated from the OSSP ts (Test Suite Library) */ +/* At some point we should use https://github.com/google/googletest instead */ -#include "portable.h" +#include "src/internal_config.h" +#include -#include "xbt/sysdep.h" /* vasprintf */ +#include "xbt/sysdep.h" /* bvprintf */ #include "xbt/cunit.h" #include "xbt/dynar.h" @@ -34,7 +37,6 @@ static int _xbt_test_suite_disabled = 0; /* Context */ xbt_test_unit_t _xbt_test_current_unit = NULL; - /* test suite test log */ typedef struct s_xbt_test_log { char *text; @@ -45,8 +47,7 @@ typedef struct s_xbt_test_log { static void xbt_test_log_dump(xbt_test_log_t log) { if (log) - fprintf(stderr, " log %p(%s:%d)=%s\n", log, log->file, log->line, - log->text); + fprintf(stderr, " log %p(%s:%d)=%s\n", log, log->file, log->line, log->text); else fprintf(stderr, " log=NULL\n"); } @@ -67,11 +68,10 @@ static void xbt_test_test_dump(xbt_test_test_t test) if (test) { xbt_test_log_t log; unsigned int it_log; - fprintf(stderr, " test %p(%s:%d)=%s (%s)\n", - test, test->file, test->line, test->title, + fprintf(stderr, " test %p(%s:%d)=%s (%s)\n", test, test->file, test->line, test->title, test->failed ? "failed" : "not failed"); xbt_dynar_foreach(test->logs, it_log, log) - xbt_test_log_dump(log); + xbt_test_log_dump(log); } else fprintf(stderr, " test=NULL\n"); } @@ -95,12 +95,10 @@ static void xbt_test_unit_dump(xbt_test_unit_t unit) if (unit) { xbt_test_test_t test; unsigned int it_test; - fprintf(stderr, " UNIT %s: %s (%s)\n", - unit->name, unit->title, - (unit->enabled ? "enabled" : "disabled")); + fprintf(stderr, " UNIT %s: %s (%s)\n", unit->name, unit->title, (unit->enabled ? "enabled" : "disabled")); if (unit->enabled) xbt_dynar_foreach(unit->tests, it_test, test) - xbt_test_test_dump(test); + xbt_test_test_dump(test); } else { fprintf(stderr, " unit=NULL\n"); } @@ -159,14 +157,12 @@ xbt_test_suite_t xbt_test_suite_new(const char *name, const char *fmt, ...) { xbt_test_suite_t suite = xbt_new0(struct s_xbt_test_suite, 1); va_list ap; - int vres; if (!_xbt_test_suites) - _xbt_test_suites = - xbt_dynar_new(sizeof(xbt_test_suite_t), xbt_test_suite_free); + _xbt_test_suites = xbt_dynar_new(sizeof(xbt_test_suite_t), xbt_test_suite_free); va_start(ap, fmt); - vres = vasprintf(&suite->title, fmt, ap); + suite->title = bvprintf(fmt, ap); suite->units = xbt_dynar_new(sizeof(xbt_test_unit_t), &xbt_test_unit_free); va_end(ap); suite->name = name; @@ -178,23 +174,21 @@ xbt_test_suite_t xbt_test_suite_new(const char *name, const char *fmt, ...) } /** @brief retrieve a testsuite from name, or create a new one */ -xbt_test_suite_t xbt_test_suite_by_name(const char *name, const char *fmt, - ...) +xbt_test_suite_t xbt_test_suite_by_name(const char *name, const char *fmt, ...) { xbt_test_suite_t suite; unsigned int it_suite; char *bufname; va_list ap; - int vres; if (_xbt_test_suites) xbt_dynar_foreach(_xbt_test_suites, it_suite, suite) - if (!strcmp(suite->name, name)) + if (!strcmp(suite->name, name)) return suite; va_start(ap, fmt); - vres = vasprintf(&bufname, fmt, ap); + bufname = bvprintf(fmt, ap); va_end(ap); suite = xbt_test_suite_new(name, bufname, NULL); free(bufname); @@ -207,24 +201,20 @@ void xbt_test_suite_dump(xbt_test_suite_t suite) if (suite) { xbt_test_unit_t unit; unsigned int it_unit; - fprintf(stderr, "TESTSUITE %s: %s (%s)\n", - suite->name, suite->title, - suite->enabled ? "enabled" : "disabled"); + fprintf(stderr, "TESTSUITE %s: %s (%s)\n", suite->name, suite->title, suite->enabled ? "enabled" : "disabled"); if (suite->enabled) xbt_dynar_foreach(suite->units, it_unit, unit) - xbt_test_unit_dump(unit); + xbt_test_unit_dump(unit); } else { fprintf(stderr, "TESTSUITE IS NULL!\n"); } } /* add test case to test suite */ -void xbt_test_suite_push(xbt_test_suite_t suite, const char *name, - ts_test_cb_t func, const char *fmt, ...) +void xbt_test_suite_push(xbt_test_suite_t suite, const char *name, ts_test_cb_t func, const char *fmt, ...) { xbt_test_unit_t unit; va_list ap; - int vres; xbt_assert(suite); xbt_assert(func); @@ -232,7 +222,7 @@ void xbt_test_suite_push(xbt_test_suite_t suite, const char *name, unit = xbt_new0(struct s_xbt_test_unit, 1); va_start(ap, fmt); - vres = vasprintf(&unit->title, fmt, ap); + unit->title = bvprintf(fmt, ap); va_end(ap); unit->name = (char *) name; unit->func = func; @@ -246,7 +236,7 @@ void xbt_test_suite_push(xbt_test_suite_t suite, const char *name, } /* run test one suite */ -static int xbt_test_suite_run(xbt_test_suite_t suite) +static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity) { xbt_test_unit_t unit; xbt_test_test_t test; @@ -258,7 +248,6 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) unsigned int it_unit, it_test, it_log; int first = 1; /* for result pretty printing */ - int vres; if (suite == NULL) return 0; @@ -269,9 +258,7 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) int suite_len = strlen(suite->title); int i; - xbt_assert2(suite_len < 68, - "suite title \"%s\" too long (%d should be less than 68", - suite->title, suite_len); + xbt_assert(suite_len < 68, "suite title \"%s\" too long (%d should be less than 68", suite->title, suite_len); suite_title[0] = ' '; for (i = 1; i < 80; i++) @@ -296,8 +283,8 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) unit->test_expect = 0; /* display unit title */ - vres = asprintf(&cp, " Unit: %s ......................................" - "......................................", unit->title); + cp = bprintf(" Unit: %s ......................................" + "......................................", unit->title); cp[70] = '\0'; fprintf(stderr, "%s", cp); free(cp); @@ -322,10 +309,8 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) unit->test_expect++; } } - - /* Display whether this unit went well */ - if (unit->test_failed > 0 || unit->test_expect) { + if (unit->test_failed > 0 || unit->test_expect || (verbosity && unit->nb_tests > 0)) { /* some tests failed (or were supposed to), so do detailed reporting of test case */ if (unit->test_failed > 0) { fprintf(stderr, ".. failed\n"); @@ -337,33 +322,23 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) xbt_dynar_foreach(unit->tests, it_test, test) { file = (test->file != NULL ? test->file : unit->file); line = (test->line != 0 ? test->line : unit->line); - fprintf(stderr, " %s: %s [%s:%d]\n", - (test->ignored ? " SKIP" - : (test->expected_failure - ? (test->failed ? "EFAIL" : "EPASS") : (test->failed ? - " FAIL" : - " PASS"))), - test->title, file, line); - - if ((test->expected_failure && !test->failed) - || (!test->expected_failure && test->failed)) { + fprintf(stderr, " %s: %s [%s:%d]\n", (test->ignored ? " SKIP" : (test->expected_failure + ? (test-> failed ? "EFAIL" : "EPASS") : (test->failed ? " FAIL" : " PASS"))),test->title, file, line); + + if ((test->expected_failure && !test->failed) || (!test->expected_failure && test->failed)) { xbt_dynar_foreach(test->logs, it_log, log) { file = (log->file != NULL ? log->file : file); line = (log->line != 0 ? log->line : line); - fprintf(stderr, " %s:%d: %s\n", - file, line, log->text); - + fprintf(stderr, " %s:%d: %s\n", file, line, log->text); } } } - fprintf(stderr, " Summary: %d of %d tests failed", - unit->test_failed, unit->nb_tests); + fprintf(stderr, " Summary: %d of %d tests failed", unit->test_failed, unit->nb_tests); if (unit->test_ignore) { fprintf(stderr, " (%d tests ignored)\n", unit->test_ignore); } else { fprintf(stderr, "\n"); } - } else if (!unit->enabled) { fprintf(stderr, " disabled\n"); /* no test were run */ } else if (unit->nb_tests) { @@ -410,24 +385,16 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) _xbt_test_suite_ignore++; } - /* print test suite summary */ if (suite->enabled) { - - fprintf(stderr, - " =====================================================================%s\n", - (suite->nb_units - ? (suite->unit_failed ? "== FAILED" : "====== OK") - : (suite->unit_disabled ? " DISABLED" : "==== SKIP"))); - fprintf(stderr, " Summary: Units: %.0f%% ok (%d units: ", - suite->nb_units - ? ((1 - - (double) suite->unit_failed / (double) suite->nb_units) * - 100.0) : 100.0, suite->nb_units); + fprintf(stderr," =====================================================================%s\n", + (suite->nb_units ? (suite->unit_failed ? "== FAILED" : "====== OK") : + (suite->unit_disabled ? " DISABLED" : "==== SKIP"))); + fprintf(stderr, " Summary: Units: %.0f%% ok (%d units: ", suite->nb_units + ? ((1 - (double) suite->unit_failed / (double) suite->nb_units) * 100.0) : 100.0, suite->nb_units); if (suite->nb_units != suite->unit_failed) { - fprintf(stderr, "%s%d ok", (first ? "" : ", "), - suite->nb_units - suite->unit_failed); + fprintf(stderr, "%s%d ok", (first ? "" : ", "), suite->nb_units - suite->unit_failed); first = 0; } if (suite->unit_failed) { @@ -435,25 +402,18 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) first = 0; } if (suite->unit_ignore) { - fprintf(stderr, "%s%d ignored", (first ? "" : ", "), - suite->unit_ignore); + fprintf(stderr, "%s%d ignored", (first ? "" : ", "), suite->unit_ignore); first = 0; } if (suite->unit_disabled) { - fprintf(stderr, "%s%d disabled", (first ? "" : ", "), - suite->unit_disabled); - first = 0; + fprintf(stderr, "%s%d disabled", (first ? "" : ", "), suite->unit_disabled); } - fprintf(stderr, ")\n Tests: %.0f%% ok (%d tests: ", - suite->nb_tests - ? ((1 - - (double) suite->test_failed / (double) suite->nb_tests) * - 100.0) : 100.0, suite->nb_tests); + fprintf(stderr, ")\n Tests: %.0f%% ok (%d tests: ", suite->nb_tests + ? ((1 - (double) suite->test_failed / (double) suite->nb_tests) * 100.0) : 100.0, suite->nb_tests); first = 1; if (suite->nb_tests != suite->test_failed) { - fprintf(stderr, "%s%d ok", (first ? "" : ", "), - suite->nb_tests - suite->test_failed); + fprintf(stderr, "%s%d ok", (first ? "" : ", "), suite->nb_tests - suite->test_failed); first = 0; } if (suite->test_failed) { @@ -461,14 +421,11 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) first = 0; } if (suite->test_ignore) { - fprintf(stderr, "%s%d ignored", (first ? "" : "; "), - suite->test_ignore); + fprintf(stderr, "%s%d ignored", (first ? "" : "; "), suite->test_ignore); first = 0; } if (suite->test_expect) { - fprintf(stderr, "%s%d expected to fail", (first ? "" : "; "), - suite->test_expect); - first = 0; + fprintf(stderr, "%s%d expected to fail", (first ? "" : "; "), suite->test_expect); } fprintf(stderr, ")\n"); } @@ -479,7 +436,6 @@ static void apply_selection(char *selection) { /* for the parsing */ char *sel = selection; - char *p; int done = 0; char dir[1024]; /* the directive */ /* iterators */ @@ -500,7 +456,7 @@ static void apply_selection(char *selection) while (!done) { int enabling = 1; - p = strchr(sel, ','); + char *p = strchr(sel, ','); if (p) { strncpy(dir, sel, p - sel); dir[p - sel] = '\0'; @@ -528,16 +484,10 @@ static void apply_selection(char *selection) 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)) { - 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) { @@ -549,7 +499,7 @@ static void apply_selection(char *selection) unsigned int it; for (it = 0; it < xbt_dynar_length(_xbt_test_suites); it++) { xbt_test_suite_t thissuite = - xbt_dynar_get_as(_xbt_test_suites, it, xbt_test_suite_t); + xbt_dynar_get_as(_xbt_test_suites, it, xbt_test_suite_t); if (!strcmp(suitename, thissuite->name)) { /* Do not disable the whole suite when we just want to disable a child */ if (enabling || (unitname[0] == '\0')) @@ -562,34 +512,25 @@ static void apply_selection(char *selection) } else { /* act on one child only */ unsigned int it2_unit; /* search it, first (we won't reuse it for external loop which gets broken) */ - for (it2_unit = 0; it2_unit < xbt_dynar_length(thissuite->units); + 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 (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 */ - 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); } - } } @@ -602,13 +543,13 @@ void xbt_test_dump(char *selection) xbt_test_suite_t suite; xbt_dynar_foreach(_xbt_test_suites, it_suite, suite) - xbt_test_suite_dump(suite); + xbt_test_suite_dump(suite); } else { printf(" No suite defined."); } } -int xbt_test_run(char *selection) +int xbt_test_run(char *selection, int verbosity) { apply_selection(selection); @@ -619,77 +560,55 @@ int xbt_test_run(char *selection) /* Run all the suites */ xbt_dynar_foreach(_xbt_test_suites, it_suite, suite) - xbt_test_suite_run(suite); + xbt_test_suite_run(suite, verbosity); /* Display some more statistics */ - fprintf(stderr, "\n\n TOTAL: Suites: %.0f%% ok (%d suites: ", - _xbt_test_nb_suites - ? ((1 - - (double) _xbt_test_suite_failed / - (double) _xbt_test_nb_suites) * 100.0) + fprintf(stderr, "\n\n TOTAL: Suites: %.0f%% ok (%d suites: ",_xbt_test_nb_suites + ? ((1 - (double) _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); 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) { - fprintf(stderr, "%s%d ignored", (first ? "" : ", "), - _xbt_test_suite_ignore); - first = 0; + fprintf(stderr, "%s%d ignored", (first ? "" : ", "), _xbt_test_suite_ignore); } - fprintf(stderr, ")\n Units: %.0f%% ok (%d units: ", - _xbt_test_nb_units - ? ((1 - - (double) _xbt_test_unit_failed / - (double) _xbt_test_nb_units) * 100.0) : 100.0, - _xbt_test_nb_units); + fprintf(stderr, ")\n Units: %.0f%% ok (%d units: ", _xbt_test_nb_units + ? ((1 - (double) _xbt_test_unit_failed / (double) _xbt_test_nb_units) * 100.0) : 100.0, _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) { - 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) { - fprintf(stderr, "%s%d ignored", (first ? "" : ", "), - _xbt_test_unit_ignore); - first = 0; + fprintf(stderr, "%s%d ignored", (first ? "" : ", "), _xbt_test_unit_ignore); } - fprintf(stderr, ")\n Tests: %.0f%% ok (%d tests: ", - _xbt_test_nb_tests - ? ((1 - - (double) _xbt_test_test_failed / - (double) _xbt_test_nb_tests) * 100.0) : 100.0, - _xbt_test_nb_tests); + fprintf(stderr, ")\n Tests: %.0f%% ok (%d tests: ", _xbt_test_nb_tests + ? ((1 - (double) _xbt_test_test_failed / (double) _xbt_test_nb_tests) * 100.0) : 100.0, _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) { - 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) { - 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) { - 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"); @@ -709,16 +628,12 @@ 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; - xbt_test_test_t test; - va_list ap; - int vres; - 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); - vres = vasprintf(&test->title, fmt, ap); + test->title = bvprintf(fmt, ap); va_end(ap); test->failed = 0; test->expected_failure = 0; @@ -734,26 +649,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; - xbt_test_test_t test; - xbt_test_log_t log; - va_list ap; - int vres; - xbt_assert(unit); - xbt_assert(fmt); - - xbt_assert1(xbt_dynar_length(_xbt_test_current_unit->tests), - "Test failed even before being declared (broken unit: %s)", - unit->title); + xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests), + "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); - vres = vasprintf(&log->text, fmt, ap); + 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; @@ -761,29 +669,22 @@ void _xbt_test_fail(const char *file, int line, const char *fmt, ...) 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) { - xbt_test_test_t test; - xbt_assert1(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); + 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); + 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) { - xbt_test_test_t test; - - xbt_assert1(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); + xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests), + "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; } @@ -791,45 +692,33 @@ 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; - xbt_test_test_t test; - xbt_test_log_t log; - va_list ap; - int vres; - xbt_assert(unit); - xbt_assert(fmt); - - xbt_assert1(xbt_dynar_length(_xbt_test_current_unit->tests), - "Test logged into even before being declared (broken test unit: %s)", - unit->title); + xbt_assert(xbt_dynar_length(_xbt_test_current_unit->tests), + "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); - vres = vasprintf(&log->text, fmt, ap); + 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); } - - - #ifdef SIMGRID_TEST - XBT_TEST_SUITE("cunit", "Testsuite mechanism autotest"); XBT_TEST_UNIT("expect", test_expected_failure, "expected failures") { - xbt_test_add0("Skipped test"); + xbt_test_add("Skipped test"); xbt_test_skip(); - xbt_test_add2("%s %s", "EXPECTED", "FAILURE"); + xbt_test_add("%s %s", "EXPECTED", "FAILURE"); xbt_test_expect_failure(); - xbt_test_log2("%s %s", "Test", "log"); - xbt_test_fail0("EXPECTED FAILURE"); + xbt_test_log("%s %s", "Test", "log"); + xbt_test_fail("EXPECTED FAILURE"); } - -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */