diff options
author | Martin Matuska <martin@matuska.org> | 2017-02-21 13:12:07 +0100 |
---|---|---|
committer | Martin Matuska <martin@matuska.org> | 2017-02-21 13:15:44 +0100 |
commit | 042dc9445a45ff789a2fac9dd6976ec2df8b6f98 (patch) | |
tree | 843c5d996707f60815f915c0b66bc667122d6802 /cpio | |
parent | 481e97f6ab6cb909a31c39d1e4954db1a98cfdbb (diff) | |
parent | 47ac1b5306292bf17e7c5f15a1655578378411d6 (diff) | |
download | libarchive-042dc9445a45ff789a2fac9dd6976ec2df8b6f98.tar.gz |
Merge pull request #871 from praiskup/dev-in-version
Unify version test among tests and allow trailing "dev" in version.
Diffstat (limited to 'cpio')
-rw-r--r-- | cpio/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | cpio/test/test_option_version.c | 85 |
2 files changed, 3 insertions, 83 deletions
diff --git a/cpio/test/CMakeLists.txt b/cpio/test/CMakeLists.txt index 8ffb5427..c99ef65a 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 ac58cefd..78ac2180 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"); } |