X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0f5e8daaa6e9f74521068aa75837200bcd182ea6..b2252602473b26e442a9c96b4f28dc089deb19f4:/src/xbt/cunit.c diff --git a/src/xbt/cunit.c b/src/xbt/cunit.c index 97f37ea5c3..08f52bb112 100644 --- a/src/xbt/cunit.c +++ b/src/xbt/cunit.c @@ -1,6 +1,6 @@ /* cunit - A little C Unit facility */ -/* Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2005-2014. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -10,7 +10,7 @@ #include "portable.h" -#include "xbt/sysdep.h" /* vasprintf */ +#include "xbt/sysdep.h" /* bvprintf */ #include "xbt/cunit.h" #include "xbt/dynar.h" @@ -160,14 +160,13 @@ 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); 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); @@ -188,7 +187,6 @@ xbt_test_suite_t xbt_test_suite_by_name(const char *name, const char *fmt, char *bufname; va_list ap; - int vres; if (_xbt_test_suites) xbt_dynar_foreach(_xbt_test_suites, it_suite, suite) @@ -196,7 +194,7 @@ xbt_test_suite_t xbt_test_suite_by_name(const char *name, const char *fmt, 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); @@ -226,7 +224,6 @@ void xbt_test_suite_push(xbt_test_suite_t suite, const char *name, { xbt_test_unit_t unit; va_list ap; - int vres; xbt_assert(suite); xbt_assert(func); @@ -234,7 +231,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; @@ -248,7 +245,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; @@ -260,7 +257,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; @@ -271,7 +267,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, + xbt_assert(suite_len < 68, "suite title \"%s\" too long (%d should be less than 68", suite->title, suite_len); @@ -299,9 +295,7 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) unit->test_expect = 0; /* display unit title */ - vres = - asprintf(&cp, - " Unit: %s ......................................" + cp = bprintf(" Unit: %s ......................................" "......................................", unit->title); cp[70] = '\0'; fprintf(stderr, "%s", cp); @@ -330,7 +324,8 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) /* 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"); @@ -449,7 +444,6 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) if (suite->unit_disabled) { fprintf(stderr, "%s%d disabled", (first ? "" : ", "), suite->unit_disabled); - first = 0; } fprintf(stderr, ")\n Tests: %.0f%% ok (%d tests: ", suite->nb_tests @@ -476,7 +470,6 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) if (suite->test_expect) { fprintf(stderr, "%s%d expected to fail", (first ? "" : "; "), suite->test_expect); - first = 0; } fprintf(stderr, ")\n"); } @@ -618,7 +611,7 @@ void xbt_test_dump(char *selection) } } -int xbt_test_run(char *selection) +int xbt_test_run(char *selection, int verbosity) { apply_selection(selection); @@ -629,7 +622,7 @@ 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: ", @@ -652,7 +645,6 @@ int xbt_test_run(char *selection) if (_xbt_test_suite_ignore) { fprintf(stderr, "%s%d ignored", (first ? "" : ", "), _xbt_test_suite_ignore); - first = 0; } fprintf(stderr, ")\n Units: %.0f%% ok (%d units: ", _xbt_test_nb_units @@ -674,7 +666,6 @@ int xbt_test_run(char *selection) if (_xbt_test_unit_ignore) { fprintf(stderr, "%s%d ignored", (first ? "" : ", "), _xbt_test_unit_ignore); - first = 0; } fprintf(stderr, ")\n Tests: %.0f%% ok (%d tests: ", _xbt_test_nb_tests @@ -722,14 +713,13 @@ 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_start(ap, fmt); - vres = vasprintf(&test->title, fmt, ap); + test->title = bvprintf(fmt, ap); va_end(ap); test->failed = 0; test->expected_failure = 0; @@ -748,18 +738,17 @@ void _xbt_test_fail(const char *file, int line, const char *fmt, ...) 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), + 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_start(ap, fmt); - vres = vasprintf(&log->text, fmt, ap); + log->text = bvprintf(fmt, ap); va_end(ap); log->file = file; log->line = line; @@ -779,7 +768,7 @@ void xbt_test_exception(xbt_ex_t e) void xbt_test_expect_failure(void) { xbt_test_test_t test; - xbt_assert1(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 = @@ -791,7 +780,7 @@ void xbt_test_skip(void) { xbt_test_test_t test; - xbt_assert1(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); @@ -807,18 +796,17 @@ void _xbt_test_log(const char *file, int line, const char *fmt, ...) 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), + 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_start(ap, fmt); - vres = vasprintf(&log->text, fmt, ap); + log->text = bvprintf(fmt, ap); va_end(ap); log->file = file; log->line = line; @@ -836,13 +824,13 @@ 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 */