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