2
* Copyright (c) 2003-2007 Tim Kientzle
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
__FBSDID("$FreeBSD$");
29
* Test that --version option works and generates reasonable output.
33
verify(const char *p, size_t s)
37
/* Version message should start with name of program, then space. */
38
failure("version message too short:", p);
41
failure("Version message should begin with 'bsdcpio': %s", p);
42
if (!assertEqualMem(q, "bsdcpio ", 8))
43
/* If we're not testing bsdcpio, don't keep going. */
46
/* Version number is a series of digits and periods. */
47
while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
51
/* Version number terminated by space. */
52
failure("Version: %s", p);
54
/* Skip a single trailing a,b,c, or d. */
55
if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
57
failure("Version: %s", p);
61
failure("Version: %s", p);
62
assertEqualMem(q, "-- ", 3);
64
/* libarchive name and version number */
66
failure("Version: %s", p);
67
assertEqualMem(q, "libarchive ", 11);
69
/* Version number is a series of digits and periods. */
70
while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
74
/* Skip a single trailing a,b,c, or d. */
75
if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
77
/* All terminated by end-of-line: \r, \r\n, or \n */
79
failure("Version: %s", p);
82
assertEqualMem(q, "\x0d\x0a", 2);
84
assertEqualMem(q, "\x0a", 1);
88
DEFINE_TEST(test_option_version)
94
r = systemf("%s --version >version.stdout 2>version.stderr", testprog);
96
r = systemf("%s -W version >version.stdout 2>version.stderr",
98
failure("Unable to run either %s --version or %s -W version",
103
/* --version should generate nothing to stderr. */
104
assertEmptyFile("version.stderr");
105
/* Verify format of version message. */
106
p = slurpfile(&s, "version.stdout");