diff options
author | kientzle <kientzle@FreeBSD.org> | 2008-06-21 02:17:18 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2008-06-21 02:17:18 +0000 |
commit | 76e2d7055fdde2885c8fad05dca34ec5a5d8cc53 (patch) | |
tree | 2c8b57a5c740d5fd4f3698dad57ad441123a84e7 /usr.bin/cpio | |
parent | 10c5185886b2055f7d8229832c2636b2254e9957 (diff) | |
download | FreeBSD-src-76e2d7055fdde2885c8fad05dca34ec5a5d8cc53.zip FreeBSD-src-76e2d7055fdde2885c8fad05dca34ec5a5d8cc53.tar.gz |
MfP4: test improvements, mostly for portability.
Diffstat (limited to 'usr.bin/cpio')
-rw-r--r-- | usr.bin/cpio/test/main.c | 51 | ||||
-rw-r--r-- | usr.bin/cpio/test/test.h | 37 |
2 files changed, 68 insertions, 20 deletions
diff --git a/usr.bin/cpio/test/main.c b/usr.bin/cpio/test/main.c index c88dd2a..133f4a9 100644 --- a/usr.bin/cpio/test/main.c +++ b/usr.bin/cpio/test/main.c @@ -27,13 +27,13 @@ * Various utility routines useful for test programs. * Each test program is linked against this file. */ +#include "test.h" + #include <errno.h> #include <locale.h> #include <stdarg.h> #include <time.h> -#include "test.h" - /* * This same file is used pretty much verbatim for all test harnesses. * @@ -541,6 +541,48 @@ test_assert_equal_file(const char *f1, const char *f2pattern, ...) return (0); } +int +test_assert_file_exists(const char *fpattern, ...) +{ + char f[1024]; + va_list ap; + + va_start(ap, fpattern); + vsprintf(f, fpattern, ap); + va_end(ap); + + if (!access(f, F_OK)) + return (1); + if (!previous_failures(test_filename, test_line)) { + fprintf(stderr, "%s:%d: File doesn't exist\n", + test_filename, test_line); + fprintf(stderr, " file=\"%s\"\n", f); + report_failure(test_extra); + } + return (0); +} + +int +test_assert_file_not_exists(const char *fpattern, ...) +{ + char f[1024]; + va_list ap; + + va_start(ap, fpattern); + vsprintf(f, fpattern, ap); + va_end(ap); + + if (access(f, F_OK)) + return (1); + if (!previous_failures(test_filename, test_line)) { + fprintf(stderr, "%s:%d: File exists and shouldn't\n", + test_filename, test_line); + fprintf(stderr, " file=\"%s\"\n", f); + report_failure(test_extra); + } + return (0); +} + /* assertFileContents() asserts the contents of a file. */ int test_assert_file_contents(const void *buff, int s, const char *fpattern, ...) @@ -670,8 +712,11 @@ static int test_run(int i, const char *tmpdir) { int failures_before = failures; - if (!quiet_flag) + if (!quiet_flag) { printf("%d: %s\n", i, tests[i].name); + fflush(stdout); + } + /* * Always explicitly chdir() in case the last test moved us to * a strange place. diff --git a/usr.bin/cpio/test/test.h b/usr.bin/cpio/test/test.h index 06e6d90..39a9837 100644 --- a/usr.bin/cpio/test/test.h +++ b/usr.bin/cpio/test/test.h @@ -31,8 +31,18 @@ * 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 +#if defined(HAVE_CONFIG_H) +/* Most POSIX platforms use the 'configure' script to build config.h */ +#include "../../config.h" +#elif defined(__FreeBSD__) +/* Building as part of FreeBSD system requires a pre-built config.h. */ +#include "../config_freebsd.h" +#elif defined(_WIN32) +/* Win32 can't run the 'configure' script. */ +#include "../config_windows.h" +#else +/* Warn if the library hasn't been (automatically or manually) configured. */ +#error Oops: No config.h and no pre-built configuration in test.h. #endif #include <dirent.h> @@ -51,20 +61,6 @@ #include <dmalloc.h> #endif -#if defined(HAVE_CONFIG_H) -/* Most POSIX platforms use the 'configure' script to build config.h */ -#include "../../config.h" -#elif defined(__FreeBSD__) -/* Building as part of FreeBSD system requires a pre-built config.h. */ -#include "../config_freebsd.h" -#elif defined(_WIN32) -/* Win32 can't run the 'configure' script. */ -#include "../config_windows.h" -#else -/* Warn if the library hasn't been (automatically or manually) configured. */ -#error Oops: No config.h and no pre-built configuration in test.h. -#endif - /* No non-FreeBSD platform will have __FBSDID, so just define it here. */ #ifdef __FreeBSD__ #include <sys/cdefs.h> /* For __FBSDID */ @@ -102,6 +98,12 @@ /* Assert that a file is empty; supports printf-style arguments. */ #define assertEmptyFile \ test_setup(__FILE__, __LINE__);test_assert_empty_file +/* Assert that a file exists; supports printf-style arguments. */ +#define assertFileExists \ + test_setup(__FILE__, __LINE__);test_assert_file_exists +/* Assert that a file exists; supports printf-style arguments. */ +#define assertFileNotExists \ + test_setup(__FILE__, __LINE__);test_assert_file_not_exists /* Assert that file contents match a string; supports printf-style arguments. */ #define assertFileContents \ test_setup(__FILE__, __LINE__);test_assert_file_contents @@ -127,6 +129,8 @@ int test_assert_equal_string(const char *, int, const char *v1, const char *, co int test_assert_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); int test_assert_equal_mem(const char *, int, const char *, const char *, const char *, const char *, size_t, const char *, void *); int test_assert_file_contents(const void *, int, const char *, ...); +int test_assert_file_exists(const char *, ...); +int test_assert_file_not_exists(const char *, ...); /* Like sprintf, then system() */ int systemf(const char * fmt, ...); @@ -144,4 +148,3 @@ void extract_reference_file(const char *); /* Pathname of exe to be tested. */ char *testprog; - |