From owner-svn-src-head@FreeBSD.ORG Sun Mar 8 05:38:46 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 208B8106564A; Sun, 8 Mar 2009 05:38:46 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 03F398FC08; Sun, 8 Mar 2009 05:38:46 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n285cjPq073515; Sun, 8 Mar 2009 05:38:45 GMT (envelope-from kientzle@svn.freebsd.org) Received: (from kientzle@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n285cjM8073513; Sun, 8 Mar 2009 05:38:45 GMT (envelope-from kientzle@svn.freebsd.org) Message-Id: <200903080538.n285cjM8073513@svn.freebsd.org> From: Tim Kientzle Date: Sun, 8 Mar 2009 05:38:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189519 - head/usr.bin/tar/test X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Mar 2009 05:38:46 -0000 Author: kientzle Date: Sun Mar 8 05:38:45 2009 New Revision: 189519 URL: http://svn.freebsd.org/changeset/base/189519 Log: Merge r368,496,625,626 from libarchive.googlecode.com: A number of style and portability tweaks to the test harness. Most significantly, don't use getopt(). Modified: head/usr.bin/tar/test/main.c head/usr.bin/tar/test/test.h Modified: head/usr.bin/tar/test/main.c ============================================================================== --- head/usr.bin/tar/test/main.c Sun Mar 8 05:35:59 2009 (r189518) +++ head/usr.bin/tar/test/main.c Sun Mar 8 05:38:45 2009 (r189519) @@ -56,7 +56,11 @@ __FBSDID("$FreeBSD$"); */ #undef DEFINE_TEST #define DEFINE_TEST(name) void name(void); +#ifdef LIST_H +#include LIST_H +#else #include "list.h" +#endif /* Interix doesn't define these in a standard header. */ #if __INTERIX__ @@ -80,7 +84,7 @@ static int skips = 0; static int assertions = 0; /* Directory where uuencoded reference files can be found. */ -static char *refdir; +static const char *refdir; /* * My own implementation of the standard assert() macro emits the @@ -476,7 +480,9 @@ test_assert_empty_file(const char *f1fmt va_end(ap); if (stat(f1, &st) != 0) { - fprintf(stderr, "%s:%d: Could not stat: %s\n", test_filename, test_line, f1); + fprintf(stderr, "%s:%d: Could not stat: %s\n", + test_filename, test_line, f1); + failures ++; report_failure(NULL); return (0); } @@ -519,6 +525,7 @@ test_assert_non_empty_file(const char *f fprintf(stderr, "%s:%d: Could not stat: %s\n", test_filename, test_line, f1); report_failure(NULL); + failures++; return (0); } if (st.st_size != 0) @@ -630,6 +637,15 @@ test_assert_file_contents(const void *bu va_end(ap); fd = open(f, O_RDONLY); + if (fd < 0) { + failures ++; + if (!previous_failures(test_filename, test_line)) { + fprintf(stderr, "%s:%d: File doesn't exist: %s\n", + test_filename, test_line, f); + report_failure(test_extra); + } + return (0); + } contents = malloc(s * 2); n = read(fd, contents, s * 2); if (n == s && memcmp(buff, contents, s) == 0) { @@ -731,7 +747,11 @@ slurpfile(size_t * sizep, const char *fm #undef DEFINE_TEST #define DEFINE_TEST(n) { n, #n }, struct { void (*func)(void); const char *name; } tests[] = { +#ifdef LIST_H + #include LIST_H +#else #include "list.h" +#endif }; /* @@ -881,10 +901,12 @@ int main(int argc, char **argv) int i, tests_run = 0, tests_failed = 0, opt; time_t now; char *refdir_alloc = NULL; - char *progname, *p; + const char *opt_arg, *progname, *p; char tmpdir[256]; char tmpdir_timestamp[256]; + (void)argc; /* UNUSED */ + /* * Name of this program, used to build root of our temp directory * tree. @@ -909,39 +931,62 @@ int main(int argc, char **argv) refdir = getenv(ENVBASE "_TEST_FILES"); /* - * Parse options. + * Parse options, without using getopt(), which isn't available + * on all platforms. */ - while ((opt = getopt(argc, argv, "dkp:qr:v")) != -1) { - switch (opt) { - case 'd': - dump_on_failure = 1; + ++argv; /* Skip program name */ + while (*argv != NULL) { + if (**argv != '-') break; - case 'k': - keep_temp_files = 1; - break; - case 'p': + p = *argv++; + ++p; /* Skip '-' */ + while (*p != '\0') { + opt = *p++; + opt_arg = NULL; + /* If 'opt' takes an argument, parse that. */ + if (opt == 'p' || opt == 'r') { + if (*p != '\0') + opt_arg = p; + else if (*argv == NULL) { + fprintf(stderr, + "Option -%c requires argument.\n", + opt); + usage(progname); + } else + opt_arg = *argv++; + p = ""; /* End of this option word. */ + } + + /* Now, handle the option. */ + switch (opt) { + case 'd': + dump_on_failure = 1; + break; + case 'k': + keep_temp_files = 1; + break; + case 'p': #ifdef PROGRAM - testprog = optarg; + testprog = opt_arg; #else - usage(progname); + usage(progname); #endif - break; - case 'q': - quiet_flag++; - break; - case 'r': - refdir = optarg; - break; - case 'v': - verbose = 1; - break; - case '?': - default: - usage(progname); + break; + case 'q': + quiet_flag++; + break; + case 'r': + refdir = opt_arg; + break; + case 'v': + verbose = 1; + break; + case '?': + default: + usage(progname); + } } } - argc -= optind; - argv += optind; /* * Sanity-check that our options make sense. @@ -976,12 +1021,14 @@ int main(int argc, char **argv) * reference files, use the current directory for that. */ if (refdir == NULL) { + char *q; systemf("/bin/pwd > %s/refdir", tmpdir); - refdir = refdir_alloc = slurpfile(NULL, "%s/refdir", tmpdir); - p = refdir + strlen(refdir); - while (p[-1] == '\n') { - --p; - *p = '\0'; + q = slurpfile(NULL, "%s/refdir", tmpdir); + refdir = refdir_alloc = q; + q += strlen(refdir); + while (q[-1] == '\n') { + --q; + *q = '\0'; } systemf("rm %s/refdir", tmpdir); } @@ -1003,7 +1050,7 @@ int main(int argc, char **argv) /* * Run some or all of the individual tests. */ - if (argc == 0) { + if (*argv == NULL) { /* Default: Run all tests. */ for (i = 0; i < limit; i++) { if (test_run(i, tmpdir)) Modified: head/usr.bin/tar/test/test.h ============================================================================== --- head/usr.bin/tar/test/test.h Sun Mar 8 05:35:59 2009 (r189518) +++ head/usr.bin/tar/test/test.h Sun Mar 8 05:38:45 2009 (r189519) @@ -151,4 +151,4 @@ void extract_reference_file(const char * */ /* Pathname of exe to be tested. */ -char *testprog; +const char *testprog;