The test_assert() function that backs my custom assert() macro
now returns a value, which supports such convenient constructs as: if (assert(NULL != foo())) { } Also be careful to setlocale("C") for each new test to avoid locale pollution. Also a couple of minor portability enhancements.
This commit is contained in:
parent
88b1623cab
commit
c300e636ea
@ -34,11 +34,8 @@
|
||||
*/
|
||||
#define PROGRAM "LIBARCHIVE"
|
||||
|
||||
/*
|
||||
* Various utility routines useful for test programs.
|
||||
* Each test program is linked against this file.
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <locale.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
@ -226,20 +223,21 @@ failure(const char *fmt, ...)
|
||||
}
|
||||
|
||||
/* Generic assert() just displays the failed condition. */
|
||||
void
|
||||
int
|
||||
test_assert(const char *file, int line, int value, const char *condition, void *extra)
|
||||
{
|
||||
++assertions;
|
||||
if (value) {
|
||||
msg[0] = '\0';
|
||||
return;
|
||||
return (value);
|
||||
}
|
||||
failures ++;
|
||||
if (previous_failures(file, line))
|
||||
return;
|
||||
return (value);
|
||||
fprintf(stderr, "%s:%d: Assertion failed\n", file, line);
|
||||
fprintf(stderr, " Condition: %s\n", condition);
|
||||
report_failure(extra);
|
||||
return (value);
|
||||
}
|
||||
|
||||
/* assertEqualInt() displays the values of the two integers. */
|
||||
@ -553,6 +551,8 @@ static int test_run(int i, const char *tmpdir)
|
||||
tests[i].name);
|
||||
exit(1);
|
||||
}
|
||||
/* Explicitly reset the locale before each test. */
|
||||
setlocale(LC_ALL, "C");
|
||||
/* Run the actual test. */
|
||||
(*tests[i].func)();
|
||||
/* Summarize the results of this test. */
|
||||
|
@ -31,8 +31,9 @@
|
||||
* The goal of this file (and the matching test.c) is to
|
||||
* simplify the very repetitive test-*.c test programs.
|
||||
*/
|
||||
|
||||
#ifndef _FILE_OFFSET_BITS
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@ -40,7 +41,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <wchar.h>
|
||||
|
||||
#ifdef USE_DMALLOC
|
||||
@ -112,7 +115,7 @@
|
||||
void failure(const char *fmt, ...);
|
||||
void test_setup(const char *, int);
|
||||
void test_skipping(const char *fmt, ...);
|
||||
void test_assert(const char *, int, int, const char *, void *);
|
||||
int test_assert(const char *, int, int, const char *, void *);
|
||||
void test_assert_empty_file(const char *, ...);
|
||||
void test_assert_equal_file(const char *, const char *, ...);
|
||||
void test_assert_equal_int(const char *, int, int, const char *, int, const char *, void *);
|
||||
|
Loading…
x
Reference in New Issue
Block a user