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.
28 * Test that --version option works and generates reasonable output.
31 DEFINE_TEST(test_version)
38 r = systemf("%s --version >version.stdout 2>version.stderr", testprog);
39 failure("Unable to run %s --version", testprog);
43 /* --version should generate nothing to stdout. */
44 assertEmptyFile("version.stderr");
45 /* Verify format of version message. */
46 q = p = slurpfile(&s, "version.stdout");
47 /* Version message should start with name of program, then space. */
49 failure("Version must start with 'bsdcat': ``%s''", p);
50 if (!assertEqualMem(q, "bsdcat ", 7))
53 /* Version number is a series of digits and periods. */
54 while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
58 /* Version number terminated by space. */
59 failure("No space after bsdcat version: ``%s''", p);
61 /* Skip a single trailing a,b,c, or d. */
62 if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
64 failure("No space after bsdcat version: ``%s''", p);
68 failure("No `-' between bsdcat and libarchive versions: ``%s''", p);
69 assertEqualMem(q, "- ", 2);
71 /* libarchive name and version number */
72 failure("Not long enough for libarchive version: ``%s''", p);
74 failure("Libarchive version must start with `libarchive': ``%s''", p);
75 assertEqualMem(q, "libarchive ", 11);
77 /* Version number is a series of digits and periods. */
78 while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
82 /* Skip a single trailing a,b,c, or d. */
83 if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
85 /* Skip arbitrary third-party version numbers. */
86 while (s > 0 && (*q == ' ' || *q == '/' || *q == '.' || isalnum(*q))) {
90 /* All terminated by end-of-line. */
92 /* Skip an optional CR character (e.g., Windows) */
93 failure("Version output must end with \\n or \\r\\n");
94 if (*q == '\r') { ++q; --s; }
95 assertEqualMem(q, "\n", 1);