From 47ac1b5306292bf17e7c5f15a1655578378411d6 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Mon, 20 Feb 2017 20:25:24 +0100 Subject: [PATCH] testsuite: allow 'dev' in version --- CMakeLists.txt | 8 +- Makefile.am | 4 +- cat/test/CMakeLists.txt | 1 + cat/test/test_version.c | 67 +---------- cpio/test/CMakeLists.txt | 1 + cpio/test/test_option_version.c | 85 +------------ libarchive/test/CMakeLists.txt | 1 + libarchive/test/test_archive_api_feature.c | 8 +- tar/test/CMakeLists.txt | 1 + tar/test/test_version.c | 72 +---------- test_utils/lib/version.c | 132 +++++++++++++++++++++ test_utils/lib/version.h | 31 +++++ 12 files changed, 188 insertions(+), 223 deletions(-) create mode 100644 test_utils/lib/version.c create mode 100644 test_utils/lib/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index eb36b5b99..9a1132cc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/Makefile.am b/Makefile.am index dd1fc813e..56a19abf5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 # # diff --git a/cat/test/CMakeLists.txt b/cat/test/CMakeLists.txt index c4642aea4..9dbf4b794 100644 --- a/cat/test/CMakeLists.txt +++ b/cat/test/CMakeLists.txt @@ -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 diff --git a/cat/test/test_version.c b/cat/test/test_version.c index e587b3440..f582a13fe 100644 --- a/cat/test/test_version.c +++ b/cat/test/test_version.c @@ -28,70 +28,9 @@ * 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"); } diff --git a/cpio/test/CMakeLists.txt b/cpio/test/CMakeLists.txt index 8ffb54276..c99ef65a0 100644 --- a/cpio/test/CMakeLists.txt +++ b/cpio/test/CMakeLists.txt @@ -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 diff --git a/cpio/test/test_option_version.c b/cpio/test/test_option_version.c index ac58cefda..78ac21807 100644 --- a/cpio/test/test_option_version.c +++ b/cpio/test/test_option_version.c @@ -25,90 +25,9 @@ #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"); } diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index 6c4ac23ba..694d88291 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -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 diff --git a/libarchive/test/test_archive_api_feature.c b/libarchive/test/test_archive_api_feature.c index d551e6a01..60773ad04 100644 --- a/libarchive/test/test_archive_api_feature.c +++ b/libarchive/test/test_archive_api_feature.c @@ -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'); } diff --git a/tar/test/CMakeLists.txt b/tar/test/CMakeLists.txt index 0d2da3650..6f6fc215a 100644 --- a/tar/test/CMakeLists.txt +++ b/tar/test/CMakeLists.txt @@ -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 diff --git a/tar/test/test_version.c b/tar/test/test_version.c index 0c904d705..d3d9a0382 100644 --- a/tar/test/test_version.c +++ b/tar/test/test_version.c @@ -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 index 000000000..8075678c5 --- /dev/null +++ b/test_utils/lib/version.c @@ -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 index 000000000..3a7ae333d --- /dev/null +++ b/test_utils/lib/version.h @@ -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 -- 2.47.2