xref: /freebsd/contrib/libarchive/cpio/test/test_cmdline.c (revision 53120fbb68952b7d620c2c0e1cf05c5017fc1b27)
1 /*-
2  * Copyright (c) 2003-2009 Tim Kientzle
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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.
24  */
25 #include "test.h"
26 
27 /*
28  * Test the command-line parsing.
29  */
30 
31 DEFINE_TEST(test_cmdline)
32 {
33 	FILE *f;
34 
35 	/* Create an empty file. */
36 	f = fopen("empty", "wb");
37 	assert(f != NULL);
38 	fclose(f);
39 
40 	failure("-Q is an invalid option on every cpio program I know of");
41 	assert(0 != systemf("%s -i -Q <empty >1.out 2>1.err", testprog));
42 	assertEmptyFile("1.out");
43 
44 	failure("-f requires an argument");
45 	assert(0 != systemf("%s -if <empty >2.out 2>2.err", testprog));
46 	assertEmptyFile("2.out");
47 
48 	failure("-f requires an argument");
49 	assert(0 != systemf("%s -i -f <empty >3.out 2>3.err", testprog));
50 	assertEmptyFile("3.out");
51 
52 	failure("--format requires an argument");
53 	assert(0 != systemf("%s -i --format <empty >4.out 2>4.err", testprog));
54 	assertEmptyFile("4.out");
55 
56 	failure("--badopt is an invalid option");
57 	assert(0 != systemf("%s -i --badop <empty >5.out 2>5.err", testprog));
58 	assertEmptyFile("5.out");
59 
60 	failure("--badopt is an invalid option");
61 	assert(0 != systemf("%s -i --badopt <empty >6.out 2>6.err", testprog));
62 	assertEmptyFile("6.out");
63 
64 	failure("--n is ambiguous");
65 	assert(0 != systemf("%s -i --n <empty >7.out 2>7.err", testprog));
66 	assertEmptyFile("7.out");
67 
68 	failure("--create forbids an argument");
69 	assert(0 != systemf("%s --create=arg <empty >8.out 2>8.err", testprog));
70 	assertEmptyFile("8.out");
71 
72 	failure("-i with empty input should succeed");
73 	assert(0 == systemf("%s -i <empty >9.out 2>9.err", testprog));
74 	assertEmptyFile("9.out");
75 
76 	failure("-o with empty input should succeed");
77 	assert(0 == systemf("%s -o <empty >10.out 2>10.err", testprog));
78 
79 	failure("-i -p is nonsense");
80 	assert(0 != systemf("%s -i -p <empty >11.out 2>11.err", testprog));
81 	assertEmptyFile("11.out");
82 
83 	failure("-p -i is nonsense");
84 	assert(0 != systemf("%s -p -i <empty >12.out 2>12.err", testprog));
85 	assertEmptyFile("12.out");
86 
87 	failure("-i -o is nonsense");
88 	assert(0 != systemf("%s -i -o <empty >13.out 2>13.err", testprog));
89 	assertEmptyFile("13.out");
90 
91 	failure("-o -i is nonsense");
92 	assert(0 != systemf("%s -o -i <empty >14.out 2>14.err", testprog));
93 	assertEmptyFile("14.out");
94 
95 	failure("-o -p is nonsense");
96 	assert(0 != systemf("%s -o -p <empty >15.out 2>15.err", testprog));
97 	assertEmptyFile("15.out");
98 
99 	failure("-p -o is nonsense");
100 	assert(0 != systemf("%s -p -o <empty >16.out 2>16.err", testprog));
101 	assertEmptyFile("16.out");
102 
103 	failure("-p with empty input should fail");
104 	assert(0 != systemf("%s -p <empty >17.out 2>17.err", testprog));
105 	assertEmptyFile("17.out");
106 }
107