ar01.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) International Business Machines Corp., 2000
  4. # Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
  5. # Author: Robbie Williamson <robbiew@us.ibm.com>
  6. #
  7. # This is a basic ar command test.
  8. AR="${AR:=ar}"
  9. TST_CNT=17
  10. TST_SETUP=setup
  11. TST_TESTFUNC=test
  12. TST_NEEDS_TMPDIR=1
  13. TST_NEEDS_CMDS="$AR"
  14. . tst_test.sh
  15. setup()
  16. {
  17. MOD=
  18. ar --help | grep "use zero for timestamps and uids/gids (default)" >/dev/null
  19. [ $? -eq 0 ] && MOD="U"
  20. }
  21. test1()
  22. {
  23. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in
  24. ROD ar -ra"$MOD" file1.in lib.a $TST_DATAROOT/file2.in
  25. ROD ar -t lib.a \> ar.out
  26. printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
  27. if diff ar.out ar.exp >/dev/null; then
  28. tst_res TPASS "ar added new file after another (-a)"
  29. else
  30. tst_res TFAIL "ar failed to add new file after another (-a)"
  31. cat ar.out
  32. fi
  33. ROD rm lib.a
  34. }
  35. test2()
  36. {
  37. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
  38. $TST_DATAROOT/file3.in $TST_DATAROOT/file4.in
  39. ROD ar -ma"$MOD" file1.in lib.a file4.in
  40. ROD ar -t lib.a \> ar.out
  41. printf "file1.in\nfile4.in\nfile2.in\nfile3.in\n" > ar.exp
  42. if diff ar.out ar.exp > /dev/null; then
  43. tst_res TPASS "ar moved file correctly (-ma)"
  44. else
  45. tst_res TFAIL "ar failed to move file (-ma)"
  46. cat ar.out
  47. fi
  48. ROD rm lib.a
  49. }
  50. test3()
  51. {
  52. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in
  53. ROD ar -rb"$MOD" file3.in lib.a $TST_DATAROOT/file2.in
  54. ROD ar -t lib.a \> ar.out
  55. printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
  56. if diff ar.out ar.exp; then
  57. tst_res TPASS "ar added new file before another (-b)"
  58. else
  59. tst_res TFAIL "ar failed to add new file before another (-b)"
  60. cat ar.out
  61. fi
  62. ROD rm lib.a
  63. }
  64. test4()
  65. {
  66. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \
  67. $TST_DATAROOT/file2.in
  68. ROD ar -mb"$MOD" file3.in lib.a file2.in
  69. ROD ar -t lib.a \> ar.out
  70. printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
  71. if diff ar.out ar.exp > /dev/null; then
  72. tst_res TPASS "ar moved file correctly (-mb)"
  73. else
  74. tst_res TFAIL "ar failed to move file (-mb)"
  75. cat ar.out
  76. fi
  77. ROD rm lib.a
  78. }
  79. test5()
  80. {
  81. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in \> ar.out
  82. if [ -s ar.out ]; then
  83. tst_res TFAIL "ar produced output unexpectedly (-c)"
  84. cat ar.out
  85. else
  86. tst_res TPASS "ar haven't produced output (-c)"
  87. fi
  88. ROD rm lib.a
  89. }
  90. test6()
  91. {
  92. ROD ar -qc"$MOD" lib.a $TST_DATAROOT/file1.in \> ar.out
  93. if [ -s ar.out ]; then
  94. tst_res TFAIL "ar produced output unexpectedly (-qc)"
  95. cat ar.out
  96. else
  97. tst_res TPASS "ar haven't produced output (-qc)"
  98. fi
  99. ROD rm lib.a
  100. }
  101. test7()
  102. {
  103. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
  104. $TST_DATAROOT/file3.in
  105. ROD ar -d"$MOD" lib.a file1.in file2.in
  106. ROD ar -t lib.a \> ar.out
  107. printf "file3.in\n" > ar.exp
  108. if diff ar.out ar.exp > /dev/null; then
  109. tst_res TPASS "ar deleted files correctly (-d)"
  110. else
  111. tst_res TFAIL "ar messed up when deleting files (-d)"
  112. cat ar.out
  113. fi
  114. ROD rm lib.a
  115. }
  116. test8()
  117. {
  118. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
  119. $TST_DATAROOT/file3.in
  120. ROD ar -d"$MOD" lib.a
  121. ROD ar -t lib.a \> ar.out
  122. printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
  123. if diff ar.out ar.exp > /dev/null; then
  124. tst_res TPASS "ar deleted nothing (-d with empty list)"
  125. else
  126. tst_res TFAIL "ar deleted files (-d with empty list)"
  127. cat ar.out
  128. fi
  129. ROD rm lib.a
  130. }
  131. test9()
  132. {
  133. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in
  134. ROD ar -ri"$MOD" file3.in lib.a $TST_DATAROOT/file2.in
  135. ROD ar -t lib.a \> ar.out
  136. printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
  137. if diff ar.out ar.exp >/dev/null; then
  138. tst_res TPASS "ar added new file before another (-i)"
  139. else
  140. tst_res TFAIL "ar failed to add new file before another (-i"
  141. cat ar.out
  142. fi
  143. ROD rm lib.a
  144. }
  145. test10()
  146. {
  147. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \
  148. $TST_DATAROOT/file2.in
  149. ROD ar -mi"$MOD" file3.in lib.a file2.in
  150. ROD ar -t lib.a \> ar.out
  151. printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
  152. if diff ar.out ar.exp > /dev/null; then
  153. tst_res TPASS "ar moved file correctly (-mi)"
  154. else
  155. tst_res TFAIL "ar failed to move file (-mi)"
  156. cat ar.out
  157. fi
  158. ROD rm lib.a
  159. }
  160. test11()
  161. {
  162. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \
  163. $TST_DATAROOT/file2.in
  164. ROD ar -m"$MOD" lib.a file3.in
  165. ROD ar -t lib.a \> ar.out
  166. printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp
  167. if diff ar.out ar.exp > /dev/null; then
  168. tst_res TPASS "ar moved file correctly (-m)"
  169. else
  170. tst_res TFAIL "ar failed to move file (-m)"
  171. cat ar.out
  172. fi
  173. ROD rm lib.a
  174. }
  175. test12()
  176. {
  177. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
  178. $TST_DATAROOT/file3.in
  179. ROD ar -p"$MOD" lib.a \> ar.out
  180. printf "This is file one\nThis is file two\nThis is file three\n" > ar.exp
  181. if diff ar.out ar.exp > /dev/null; then
  182. tst_res TPASS "ar printed file content correctly (-p)"
  183. else
  184. tst_res TFAIL "ar failed to print file content (-p)"
  185. cat ar.out
  186. fi
  187. ROD rm lib.a
  188. }
  189. test13()
  190. {
  191. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
  192. $TST_DATAROOT/file3.in
  193. ROD ar -q"$MOD" lib.a $TST_DATAROOT/file4.in
  194. ROD ar -t lib.a \> ar.out
  195. printf "file1.in\nfile2.in\nfile3.in\nfile4.in\n" > ar.exp
  196. if diff ar.out ar.exp > /dev/null; then
  197. tst_res TPASS "ar appended file correctly (-q)"
  198. else
  199. tst_res TFAIL "ar failed to append file (-q)"
  200. cat ar.out
  201. fi
  202. ROD rm lib.a
  203. }
  204. test14()
  205. {
  206. ROD touch file0.in
  207. ROD ar -cr"$MOD" lib.a file0.in $TST_DATAROOT/file1.in
  208. file0_mtime1=$(ar -tv lib.a | grep file0.in)
  209. file1_mtime1=$(ar -tv lib.a | grep file1.in)
  210. touch -c -t $(date --date='next day' +"%Y%m%d%H%M") file0.in
  211. ROD ar -ru"$MOD" lib.a file0.in $TST_DATAROOT/file1.in
  212. file0_mtime2=$(ar -tv lib.a | grep file0.in)
  213. file1_mtime2=$(ar -tv lib.a | grep file1.in)
  214. if [ "$file0_mtime1" = "$file0_mtime2" ]; then
  215. tst_res TFAIL "ar haven't updated modified file0 (-u)"
  216. else
  217. tst_res TPASS "ar updated modified file0 (-u)"
  218. fi
  219. if [ "$file1_mtime1" = "$file1_mtime2" ]; then
  220. tst_res TPASS "ar haven't updated unmodified file1 (-u)"
  221. else
  222. tst_res TFAIL "ar updated unmodified file1 (-u)"
  223. fi
  224. ROD rm lib.a file0.in
  225. }
  226. test15()
  227. {
  228. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in
  229. ROD ar -tv lib.a \> ar.out
  230. if grep -q '[rwx-]\{9\} [0-9].*/[0-9].*\s*[0-9].*.*file1.in' ar.out; then
  231. tst_res TPASS "ar verbose listing works (-tv)"
  232. else
  233. tst_res TFAIL "ar verbose listing failed (-tv)"
  234. cat ar.out
  235. fi
  236. ROD rm lib.a
  237. }
  238. test16()
  239. {
  240. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \
  241. $TST_DATAROOT/file3.in
  242. ROD ar -xv"$MOD" lib.a \> ar.out
  243. printf "x - file1.in\nx - file2.in\nx - file3.in\n" > ar.exp
  244. if diff ar.out ar.exp > /dev/null; then
  245. tst_res TPASS "ar printed extracted filenames (-xv)"
  246. else
  247. tst_res TFAIL "ar failed to print extracted filenames (-xv)"
  248. cat ar.out
  249. fi
  250. if [ -e file1.in -a -e file2.in -a -e file3.in ]; then
  251. tst_res TPASS "ar extracted files correctly"
  252. else
  253. tst_res TFAIL "ar failed to extract files"
  254. fi
  255. ROD rm -f lib.a file1.in file2.in file3.in
  256. }
  257. test17()
  258. {
  259. ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in
  260. ROD ar -xv"$MOD" lib.a file2.in \> ar.out
  261. printf "x - file2.in\n" > ar.exp
  262. if diff ar.out ar.exp > /dev/null; then
  263. tst_res TPASS "ar printed extracted filename (-xv)"
  264. else
  265. tst_res TFAIL "ar failed to print extracted filename (-xv)"
  266. cat ar.out
  267. fi
  268. if [ -e file2.in ]; then
  269. tst_res TPASS "ar extracted file correctly"
  270. else
  271. tst_res TFAIL "ar failed to extract file"
  272. fi
  273. ROD rm -f lib.a file2.in
  274. }
  275. tst_run