diff options
Diffstat (limited to 'tests/minicheck.c')
-rw-r--r-- | tests/minicheck.c | 83 |
1 files changed, 71 insertions, 12 deletions
diff --git a/tests/minicheck.c b/tests/minicheck.c index 5a1f5ed..be1e37e 100644 --- a/tests/minicheck.c +++ b/tests/minicheck.c @@ -1,14 +1,44 @@ /* Miniature re-implementation of the "check" library. - * - * This is intended to support just enough of check to run the Expat - * tests. This interface is based entirely on the portion of the - * check library being used. - */ + + This is intended to support just enough of check to run the Expat + tests. This interface is based entirely on the portion of the + check library being used. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 1997-2000 Thai Open Source Software Center Ltd + Copyright (c) 2000-2017 Expat development team + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ #include <stdio.h> #include <stdlib.h> #include <setjmp.h> #include <assert.h> +#include <string.h> #include "internal.h" /* for UNUSED_P only */ #include "minicheck.h" @@ -63,16 +93,39 @@ tcase_add_test(TCase *tc, tcase_test_function test) size_t new_size = sizeof(tcase_test_function) * nalloc; tcase_test_function *new_tests = realloc(tc->tests, new_size); assert(new_tests != NULL); - if (new_tests != tc->tests) { - free(tc->tests); - tc->tests = new_tests; - } + tc->tests = new_tests; tc->allocated = nalloc; } tc->tests[tc->ntests] = test; tc->ntests++; } +static void +tcase_free(TCase *tc) +{ + if (! tc) { + return; + } + + free(tc->tests); + free(tc); +} + +static void +suite_free(Suite *suite) +{ + if (! suite) { + return; + } + + while (suite->tests != NULL) { + TCase *next = suite->tests->next_tcase; + tcase_free(suite->tests); + suite->tests = next; + } + free(suite); +} + SRunner * srunner_create(Suite *suite) { @@ -163,8 +216,10 @@ _fail_unless(int UNUSED_P(condition), const char *UNUSED_P(file), int UNUSED_P(l we have a failure, so there's no reason to be quiet about what it is. */ - if (msg != NULL) - printf("%s", msg); + if (msg != NULL) { + const int has_newline = (msg[strlen(msg) - 1] == '\n'); + fprintf(stderr, "ERROR: %s%s", msg, has_newline ? "" : "\n"); + } longjmp(env, 1); } @@ -178,6 +233,10 @@ srunner_ntests_failed(SRunner *runner) void srunner_free(SRunner *runner) { - free(runner->suite); + if (! runner) { + return; + } + + suite_free(runner->suite); free(runner); } |