]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
testsuite: allow 'dev' in version 871/head
authorPavel Raiskup <praiskup@redhat.com>
Mon, 20 Feb 2017 19:25:24 +0000 (20:25 +0100)
committerPavel Raiskup <praiskup@redhat.com>
Tue, 21 Feb 2017 05:16:13 +0000 (06:16 +0100)
12 files changed:
CMakeLists.txt
Makefile.am
cat/test/CMakeLists.txt
cat/test/test_version.c
cpio/test/CMakeLists.txt
cpio/test/test_option_version.c
libarchive/test/CMakeLists.txt
libarchive/test/test_archive_api_feature.c
tar/test/CMakeLists.txt
tar/test/test_version.c
test_utils/lib/version.c [new file with mode: 0644]
test_utils/lib/version.h [new file with mode: 0644]

index eb36b5b99e44e521b7515f336276b7bcfd6372bf..9a1132cc72871884f407e7e122036f055a4bfb52 100644 (file)
@@ -44,13 +44,13 @@ SET(CMAKE_MACOSX_RPATH ON)
 #
 FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/build/version _version)
 STRING(REGEX REPLACE
- "^([0-9])[0-9][0-9][0-9][0-9][0-9][0-9][a-z]?$" "\\1" _major ${_version})
+ "^([0-9])[0-9][0-9][0-9][0-9][0-9][0-9][a-z]*$" "\\1" _major ${_version})
 STRING(REGEX REPLACE
- "^[0-9]([0-9][0-9][0-9])[0-9][0-9][0-9][a-z]?$" "\\1" _minor ${_version})
+ "^[0-9]([0-9][0-9][0-9])[0-9][0-9][0-9][a-z]*$" "\\1" _minor ${_version})
 STRING(REGEX REPLACE
- "^[0-9][0-9][0-9][0-9]([0-9][0-9][0-9])[a-z]?$" "\\1" _revision ${_version})
+ "^[0-9][0-9][0-9][0-9]([0-9][0-9][0-9])[a-z]*$" "\\1" _revision ${_version})
 STRING(REGEX REPLACE
- "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]([a-z]?)$" "\\1" _quality ${_version})
+ "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]([a-z]*)$" "\\1" _quality ${_version})
 SET(_version_number ${_major}${_minor}${_revision})
 STRING(REGEX REPLACE "[0]*([^0]*[0-9])$" "\\1" _trimmed_minor ${_minor})
 STRING(REGEX REPLACE "[0]*([^0]*[0-9])$" "\\1" _trimmed_revision ${_revision})
index dd1fc813e56479b7189e11573d702235b29ca4e1..56a19abf578a4c7042525abc93b925d30d1fd613 100644 (file)
@@ -310,7 +310,9 @@ pkgconfig_DATA = build/pkgconfig/libarchive.pc
 # Sources needed by all test programs
 test_utils_SOURCES= \
        test_utils/test_utils.c \
-       test_utils/test_utils.h
+       test_utils/test_utils.h \
+       test_utils/lib/version.h \
+       test_utils/lib/version.c
 
 #
 #
index c4642aea479460ff539303a3a160f644e83de499..9dbf4b7942013865a13993fe4df334ec7fa0e51f 100644 (file)
@@ -6,6 +6,7 @@
 IF(ENABLE_CAT AND ENABLE_TEST)
   SET(bsdcat_test_SOURCES
     ../../test_utils/test_utils.c
+    ../../test_utils/lib/version.c
     main.c
     test.h
     test_0.c
index e587b3440c6d622871ca47be0e868ada54711178..f582a13feb88420c0b3e9824b4a66cb955eeb9ae 100644 (file)
  * Test that --version option works and generates reasonable output.
  */
 
+#include "lib/version.h"
+
 DEFINE_TEST(test_version)
 {
-       int r;
-       char *p, *q;
-       size_t s;
-
-
-       r = systemf("%s --version >version.stdout 2>version.stderr", testprog);
-       failure("Unable to run %s --version", testprog);
-       if (!assert(r == 0))
-               return;
-
-       /* --version should generate nothing to stdout. */
-       assertEmptyFile("version.stderr");
-       /* Verify format of version message. */
-       q = p = slurpfile(&s, "version.stdout");
-       /* Version message should start with name of program, then space. */
-       assert(s > 6);
-       failure("Version must start with 'bsdcat': ``%s''", p);
-       if (!assertEqualMem(q, "bsdcat ", 7))
-               return;
-       q += 7; s -= 7;
-       /* Version number is a series of digits and periods. */
-       while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
-               ++q;
-               --s;
-       }
-       /* Version number terminated by space. */
-       failure("No space after bsdcat version: ``%s''", p);
-       assert(s > 1);
-       /* Skip a single trailing a,b,c, or d. */
-       if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
-               ++q;
-       failure("No space after bsdcat version: ``%s''", p);
-       assert(*q == ' ');
-       ++q; --s;
-       /* Separator. */
-       failure("No `-' between bsdcat and libarchive versions: ``%s''", p);
-       assertEqualMem(q, "- ", 2);
-       q += 2; s -= 2;
-       /* libarchive name and version number */
-       failure("Not long enough for libarchive version: ``%s''", p);
-       assert(s > 11);
-       failure("Libarchive version must start with `libarchive': ``%s''", p);
-       assertEqualMem(q, "libarchive ", 11);
-       q += 11; s -= 11;
-       /* Version number is a series of digits and periods. */
-       while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
-               ++q;
-               --s;
-       }
-       /* Skip a single trailing a,b,c, or d. */
-       if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
-               ++q;
-       /* Skip arbitrary third-party version numbers. */
-       while (s > 0 && (*q == ' ' || *q == '-' || *q == '/' || *q == '.' || isalnum(*q))) {
-               ++q;
-               --s;
-       }
-       /* All terminated by end-of-line. */
-       assert(s >= 1);
-       /* Skip an optional CR character (e.g., Windows) */
-       failure("Version output must end with \\n or \\r\\n");
-       if (*q == '\r') { ++q; --s; }
-       assertEqualMem(q, "\n", 1);
-       free(p);
+       assertVersion(testprog, "bsdcat");
 }
index 8ffb54276967424f2badb4cf38e7d6e948758352..c99ef65a09572b0affb7ea4c4f3f6084ed39363a 100644 (file)
@@ -8,6 +8,7 @@ IF(ENABLE_CPIO AND ENABLE_TEST)
     ../cmdline.c
     ../../libarchive_fe/err.c
     ../../test_utils/test_utils.c
+    ../../test_utils/lib/version.c
     main.c
     test.h
     test_0.c
index ac58cefda11f60c6c02f4cdf097db607ecb909c0..78ac21807434af792bac5284a59b3f74e3c5e958 100644 (file)
 #include "test.h"
 __FBSDID("$FreeBSD$");
 
-/*
- * Test that --version option works and generates reasonable output.
- */
-
-static void
-verify(const char *p, size_t s)
-{
-       const char *q = p;
-
-       /* Version message should start with name of program, then space. */
-       failure("version message too short:", p);
-       if (!assert(s > 6))
-               return;
-       failure("Version message should begin with 'bsdcpio': %s", p);
-       if (!assertEqualMem(q, "bsdcpio ", 8))
-               /* If we're not testing bsdcpio, don't keep going. */
-               return;
-       q += 8; s -= 8;
-       /* Version number is a series of digits and periods. */
-       while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
-               ++q;
-               --s;
-       }
-       /* Version number terminated by space. */
-       failure("Version: %s", p);
-       assert(s > 1);
-       /* Skip a single trailing a,b,c, or d. */
-       if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
-               ++q;
-       failure("Version: %s", p);
-       assert(*q == ' ');
-       ++q; --s;
-       /* Separator. */
-       failure("Version: %s", p);
-       assertEqualMem(q, "- ", 2);
-       q += 2; s -= 2;
-       /* libarchive name and version number */
-       assert(s > 11);
-       failure("Version: %s", p);
-       assertEqualMem(q, "libarchive ", 11);
-       q += 11; s -= 11;
-       /* Version number is a series of digits and periods. */
-       while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
-               ++q;
-               --s;
-       }
-       /* Skip a single trailing a,b,c, or d. */
-       if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
-               ++q;
-       /* Skip arbitrary third-party version numbers. */
-       while (s > 0 && (*q == ' ' || *q == '-' || *q == '/' || *q == '.' || isalnum(*q))) {
-               ++q;
-               --s;
-       }
-       /* All terminated by end-of-line: \r, \r\n, or \n */
-       assert(s >= 1);
-       failure("Version: %s", p);
-       if (*q == '\x0d') {
-               if (q[1] != '\0')
-                       assertEqualMem(q, "\x0d\x0a", 2);
-       } else
-               assertEqualMem(q, "\x0a", 1);
-}
-
+#include "lib/version.h"
 
 DEFINE_TEST(test_option_version)
 {
-       int r;
-       char *p;
-       size_t s;
-
-       r = systemf("%s --version >version.stdout 2>version.stderr", testprog);
-       if (r != 0)
-               r = systemf("%s -W version >version.stdout 2>version.stderr",
-                   testprog);
-       failure("Unable to run either %s --version or %s -W version",
-           testprog, testprog);
-       if (!assert(r == 0))
-               return;
-
-       /* --version should generate nothing to stderr. */
-       assertEmptyFile("version.stderr");
-       /* Verify format of version message. */
-       p = slurpfile(&s, "version.stdout");
-       verify(p, s);
-       free(p);
+       assertVersion(testprog, "bsdcpio");
 }
index 6c4ac23baa24456f4177587638b4e6595cb54158..694d8829168a40befc2eba4eb80f1288d948d6b5 100644 (file)
@@ -6,6 +6,7 @@
 IF(ENABLE_TEST)
   SET(libarchive_test_SOURCES
     ../../test_utils/test_utils.c
+    ../../test_utils/lib/version.c
     main.c
     read_open_memory.c
     test.h
index d551e6a01ebcad83281b0f1688c7041f0feb2769..60773ad04e547832cd69ea2410e501fd8fc46db8 100644 (file)
@@ -42,8 +42,12 @@ DEFINE_TEST(test_archive_api_feature)
        if (strlen(buff) < strlen(archive_version_string())) {
                p = archive_version_string() + strlen(buff);
                failure("Version string is: %s", archive_version_string());
-               assert(*p == 'a' || *p == 'b' || *p == 'c' || *p == 'd');
-               ++p;
+               if (p[0] == 'd'&& p[1] == 'e' && p[2] == 'v')
+                       p += 3;
+               else {
+                       assert(*p == 'a' || *p == 'b' || *p == 'c' || *p == 'd');
+                       ++p;
+               }
                failure("Version string is: %s", archive_version_string());
                assert(*p == '\0');
        }
index 0d2da365087de3a977739dae7dc263b9e3abb67b..6f6fc215ac9f10872d0367bc9d49d0ba129928ee 100644 (file)
@@ -6,6 +6,7 @@
 IF(ENABLE_TAR AND ENABLE_TEST)
   SET(bsdtar_test_SOURCES
     ../../test_utils/test_utils.c
+    ../../test_utils/lib/version.c
     main.c
     test.h
     test_0.c
index 0c904d705c22921757221195def93c8e9ccd9734..d3d9a03822e46174ac85c2da81f2b8d45937998b 100644 (file)
@@ -29,75 +29,9 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_version.c,v 1.2 2008/05/26 17:10:1
  * Test that --version option works and generates reasonable output.
  */
 
+#include "lib/version.h"
+
 DEFINE_TEST(test_version)
 {
-       int r;
-       char *p, *q;
-       size_t s;
-
-
-       r = systemf("%s --version >version.stdout 2>version.stderr", testprog);
-       if (r != 0)
-               r = systemf("%s -W version >version.stdout 2>version.stderr",
-                   testprog);
-       failure("Unable to run either %s --version or %s -W version",
-           testprog, testprog);
-       if (!assert(r == 0))
-               return;
-
-       /* --version should generate nothing to stdout. */
-       assertEmptyFile("version.stderr");
-       /* Verify format of version message. */
-       q = p = slurpfile(&s, "version.stdout");
-       /* Version message should start with name of program, then space. */
-       assert(s > 6);
-       failure("Version must start with 'bsdtar': ``%s''", p);
-       if (!assertEqualMem(q, "bsdtar ", 7))
-               goto done;
-       q += 7; s -= 7;
-       /* Version number is a series of digits and periods. */
-       while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
-               ++q;
-               --s;
-       }
-       /* Version number terminated by space. */
-       failure("No space after bsdtar version: ``%s''", p);
-       assert(s > 1);
-       /* Skip a single trailing a,b,c, or d. */
-       if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
-               ++q;
-       failure("No space after bsdtar version: ``%s''", p);
-       assert(*q == ' ');
-       ++q; --s;
-       /* Separator. */
-       failure("No `-' between bsdtar and libarchive versions: ``%s''", p);
-       assertEqualMem(q, "- ", 2);
-       q += 2; s -= 2;
-       /* libarchive name and version number */
-       failure("Not long enough for libarchive version: ``%s''", p);
-       assert(s > 11);
-       failure("Libarchive version must start with `libarchive': ``%s''", p);
-       assertEqualMem(q, "libarchive ", 11);
-       q += 11; s -= 11;
-       /* Version number is a series of digits and periods. */
-       while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
-               ++q;
-               --s;
-       }
-       /* Skip a single trailing a,b,c, or d. */
-       if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
-               ++q;
-       /* Skip arbitrary third-party version numbers. */
-       while (s > 0 && (*q == ' ' || *q == '-' || *q == '/' || *q == '.' || isalnum(*q))) {
-               ++q;
-               --s;
-       }
-       /* All terminated by end-of-line. */
-       assert(s >= 1);
-       /* Skip an optional CR character (e.g., Windows) */
-       failure("Version output must end with \\n or \\r\\n");
-       if (*q == '\r') { ++q; --s; }
-       assertEqualMem(q, "\n", 1);
-done:
-       free(p);
+       assertVersion(testprog, "bsdtar");
 }
diff --git a/test_utils/lib/version.c b/test_utils/lib/version.c
new file mode 100644 (file)
index 0000000..8075678
--- /dev/null
@@ -0,0 +1,132 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test/test.h"
+#include "lib/version.h"
+
+static void assert_version_id(char **qq, size_t *ss)
+{
+       char *q = *qq;
+       size_t s = *ss;
+
+       /* Version number is a series of digits and periods. */
+       while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
+               ++q;
+               --s;
+       }
+
+       if (q[0] == 'd' && q[1] == 'e' && q[2] == 'v') {
+               q += 3;
+               s -= 3;
+       }
+       
+       /* Skip a single trailing a,b,c, or d. */
+       if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
+               ++q;
+
+       /* Version number terminated by space. */
+       failure("No space after version: ``%s''", q);
+       assert(s > 1);
+       failure("No space after version: ``%s''", q);
+       assert(*q == ' ');
+
+       ++q; --s;
+
+       *qq = q;
+       *ss = s;
+}
+
+void assertVersion(const char *prog, const char *base)
+{
+       int r;
+       char *p, *q;
+       size_t s;
+       unsigned int prog_len = strlen(base);
+
+       r = systemf("%s --version >version.stdout 2>version.stderr", prog);
+       if (r != 0)
+               r = systemf("%s -W version >version.stdout 2>version.stderr",
+                   prog);
+
+       failure("Unable to run either %s --version or %s -W version",
+               prog, prog);
+       if (!assert(r == 0))
+               return;
+
+       /* --version should generate nothing to stdout. */
+       assertEmptyFile("version.stderr");
+
+       /* Verify format of version message. */
+       q = p = slurpfile(&s, "version.stdout");
+
+       /* Version message should start with name of program, then space. */
+       assert(s > prog_len + 1);
+       
+       failure("Version must start with '%s': ``%s''", base, p);
+       if (!assertEqualMem(q, base, prog_len))
+               goto done;
+
+       q += prog_len; s -= prog_len;
+
+       assert(*q == ' ');
+       q++; s--;
+
+       assert_version_id(&q, &s);
+
+       /* Separator. */
+       failure("No `-' between program name and versions: ``%s''", p);
+       assertEqualMem(q, "- ", 2);
+       q += 2; s -= 2;
+
+       failure("Not long enough for libarchive version: ``%s''", p);
+       assert(s > 11);
+
+       failure("Libarchive version must start with `libarchive': ``%s''", p);
+       assertEqualMem(q, "libarchive ", 11);
+
+       q += 11; s -= 11;
+
+       assert_version_id(&q, &s);
+
+
+       /* Skip arbitrary third-party version numbers. */
+       while (s > 0 && (*q == ' ' || *q == '-' || *q == '/' || *q == '.' || isalnum(*q))) {
+               ++q;
+               --s;
+       }
+
+       /* All terminated by end-of-line. */
+       assert(s >= 1);
+
+       /* Skip an optional CR character (e.g., Windows) */
+       failure("Version output must end with \\n or \\r\\n");
+
+       if (*q == '\r') { ++q; --s; }
+       assertEqualMem(q, "\n", 1);
+
+done:
+       free(p);
+
+}
diff --git a/test_utils/lib/version.h b/test_utils/lib/version.h
new file mode 100644 (file)
index 0000000..3a7ae33
--- /dev/null
@@ -0,0 +1,31 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _TESTS_LIB_VERSION_H
+#define _TESTS_LIB_VERSION_H
+
+void assertVersion(const char *prog, const char *base);
+
+#endif