1caf54c4fSMartin Matuska /*-
2*bd66c1b4SMartin Matuska * SPDX-License-Identifier: BSD-2-Clause
3*bd66c1b4SMartin Matuska *
4caf54c4fSMartin Matuska * Copyright (c) 2003-2009 Tim Kientzle
5caf54c4fSMartin Matuska * All rights reserved.
6caf54c4fSMartin Matuska */
7caf54c4fSMartin Matuska #include "test.h"
8caf54c4fSMartin Matuska
9caf54c4fSMartin Matuska /*
10caf54c4fSMartin Matuska * Test the command-line parsing.
11caf54c4fSMartin Matuska */
12caf54c4fSMartin Matuska
DEFINE_TEST(test_cmdline)13caf54c4fSMartin Matuska DEFINE_TEST(test_cmdline)
14caf54c4fSMartin Matuska {
15caf54c4fSMartin Matuska FILE *f;
16caf54c4fSMartin Matuska
17caf54c4fSMartin Matuska /* Create an empty file. */
18caf54c4fSMartin Matuska f = fopen("empty", "wb");
19caf54c4fSMartin Matuska assert(f != NULL);
20caf54c4fSMartin Matuska fclose(f);
21caf54c4fSMartin Matuska
22caf54c4fSMartin Matuska failure("-Q is an invalid option on every cpio program I know of");
23caf54c4fSMartin Matuska assert(0 != systemf("%s -i -Q <empty >1.out 2>1.err", testprog));
24caf54c4fSMartin Matuska assertEmptyFile("1.out");
25caf54c4fSMartin Matuska
26caf54c4fSMartin Matuska failure("-f requires an argument");
27caf54c4fSMartin Matuska assert(0 != systemf("%s -if <empty >2.out 2>2.err", testprog));
28caf54c4fSMartin Matuska assertEmptyFile("2.out");
29caf54c4fSMartin Matuska
30caf54c4fSMartin Matuska failure("-f requires an argument");
31caf54c4fSMartin Matuska assert(0 != systemf("%s -i -f <empty >3.out 2>3.err", testprog));
32caf54c4fSMartin Matuska assertEmptyFile("3.out");
33caf54c4fSMartin Matuska
34caf54c4fSMartin Matuska failure("--format requires an argument");
35caf54c4fSMartin Matuska assert(0 != systemf("%s -i --format <empty >4.out 2>4.err", testprog));
36caf54c4fSMartin Matuska assertEmptyFile("4.out");
37caf54c4fSMartin Matuska
38caf54c4fSMartin Matuska failure("--badopt is an invalid option");
39caf54c4fSMartin Matuska assert(0 != systemf("%s -i --badop <empty >5.out 2>5.err", testprog));
40caf54c4fSMartin Matuska assertEmptyFile("5.out");
41caf54c4fSMartin Matuska
42caf54c4fSMartin Matuska failure("--badopt is an invalid option");
43caf54c4fSMartin Matuska assert(0 != systemf("%s -i --badopt <empty >6.out 2>6.err", testprog));
44caf54c4fSMartin Matuska assertEmptyFile("6.out");
45caf54c4fSMartin Matuska
46caf54c4fSMartin Matuska failure("--n is ambiguous");
47caf54c4fSMartin Matuska assert(0 != systemf("%s -i --n <empty >7.out 2>7.err", testprog));
48caf54c4fSMartin Matuska assertEmptyFile("7.out");
49caf54c4fSMartin Matuska
50caf54c4fSMartin Matuska failure("--create forbids an argument");
51caf54c4fSMartin Matuska assert(0 != systemf("%s --create=arg <empty >8.out 2>8.err", testprog));
52caf54c4fSMartin Matuska assertEmptyFile("8.out");
53caf54c4fSMartin Matuska
54caf54c4fSMartin Matuska failure("-i with empty input should succeed");
55caf54c4fSMartin Matuska assert(0 == systemf("%s -i <empty >9.out 2>9.err", testprog));
56caf54c4fSMartin Matuska assertEmptyFile("9.out");
57caf54c4fSMartin Matuska
58caf54c4fSMartin Matuska failure("-o with empty input should succeed");
59caf54c4fSMartin Matuska assert(0 == systemf("%s -o <empty >10.out 2>10.err", testprog));
60caf54c4fSMartin Matuska
61caf54c4fSMartin Matuska failure("-i -p is nonsense");
62caf54c4fSMartin Matuska assert(0 != systemf("%s -i -p <empty >11.out 2>11.err", testprog));
63caf54c4fSMartin Matuska assertEmptyFile("11.out");
64caf54c4fSMartin Matuska
65caf54c4fSMartin Matuska failure("-p -i is nonsense");
66caf54c4fSMartin Matuska assert(0 != systemf("%s -p -i <empty >12.out 2>12.err", testprog));
67caf54c4fSMartin Matuska assertEmptyFile("12.out");
68caf54c4fSMartin Matuska
69caf54c4fSMartin Matuska failure("-i -o is nonsense");
70caf54c4fSMartin Matuska assert(0 != systemf("%s -i -o <empty >13.out 2>13.err", testprog));
71caf54c4fSMartin Matuska assertEmptyFile("13.out");
72caf54c4fSMartin Matuska
73caf54c4fSMartin Matuska failure("-o -i is nonsense");
74caf54c4fSMartin Matuska assert(0 != systemf("%s -o -i <empty >14.out 2>14.err", testprog));
75caf54c4fSMartin Matuska assertEmptyFile("14.out");
76caf54c4fSMartin Matuska
77caf54c4fSMartin Matuska failure("-o -p is nonsense");
78caf54c4fSMartin Matuska assert(0 != systemf("%s -o -p <empty >15.out 2>15.err", testprog));
79caf54c4fSMartin Matuska assertEmptyFile("15.out");
80caf54c4fSMartin Matuska
81caf54c4fSMartin Matuska failure("-p -o is nonsense");
82caf54c4fSMartin Matuska assert(0 != systemf("%s -p -o <empty >16.out 2>16.err", testprog));
83caf54c4fSMartin Matuska assertEmptyFile("16.out");
84caf54c4fSMartin Matuska
85caf54c4fSMartin Matuska failure("-p with empty input should fail");
86caf54c4fSMartin Matuska assert(0 != systemf("%s -p <empty >17.out 2>17.err", testprog));
87caf54c4fSMartin Matuska assertEmptyFile("17.out");
88caf54c4fSMartin Matuska }
89