summaryrefslogtreecommitdiff
path: root/cpio
diff options
context:
space:
mode:
Diffstat (limited to 'cpio')
-rw-r--r--cpio/test/main.c323
-rw-r--r--cpio/test/test.h79
2 files changed, 265 insertions, 137 deletions
diff --git a/cpio/test/main.c b/cpio/test/main.c
index 90336a9e..23bb9516 100644
--- a/cpio/test/main.c
+++ b/cpio/test/main.c
@@ -40,8 +40,9 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/main.c,v 1.3 2008/08/24 04:58:22 kient
#define KNOWNREF "test_option_f.cpio.uu"
#define ENVBASE "BSDCPIO" /* Prefix for environment variables. */
#define PROGRAM "bsdcpio" /* Name of program being tested. */
-#undef LIBRARY /* Not testing a library. */
-#undef EXTRA_DUMP /* How to dump extra data */
+#undef LIBRARY /* Not testing a library. */
+#undef EXTRA_DUMP /* How to dump extra data */
+#undef EXTRA_ERRNO(x) /* How to dump errno */
/* How to generate extra version info. */
#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "")
@@ -78,6 +79,7 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/main.c,v 1.3 2008/08/24 04:58:22 kient
#endif
#if !defined(__BORLANDC__)
#define access _access
+#undef chdir
#define chdir _chdir
#endif
#ifndef fileno
@@ -253,13 +255,12 @@ failure(const char *fmt, ...)
* would be better off just removing it entirely. That would simplify
* the code here noticably.
*/
-static const char *test_filename;
-static int test_line;
-static void *test_extra;
-void assertion_setup(const char *filename, int line)
+static const char *skipping_filename;
+static int skipping_line;
+void skipping_setup(const char *filename, int line)
{
- test_filename = filename;
- test_line = line;
+ skipping_filename = filename;
+ skipping_line = line;
}
/* Called at the beginning of each assert() function. */
@@ -286,6 +287,7 @@ static struct line {
int count;
int skip;
} failed_lines[10000];
+const char *failed_filename;
/* Count this failure, setup up log destination and handle initial report. */
static void
@@ -295,19 +297,16 @@ failure_start(const char *filename, int line, const char *fmt, ...)
/* Record another failure for this line. */
++failures;
- /* test_filename = filename; */
+ failed_filename = filename;
failed_lines[line].count++;
/* Determine whether to log header to console. */
switch (verbosity) {
- case VERBOSITY_FULL:
- log_console = 1;
- break;
case VERBOSITY_LIGHT_REPORT:
log_console = (failed_lines[line].count < 2);
break;
default:
- log_console = 0;
+ log_console = (verbosity >= VERBOSITY_FULL);
}
/* Log file:line header for this failure */
@@ -343,14 +342,16 @@ failure_finish(void *extra)
{
(void)extra; /* UNUSED (maybe) */
#ifdef EXTRA_DUMP
- if (extra != NULL)
+ if (extra != NULL) {
+ logprintf(" errno: %d\n", EXTRA_ERRNO(extra));
logprintf(" detail: %s\n", EXTRA_DUMP(extra));
+ }
#endif
if (dump_on_failure) {
fprintf(stderr,
" *** forcing core dump so failure can be debugged ***\n");
- *(char *)(NULL) = 0;
+ abort();
exit(1);
}
}
@@ -365,12 +366,15 @@ test_skipping(const char *fmt, ...)
va_start(ap, fmt);
vsprintf(buff, fmt, ap);
va_end(ap);
+ /* Use failure() message if set. */
+ msg = nextmsg;
+ nextmsg = NULL;
/* failure_start() isn't quite right, but is awfully convenient. */
- failure_start(test_filename, test_line, "SKIPPING: %s", buff);
+ failure_start(skipping_filename, skipping_line, "SKIPPING: %s", buff);
--failures; /* Undo failures++ in failure_start() */
/* Don't failure_finish() here. */
/* Mark as skip, so doesn't count as failed test. */
- failed_lines[test_line].skip = 1;
+ failed_lines[skipping_line].skip = 1;
++skips;
}
@@ -427,7 +431,7 @@ static void strdump(const char *e, const char *p)
logprintf(" %s = ", e);
if (p == NULL) {
- logprintf("NULL");
+ logprintf("NULL\n");
return;
}
logprintf("\"");
@@ -592,9 +596,9 @@ assertion_equal_mem(const char *file, int line,
offset += 16;
}
logprintf(" Dump of %s\n", e1);
- hexdump(v1, v2, l < 64 ? l : 64, offset);
+ hexdump(v1, v2, l < 128 ? l : 128, offset);
logprintf(" Dump of %s\n", e2);
- hexdump(v2, v1, l < 64 ? l : 64, offset);
+ hexdump(v2, v1, l < 128 ? l : 128, offset);
logprintf("\n");
failure_finish(extra);
return (0);
@@ -602,29 +606,24 @@ assertion_equal_mem(const char *file, int line,
/* Verify that the named file exists and is empty. */
int
-assertion_empty_file(const char *f1fmt, ...)
+assertion_empty_file(const char *filename, int line, const char *f1)
{
char buff[1024];
- char f1[1024];
struct stat st;
- va_list ap;
ssize_t s;
FILE *f;
- assertion_count(test_filename, test_line);
- va_start(ap, f1fmt);
- vsprintf(f1, f1fmt, ap);
- va_end(ap);
+ assertion_count(filename, line);
if (stat(f1, &st) != 0) {
- failure_start(test_filename, test_line, "Stat failed: %s", f1);
+ failure_start(filename, line, "Stat failed: %s", f1);
failure_finish(NULL);
return (0);
}
if (st.st_size == 0)
return (1);
- failure_start(test_filename, test_line, "File should be empty: %s", f1);
+ failure_start(filename, line, "File should be empty: %s", f1);
logprintf(" File size: %d\n", (int)st.st_size);
logprintf(" Contents:\n");
f = fopen(f1, "rb");
@@ -643,24 +642,19 @@ assertion_empty_file(const char *f1fmt, ...)
/* Verify that the named file exists and is not empty. */
int
-assertion_non_empty_file(const char *f1fmt, ...)
+assertion_non_empty_file(const char *filename, int line, const char *f1)
{
- char f1[1024];
struct stat st;
- va_list ap;
- assertion_count(test_filename, test_line);
- va_start(ap, f1fmt);
- vsprintf(f1, f1fmt, ap);
- va_end(ap);
+ assertion_count(filename, line);
if (stat(f1, &st) != 0) {
- failure_start(test_filename, test_line, "Stat failed: %s", f1);
+ failure_start(filename, line, "Stat failed: %s", f1);
failure_finish(NULL);
return (0);
}
if (st.st_size == 0) {
- failure_start(test_filename, test_line, "File empty: %s", f1);
+ failure_start(filename, line, "File empty: %s", f1);
failure_finish(NULL);
return (0);
}
@@ -670,19 +664,14 @@ assertion_non_empty_file(const char *f1fmt, ...)
/* Verify that two files have the same contents. */
/* TODO: hexdump the first bytes that actually differ. */
int
-assertion_equal_file(const char *fn1, const char *f2pattern, ...)
+assertion_equal_file(const char *filename, int line, const char *fn1, const char *fn2)
{
- char fn2[1024];
- va_list ap;
char buff1[1024];
char buff2[1024];
FILE *f1, *f2;
int n1, n2;
- assertion_count(test_filename, test_line);
- va_start(ap, f2pattern);
- vsprintf(fn2, f2pattern, ap);
- va_end(ap);
+ assertion_count(filename, line);
f1 = fopen(fn1, "rb");
f2 = fopen(fn2, "rb");
@@ -701,24 +690,18 @@ assertion_equal_file(const char *fn1, const char *f2pattern, ...)
}
fclose(f1);
fclose(f2);
- failure_start(test_filename, test_line, "Files not identical");
+ failure_start(filename, line, "Files not identical");
logprintf(" file1=\"%s\"\n", fn1);
logprintf(" file2=\"%s\"\n", fn2);
- failure_finish(test_extra);
+ failure_finish(NULL);
return (0);
}
/* Verify that the named file does exist. */
int
-assertion_file_exists(const char *fpattern, ...)
+assertion_file_exists(const char *filename, int line, const char *f)
{
- char f[1024];
- va_list ap;
-
- assertion_count(test_filename, test_line);
- va_start(ap, fpattern);
- vsprintf(f, fpattern, ap);
- va_end(ap);
+ assertion_count(filename, line);
#if defined(_WIN32) && !defined(__CYGWIN__)
if (!_access(f, 0))
@@ -727,22 +710,16 @@ assertion_file_exists(const char *fpattern, ...)
if (!access(f, F_OK))
return (1);
#endif
- failure_start(test_filename, test_line, "File should exist: %s", f);
- failure_finish(test_extra);
+ failure_start(filename, line, "File should exist: %s", f);
+ failure_finish(NULL);
return (0);
}
/* Verify that the named file doesn't exist. */
int
-assertion_file_not_exists(const char *fpattern, ...)
+assertion_file_not_exists(const char *filename, int line, const char *f)
{
- char f[1024];
- va_list ap;
-
- assertion_count(test_filename, test_line);
- va_start(ap, fpattern);
- vsprintf(f, fpattern, ap);
- va_end(ap);
+ assertion_count(filename, line);
#if defined(_WIN32) && !defined(__CYGWIN__)
if (_access(f, 0))
@@ -751,31 +728,26 @@ assertion_file_not_exists(const char *fpattern, ...)
if (access(f, F_OK))
return (1);
#endif
- failure_start(test_filename, test_line, "File should not exist: %s", f);
- failure_finish(test_extra);
+ failure_start(filename, line, "File should not exist: %s", f);
+ failure_finish(NULL);
return (0);
}
/* Compare the contents of a file to a block of memory. */
int
-assertion_file_contents(const void *buff, int s, const char *fpattern, ...)
+assertion_file_contents(const char *filename, int line, const void *buff, int s, const char *fn)
{
- char fn[1024];
- va_list ap;
char *contents;
FILE *f;
int n;
- assertion_count(test_filename, test_line);
- va_start(ap, fpattern);
- vsprintf(fn, fpattern, ap);
- va_end(ap);
+ assertion_count(filename, line);
f = fopen(fn, "rb");
if (f == NULL) {
- failure_start(test_filename, test_line,
+ failure_start(filename, line,
"File should exist: %s", fn);
- failure_finish(test_extra);
+ failure_finish(NULL);
return (0);
}
contents = malloc(s * 2);
@@ -785,7 +757,7 @@ assertion_file_contents(const void *buff, int s, const char *fpattern, ...)
free(contents);
return (1);
}
- failure_start(test_filename, test_line, "File contents don't match");
+ failure_start(filename, line, "File contents don't match");
logprintf(" file=\"%s\"\n", fn);
if (n > 0)
hexdump(contents, buff, n > 512 ? 512 : n, 0);
@@ -793,26 +765,26 @@ assertion_file_contents(const void *buff, int s, const char *fpattern, ...)
logprintf(" File empty, contents should be:\n");
hexdump(buff, NULL, s > 512 ? 512 : n, 0);
}
- failure_finish(test_extra);
+ failure_finish(NULL);
free(contents);
return (0);
}
/* Check the contents of a text file, being tolerant of line endings. */
int
-assertion_text_file_contents(const char *buff, const char *fn)
+assertion_text_file_contents(const char *filename, int line, const char *buff, const char *fn)
{
char *contents;
const char *btxt, *ftxt;
FILE *f;
int n, s;
- assertion_count(test_filename, test_line);
+ assertion_count(filename, line);
f = fopen(fn, "r");
if (f == NULL) {
- failure_start(test_filename, test_line,
+ failure_start(filename, line,
"File doesn't exist: %s", fn);
- failure_finish(test_extra);
+ failure_finish(NULL);
return (0);
}
s = strlen(buff);
@@ -842,19 +814,122 @@ assertion_text_file_contents(const char *buff, const char *fn)
free(contents);
return (1);
}
- failure_start(test_filename, test_line, "Contents don't match");
+ failure_start(filename, line, "Contents don't match");
logprintf(" file=\"%s\"\n", fn);
- if (n > 0)
+ if (n > 0) {
hexdump(contents, buff, n, 0);
- else {
+ logprintf(" expected\n", fn);
+ hexdump(buff, contents, s, 0);
+ } else {
logprintf(" File empty, contents should be:\n");
hexdump(buff, NULL, s, 0);
}
- failure_finish(test_extra);
+ failure_finish(NULL);
free(contents);
return (0);
}
+/* Verify that a text file contains the specified lines, regardless of order */
+/* This could be more efficient if we sorted both sets of lines, etc, but
+ * since this is used only for testing and only ever deals with a dozen or so
+ * lines at a time, this relatively crude approach is just fine. */
+int
+assertion_file_contains_lines_any_order(const char *file, int line,
+ const char *pathname, const char *lines[])
+{
+ char *buff;
+ size_t buff_size;
+ size_t expected_count, actual_count, i, j;
+ char **expected;
+ char *p, **actual;
+ char c;
+ int expected_failure = 0, actual_failure = 0;
+
+ assertion_count(file, line);
+
+ buff = slurpfile(&buff_size, "%s", pathname);
+ if (buff == NULL) {
+ failure_start(pathname, line, "Can't read file: %s", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+
+ // Make a copy of the provided lines and count up the expected file size.
+ expected_count = 0;
+ for (i = 0; lines[i] != NULL; ++i) {
+ }
+ expected_count = i;
+ expected = malloc(sizeof(char *) * expected_count);
+ for (i = 0; lines[i] != NULL; ++i) {
+ expected[i] = strdup(lines[i]);
+ }
+
+ // Break the file into lines
+ actual_count = 0;
+ for (c = '\0', p = buff; p < buff + buff_size; ++p) {
+ if (*p == '\x0d' || *p == '\x0a')
+ *p = '\0';
+ if (c == '\0' && *p != '\0')
+ ++actual_count;
+ c = *p;
+ }
+ actual = malloc(sizeof(char *) * actual_count);
+ for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
+ if (*p != '\0') {
+ actual[j] = p;
+ ++j;
+ }
+ }
+
+ // Erase matching lines from both lists
+ for (i = 0; i < expected_count; ++i) {
+ if (expected[i] == NULL)
+ continue;
+ for (j = 0; j < actual_count; ++j) {
+ if (actual[j] == NULL)
+ continue;
+ if (strcmp(expected[i], actual[j]) == 0) {
+ free(expected[i]);
+ expected[i] = NULL;
+ actual[j] = NULL;
+ break;
+ }
+ }
+ }
+
+ // If there's anything left, it's a failure
+ for (i = 0; i < expected_count; ++i) {
+ if (expected[i] != NULL)
+ ++expected_failure;
+ }
+ for (j = 0; j < actual_count; ++j) {
+ if (actual[j] != NULL)
+ ++actual_failure;
+ }
+ if (expected_failure == 0 && actual_failure == 0) {
+ free(buff);
+ free(expected);
+ free(actual);
+ return (1);
+ }
+ failure_start(file, line, "File doesn't match: %s", pathname);
+ for (i = 0; i < expected_count; ++i) {
+ if (expected[i] != NULL) {
+ logprintf(" Expected but not present: %s\n", expected[i]);
+ free(expected[i]);
+ }
+ }
+ for (j = 0; j < actual_count; ++j) {
+ if (actual[j] != NULL)
+ logprintf(" Present but not expected: %s\n", actual[j]);
+ }
+ failure_finish(NULL);
+ free(buff);
+ free(expected);
+ free(actual);
+ return (0);
+}
+
/* Test that two paths point to the same file. */
/* As a side-effect, asserts that both files exist. */
static int
@@ -1644,7 +1719,7 @@ struct { void (*func)(void); const char *name; int failures; } tests[] = {
* Summarize repeated failures in the just-completed test.
*/
static void
-test_summarize(const char *filename, int failed)
+test_summarize(int failed)
{
unsigned int i;
@@ -1663,9 +1738,10 @@ test_summarize(const char *filename, int failed)
for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) {
if (failed_lines[i].count > 1 && !failed_lines[i].skip)
logprintf("%s:%d: Summary: Failed %d times\n",
- filename, i, failed_lines[i].count);
+ failed_filename, i, failed_lines[i].count);
}
/* Clear the failure history for the next file. */
+ failed_filename = NULL;
memset(failed_lines, 0, sizeof(failed_lines));
}
@@ -1675,6 +1751,7 @@ test_summarize(const char *filename, int failed)
static int
test_run(int i, const char *tmpdir)
{
+ char workdir[1024];
char logfilename[64];
int failures_before = failures;
int oldumask;
@@ -1701,11 +1778,12 @@ test_run(int i, const char *tmpdir)
logfile = fopen(logfilename, "w");
fprintf(logfile, "%s\n\n", tests[i].name);
/* Chdir() to a work dir for this specific test. */
- if (!assertMakeDir(tests[i].name, 0755)
- || !assertChdir(tests[i].name)) {
+ snprintf(workdir, sizeof(workdir), "%s/%s", tmpdir, tests[i].name);
+ testworkdir = workdir;
+ if (!assertMakeDir(testworkdir, 0755)
+ || !assertChdir(testworkdir)) {
fprintf(stderr,
- "ERROR: Can't chdir to work dir %s/%s\n",
- tmpdir, tests[i].name);
+ "ERROR: Can't chdir to work dir %s\n", testworkdir);
exit(1);
}
/* Explicitly reset the locale before each test. */
@@ -1719,6 +1797,7 @@ test_run(int i, const char *tmpdir)
/*
* Clean up and report afterwards.
*/
+ testworkdir = NULL;
/* Restore umask */
umask(oldumask);
/* Reset locale. */
@@ -1731,7 +1810,7 @@ test_run(int i, const char *tmpdir)
}
/* Report per-test summaries. */
tests[i].failures = failures - failures_before;
- test_summarize(test_filename, tests[i].failures);
+ test_summarize(tests[i].failures);
/* Close the per-test log file. */
fclose(logfile);
logfile = NULL;
@@ -1876,7 +1955,7 @@ int
main(int argc, char **argv)
{
static const int limit = sizeof(tests) / sizeof(tests[0]);
- int i, tests_run = 0, tests_failed = 0, option;
+ int i, start, end, tests_run = 0, tests_failed = 0, option;
time_t now;
char *refdir_alloc = NULL;
const char *progname;
@@ -1967,6 +2046,7 @@ main(int argc, char **argv)
#ifdef PROGRAM
testprogfile = option_arg;
#else
+ fprintf(stderr, "-p option not permitted\n");
usage(progname);
#endif
break;
@@ -1980,6 +2060,8 @@ main(int argc, char **argv)
verbosity++;
break;
default:
+ fprintf(stderr, "Unrecognized option '%c'\n",
+ option);
usage(progname);
}
}
@@ -1989,8 +2071,11 @@ main(int argc, char **argv)
* Sanity-check that our options make sense.
*/
#ifdef PROGRAM
- if (testprogfile == NULL)
+ if (testprogfile == NULL) {
+ fprintf(stderr, "Program executable required\n");
usage(progname);
+ }
+
{
char *testprg;
#if defined(_WIN32) && !defined(__CYGWIN__)
@@ -2073,19 +2158,46 @@ main(int argc, char **argv)
} else {
while (*(argv) != NULL) {
if (**argv >= '0' && **argv <= '9') {
- i = atoi(*argv);
- if (i < 0 || i >= limit) {
+ char *p = *argv;
+ start = 0;
+ while (*p >= '0' && *p <= '9') {
+ start *= 10;
+ start += *p - '0';
+ ++p;
+ }
+ if (*p == '\0') {
+ end = start;
+ } else if (*p == '-') {
+ ++p;
+ if (*p == '\0') {
+ end = limit - 1;
+ } else {
+ end = 0;
+ while (*p >= '0' && *p <= '9') {
+ end *= 10;
+ end += *p - '0';
+ ++p;
+ }
+ }
+ } else {
printf("*** INVALID Test %s\n", *argv);
free(refdir_alloc);
usage(progname);
- /* usage() never returns */
+ return (1);
+ }
+ if (start < 0 || end >= limit || start > end) {
+ printf("*** INVALID Test %s\n", *argv);
+ free(refdir_alloc);
+ usage(progname);
+ return (1);
}
} else {
- for (i = 0; i < limit; ++i) {
- if (strcmp(*argv, tests[i].name) == 0)
+ for (start = 0; start < limit; ++start) {
+ if (strcmp(*argv, tests[start].name) == 0)
break;
}
- if (i >= limit) {
+ end = start;
+ if (start >= limit) {
printf("*** INVALID Test ``%s''\n",
*argv);
free(refdir_alloc);
@@ -2093,9 +2205,12 @@ main(int argc, char **argv)
/* usage() never returns */
}
}
- if (test_run(i, tmpdir))
- tests_failed++;
- tests_run++;
+ while (start <= end) {
+ if (test_run(start, tmpdir))
+ tests_failed++;
+ tests_run++;
+ ++start;
+ }
argv++;
}
}
diff --git a/cpio/test/test.h b/cpio/test/test.h
index 2d68f310..a552c8f5 100644
--- a/cpio/test/test.h
+++ b/cpio/test/test.h
@@ -48,9 +48,6 @@
#include <sys/types.h> /* Windows requires this before sys/stat.h */
#include <sys/stat.h>
-#ifdef USE_DMALLOC
-#include <dmalloc.h>
-#endif
#if HAVE_DIRENT_H
#include <dirent.h>
#endif
@@ -63,6 +60,9 @@
#ifdef HAVE_IO_H
#include <io.h>
#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -97,6 +97,10 @@
#define snprintf sprintf_s
#endif
+#if defined(__BORLANDC__)
+#pragma warn -8068 /* Constant out of range in comparison. */
+#endif
+
/* Cygwin */
#if defined(__CYGWIN__)
/* Cygwin-1.7.x is lazy about populating nlinks, so don't
@@ -104,6 +108,7 @@
# define NLINKS_INACCURATE_FOR_DIRS
#endif
+/* Haiku OS and QNX */
#if defined(__HAIKU__) || defined(__QNXNTO__)
/* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */
#include <stdint.h>
@@ -146,17 +151,15 @@
/* As above, but raw blocks of bytes. */
#define assertEqualMem(v1, v2, l) \
assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL)
-/* Assert two files are the same; allow printf-style expansion of second name.
- * See below for comments about variable arguments here...
- */
-#define assertEqualFile \
- assertion_setup(__FILE__, __LINE__);assertion_equal_file
-/* Assert that a file is empty; supports printf-style arguments. */
-#define assertEmptyFile \
- assertion_setup(__FILE__, __LINE__);assertion_empty_file
-/* Assert that a file is not empty; supports printf-style arguments. */
-#define assertNonEmptyFile \
- assertion_setup(__FILE__, __LINE__);assertion_non_empty_file
+/* Assert two files are the same. */
+#define assertEqualFile(f1, f2) \
+ assertion_equal_file(__FILE__, __LINE__, (f1), (f2))
+/* Assert that a file is empty. */
+#define assertEmptyFile(pathname) \
+ assertion_empty_file(__FILE__, __LINE__, (pathname))
+/* Assert that a file is not empty. */
+#define assertNonEmptyFile(pathname) \
+ assertion_non_empty_file(__FILE__, __LINE__, (pathname))
#define assertFileAtime(pathname, sec, nsec) \
assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec)
#define assertFileAtimeRecent(pathname) \
@@ -166,14 +169,14 @@
#define assertFileBirthtimeRecent(pathname) \
assertion_file_birthtime_recent(__FILE__, __LINE__, pathname)
/* Assert that a file exists; supports printf-style arguments. */
-#define assertFileExists \
- assertion_setup(__FILE__, __LINE__);assertion_file_exists
-/* Assert that a file exists; supports printf-style arguments. */
-#define assertFileNotExists \
- assertion_setup(__FILE__, __LINE__);assertion_file_not_exists
-/* Assert that file contents match a string; supports printf-style arguments. */
-#define assertFileContents \
- assertion_setup(__FILE__, __LINE__);assertion_file_contents
+#define assertFileExists(pathname) \
+ assertion_file_exists(__FILE__, __LINE__, pathname)
+/* Assert that a file exists. */
+#define assertFileNotExists(pathname) \
+ assertion_file_not_exists(__FILE__, __LINE__, pathname)
+/* Assert that file contents match a string. */
+#define assertFileContents(data, data_size, pathname) \
+ assertion_file_contents(__FILE__, __LINE__, data, data_size, pathname)
#define assertFileMtime(pathname, sec, nsec) \
assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec)
#define assertFileMtimeRecent(pathname) \
@@ -182,8 +185,10 @@
assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks)
#define assertFileSize(pathname, size) \
assertion_file_size(__FILE__, __LINE__, pathname, size)
-#define assertTextFileContents \
- assertion_setup(__FILE__, __LINE__);assertion_text_file_contents
+#define assertTextFileContents(text, pathname) \
+ assertion_text_file_contents(__FILE__, __LINE__, text, pathname)
+#define assertFileContainsLinesAnyOrder(pathname, lines) \
+ assertion_file_contains_lines_any_order(__FILE__, __LINE__, pathname, lines)
#define assertIsDir(pathname, mode) \
assertion_is_dir(__FILE__, __LINE__, pathname, mode)
#define assertIsHardlink(path1, path2) \
@@ -213,14 +218,14 @@
* but effective.
*/
#define skipping \
- assertion_setup(__FILE__, __LINE__);test_skipping
+ skipping_setup(__FILE__, __LINE__);test_skipping
/* Function declarations. These are defined in test_utility.c. */
void failure(const char *fmt, ...);
int assertion_assert(const char *, int, int, const char *, void *);
int assertion_chdir(const char *, int, const char *);
-int assertion_empty_file(const char *, ...);
-int assertion_equal_file(const char *, const char *, ...);
+int assertion_empty_file(const char *, int, const char *);
+int assertion_equal_file(const char *, int, const char *, const char *);
int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *);
int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *);
int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *);
@@ -229,12 +234,13 @@ int assertion_file_atime(const char *, int, const char *, long, long);
int assertion_file_atime_recent(const char *, int, const char *);
int assertion_file_birthtime(const char *, int, const char *, long, long);
int assertion_file_birthtime_recent(const char *, int, const char *);
-int assertion_file_contents(const void *, int, const char *, ...);
-int assertion_file_exists(const char *, ...);
+int assertion_file_contains_lines_any_order(const char *, int, const char *, const char **);
+int assertion_file_contents(const char *, int, const void *, int, const char *);
+int assertion_file_exists(const char *, int, const char *);
int assertion_file_mtime(const char *, int, const char *, long, long);
int assertion_file_mtime_recent(const char *, int, const char *);
int assertion_file_nlinks(const char *, int, const char *, int);
-int assertion_file_not_exists(const char *, ...);
+int assertion_file_not_exists(const char *, int, const char *);
int assertion_file_size(const char *, int, const char *, long);
int assertion_is_dir(const char *, int, const char *, int);
int assertion_is_hardlink(const char *, int, const char *, const char *);
@@ -245,11 +251,11 @@ int assertion_make_dir(const char *, int, const char *, int);
int assertion_make_file(const char *, int, const char *, int, const char *);
int assertion_make_hardlink(const char *, int, const char *newpath, const char *);
int assertion_make_symlink(const char *, int, const char *newpath, const char *);
-int assertion_non_empty_file(const char *, ...);
-int assertion_text_file_contents(const char *buff, const char *f);
+int assertion_non_empty_file(const char *, int, const char *);
+int assertion_text_file_contents(const char *, int, const char *buff, const char *f);
int assertion_umask(const char *, int, int);
-void assertion_setup(const char *, int);
+void skipping_setup(const char *, int);
void test_skipping(const char *fmt, ...);
/* Like sprintf, then system() */
@@ -274,6 +280,9 @@ char *slurpfile(size_t *, const char *fmt, ...);
/* Extracts named reference file to the current directory. */
void extract_reference_file(const char *);
+/* Path to working directory for current test */
+const char *testworkdir;
+
/*
* Special interfaces for program test harness.
*/
@@ -283,3 +292,7 @@ const char *testprogfile;
/* Name of exe to use in printf-formatted command strings. */
/* On Windows, this includes leading/trailing quotes. */
const char *testprog;
+
+#ifdef USE_DMALLOC
+#include <dmalloc.h>
+#endif