1*caf54c4fSMartin Matuska /*- 2*caf54c4fSMartin Matuska * Copyright (c) 2003-2009 Tim Kientzle 3*caf54c4fSMartin Matuska * All rights reserved. 4*caf54c4fSMartin Matuska * 5*caf54c4fSMartin Matuska * Redistribution and use in source and binary forms, with or without 6*caf54c4fSMartin Matuska * modification, are permitted provided that the following conditions 7*caf54c4fSMartin Matuska * are met: 8*caf54c4fSMartin Matuska * 1. Redistributions of source code must retain the above copyright 9*caf54c4fSMartin Matuska * notice, this list of conditions and the following disclaimer. 10*caf54c4fSMartin Matuska * 2. Redistributions in binary form must reproduce the above copyright 11*caf54c4fSMartin Matuska * notice, this list of conditions and the following disclaimer in the 12*caf54c4fSMartin Matuska * documentation and/or other materials provided with the distribution. 13*caf54c4fSMartin Matuska * 14*caf54c4fSMartin Matuska * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15*caf54c4fSMartin Matuska * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16*caf54c4fSMartin Matuska * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17*caf54c4fSMartin Matuska * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18*caf54c4fSMartin Matuska * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19*caf54c4fSMartin Matuska * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20*caf54c4fSMartin Matuska * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21*caf54c4fSMartin Matuska * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22*caf54c4fSMartin Matuska * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23*caf54c4fSMartin Matuska * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24*caf54c4fSMartin Matuska */ 25*caf54c4fSMartin Matuska #include "test.h" 26*caf54c4fSMartin Matuska __FBSDID("$FreeBSD$"); 27*caf54c4fSMartin Matuska 28*caf54c4fSMartin Matuska /* 29*caf54c4fSMartin Matuska * Test the command-line parsing. 30*caf54c4fSMartin Matuska */ 31*caf54c4fSMartin Matuska 32*caf54c4fSMartin Matuska DEFINE_TEST(test_cmdline) 33*caf54c4fSMartin Matuska { 34*caf54c4fSMartin Matuska FILE *f; 35*caf54c4fSMartin Matuska 36*caf54c4fSMartin Matuska /* Create an empty file. */ 37*caf54c4fSMartin Matuska f = fopen("empty", "wb"); 38*caf54c4fSMartin Matuska assert(f != NULL); 39*caf54c4fSMartin Matuska fclose(f); 40*caf54c4fSMartin Matuska 41*caf54c4fSMartin Matuska failure("-Q is an invalid option on every cpio program I know of"); 42*caf54c4fSMartin Matuska assert(0 != systemf("%s -i -Q <empty >1.out 2>1.err", testprog)); 43*caf54c4fSMartin Matuska assertEmptyFile("1.out"); 44*caf54c4fSMartin Matuska 45*caf54c4fSMartin Matuska failure("-f requires an argument"); 46*caf54c4fSMartin Matuska assert(0 != systemf("%s -if <empty >2.out 2>2.err", testprog)); 47*caf54c4fSMartin Matuska assertEmptyFile("2.out"); 48*caf54c4fSMartin Matuska 49*caf54c4fSMartin Matuska failure("-f requires an argument"); 50*caf54c4fSMartin Matuska assert(0 != systemf("%s -i -f <empty >3.out 2>3.err", testprog)); 51*caf54c4fSMartin Matuska assertEmptyFile("3.out"); 52*caf54c4fSMartin Matuska 53*caf54c4fSMartin Matuska failure("--format requires an argument"); 54*caf54c4fSMartin Matuska assert(0 != systemf("%s -i --format <empty >4.out 2>4.err", testprog)); 55*caf54c4fSMartin Matuska assertEmptyFile("4.out"); 56*caf54c4fSMartin Matuska 57*caf54c4fSMartin Matuska failure("--badopt is an invalid option"); 58*caf54c4fSMartin Matuska assert(0 != systemf("%s -i --badop <empty >5.out 2>5.err", testprog)); 59*caf54c4fSMartin Matuska assertEmptyFile("5.out"); 60*caf54c4fSMartin Matuska 61*caf54c4fSMartin Matuska failure("--badopt is an invalid option"); 62*caf54c4fSMartin Matuska assert(0 != systemf("%s -i --badopt <empty >6.out 2>6.err", testprog)); 63*caf54c4fSMartin Matuska assertEmptyFile("6.out"); 64*caf54c4fSMartin Matuska 65*caf54c4fSMartin Matuska failure("--n is ambiguous"); 66*caf54c4fSMartin Matuska assert(0 != systemf("%s -i --n <empty >7.out 2>7.err", testprog)); 67*caf54c4fSMartin Matuska assertEmptyFile("7.out"); 68*caf54c4fSMartin Matuska 69*caf54c4fSMartin Matuska failure("--create forbids an argument"); 70*caf54c4fSMartin Matuska assert(0 != systemf("%s --create=arg <empty >8.out 2>8.err", testprog)); 71*caf54c4fSMartin Matuska assertEmptyFile("8.out"); 72*caf54c4fSMartin Matuska 73*caf54c4fSMartin Matuska failure("-i with empty input should succeed"); 74*caf54c4fSMartin Matuska assert(0 == systemf("%s -i <empty >9.out 2>9.err", testprog)); 75*caf54c4fSMartin Matuska assertEmptyFile("9.out"); 76*caf54c4fSMartin Matuska 77*caf54c4fSMartin Matuska failure("-o with empty input should succeed"); 78*caf54c4fSMartin Matuska assert(0 == systemf("%s -o <empty >10.out 2>10.err", testprog)); 79*caf54c4fSMartin Matuska 80*caf54c4fSMartin Matuska failure("-i -p is nonsense"); 81*caf54c4fSMartin Matuska assert(0 != systemf("%s -i -p <empty >11.out 2>11.err", testprog)); 82*caf54c4fSMartin Matuska assertEmptyFile("11.out"); 83*caf54c4fSMartin Matuska 84*caf54c4fSMartin Matuska failure("-p -i is nonsense"); 85*caf54c4fSMartin Matuska assert(0 != systemf("%s -p -i <empty >12.out 2>12.err", testprog)); 86*caf54c4fSMartin Matuska assertEmptyFile("12.out"); 87*caf54c4fSMartin Matuska 88*caf54c4fSMartin Matuska failure("-i -o is nonsense"); 89*caf54c4fSMartin Matuska assert(0 != systemf("%s -i -o <empty >13.out 2>13.err", testprog)); 90*caf54c4fSMartin Matuska assertEmptyFile("13.out"); 91*caf54c4fSMartin Matuska 92*caf54c4fSMartin Matuska failure("-o -i is nonsense"); 93*caf54c4fSMartin Matuska assert(0 != systemf("%s -o -i <empty >14.out 2>14.err", testprog)); 94*caf54c4fSMartin Matuska assertEmptyFile("14.out"); 95*caf54c4fSMartin Matuska 96*caf54c4fSMartin Matuska failure("-o -p is nonsense"); 97*caf54c4fSMartin Matuska assert(0 != systemf("%s -o -p <empty >15.out 2>15.err", testprog)); 98*caf54c4fSMartin Matuska assertEmptyFile("15.out"); 99*caf54c4fSMartin Matuska 100*caf54c4fSMartin Matuska failure("-p -o is nonsense"); 101*caf54c4fSMartin Matuska assert(0 != systemf("%s -p -o <empty >16.out 2>16.err", testprog)); 102*caf54c4fSMartin Matuska assertEmptyFile("16.out"); 103*caf54c4fSMartin Matuska 104*caf54c4fSMartin Matuska failure("-p with empty input should fail"); 105*caf54c4fSMartin Matuska assert(0 != systemf("%s -p <empty >17.out 2>17.err", testprog)); 106*caf54c4fSMartin Matuska assertEmptyFile("17.out"); 107*caf54c4fSMartin Matuska } 108