test_cmdline.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. __FBSDID("$FreeBSD$");
  27. /*
  28. * Test the command-line parsing.
  29. */
  30. DEFINE_TEST(test_cmdline)
  31. {
  32. FILE *f;
  33. /* Create an empty file. */
  34. f = fopen("empty", "wb");
  35. assert(f != NULL);
  36. fclose(f);
  37. failure("-Q is an invalid option on every cpio program I know of");
  38. assert(0 != systemf("%s -i -Q <empty >1.out 2>1.err", testprog));
  39. assertEmptyFile("1.out");
  40. failure("-f requires an argument");
  41. assert(0 != systemf("%s -if <empty >2.out 2>2.err", testprog));
  42. assertEmptyFile("2.out");
  43. failure("-f requires an argument");
  44. assert(0 != systemf("%s -i -f <empty >3.out 2>3.err", testprog));
  45. assertEmptyFile("3.out");
  46. failure("--format requires an argument");
  47. assert(0 != systemf("%s -i --format <empty >4.out 2>4.err", testprog));
  48. assertEmptyFile("4.out");
  49. failure("--badopt is an invalid option");
  50. assert(0 != systemf("%s -i --badop <empty >5.out 2>5.err", testprog));
  51. assertEmptyFile("5.out");
  52. failure("--badopt is an invalid option");
  53. assert(0 != systemf("%s -i --badopt <empty >6.out 2>6.err", testprog));
  54. assertEmptyFile("6.out");
  55. failure("--n is ambiguous");
  56. assert(0 != systemf("%s -i --n <empty >7.out 2>7.err", testprog));
  57. assertEmptyFile("7.out");
  58. failure("--create forbids an argument");
  59. assert(0 != systemf("%s --create=arg <empty >8.out 2>8.err", testprog));
  60. assertEmptyFile("8.out");
  61. failure("-i with empty input should succeed");
  62. assert(0 == systemf("%s -i <empty >9.out 2>9.err", testprog));
  63. assertEmptyFile("9.out");
  64. failure("-o with empty input should succeed");
  65. assert(0 == systemf("%s -o <empty >10.out 2>10.err", testprog));
  66. failure("-i -p is nonsense");
  67. assert(0 != systemf("%s -i -p <empty >11.out 2>11.err", testprog));
  68. assertEmptyFile("11.out");
  69. failure("-p -i is nonsense");
  70. assert(0 != systemf("%s -p -i <empty >12.out 2>12.err", testprog));
  71. assertEmptyFile("12.out");
  72. failure("-i -o is nonsense");
  73. assert(0 != systemf("%s -i -o <empty >13.out 2>13.err", testprog));
  74. assertEmptyFile("13.out");
  75. failure("-o -i is nonsense");
  76. assert(0 != systemf("%s -o -i <empty >14.out 2>14.err", testprog));
  77. assertEmptyFile("14.out");
  78. failure("-o -p is nonsense");
  79. assert(0 != systemf("%s -o -p <empty >15.out 2>15.err", testprog));
  80. assertEmptyFile("15.out");
  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. failure("-p with empty input should fail");
  85. assert(0 != systemf("%s -p <empty >17.out 2>17.err", testprog));
  86. assertEmptyFile("17.out");
  87. }