From 152e214a9a66ee274f3d26344a30672970dd3c32 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sat, 21 Jun 2008 02:17:18 +0000 Subject: [PATCH] MfP4: test improvements, mostly for portability. --- usr.bin/cpio/test/main.c | 51 +++++++++++++++++++++++++++++++++++++--- 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 c88dd2ac341..133f4a98939 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 #include #include #include -#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 06e6d903fc8..39a98376f33 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 @@ -51,20 +61,6 @@ #include #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 /* 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; - -- 2.45.0