1 #!/bin/sh 2 # 3 # Copyright (c) International Business Machines Corp., 2000 4 # 06/01 Robbie Williamson (robbiew (at] us.ibm.com) 5 # Copyright (c) 2016 Cyril Hrubis <chrubis (at] suse.cz> 6 # 7 # This program is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 15 # the GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program; if not, write to the Free Software 19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 # 21 #----------------------------------------------------------------------- 22 # 23 # This is a basic ar command test. 24 # 25 AR="${AR:=ar}" 26 TST_CNT=17 27 TST_TESTFUNC=test 28 TST_NEEDS_TMPDIR=1 29 TST_NEEDS_CMDS="$AR" 30 31 . tst_test.sh 32 33 test1() 34 { 35 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in 36 ROD ar -ra file1.in lib.a $TST_DATAROOT/file2.in 37 ROD ar -t lib.a \> ar.out 38 39 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 40 41 if diff ar.out ar.exp >/dev/null; then 42 tst_res TPASS "ar added new file after another (-a)" 43 else 44 tst_res TFAIL "ar failed to add new file after another (-a)" 45 cat ar.out 46 fi 47 48 ROD rm lib.a 49 } 50 51 test2() 52 { 53 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 54 $TST_DATAROOT/file3.in $TST_DATAROOT/file4.in 55 ROD ar -ma file1.in lib.a file4.in 56 ROD ar -t lib.a \> ar.out 57 58 printf "file1.in\nfile4.in\nfile2.in\nfile3.in\n" > ar.exp 59 60 if diff ar.out ar.exp > /dev/null; then 61 tst_res TPASS "ar moved file correctly (-ma)" 62 else 63 tst_res TFAIL "ar failed to move file (-ma)" 64 cat ar.out 65 fi 66 67 ROD rm lib.a 68 } 69 70 test3() 71 { 72 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in 73 ROD ar -rb file3.in lib.a $TST_DATAROOT/file2.in 74 ROD ar -t lib.a \> ar.out 75 76 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 77 78 if diff ar.out ar.exp; then 79 tst_res TPASS "ar added new file before another (-b)" 80 else 81 tst_res TFAIL "ar failed to add new file before another (-b)" 82 cat ar.out 83 fi 84 85 ROD rm lib.a 86 } 87 88 test4() 89 { 90 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \ 91 $TST_DATAROOT/file2.in 92 ROD ar -mb file3.in lib.a file2.in 93 ROD ar -t lib.a \> ar.out 94 95 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 96 97 if diff ar.out ar.exp > /dev/null; then 98 tst_res TPASS "ar moved file correctly (-mb)" 99 else 100 tst_res TFAIL "ar failed to move file (-mb)" 101 cat ar.out 102 fi 103 104 ROD rm lib.a 105 } 106 107 test5() 108 { 109 ROD ar -cr lib.a $TST_DATAROOT/file1.in \> ar.out 110 111 if [ -s ar.out ]; then 112 tst_res TFAIL "ar produced output unexpectedly (-c)" 113 cat ar.out 114 else 115 tst_res TPASS "ar haven't produced output (-c)" 116 fi 117 118 ROD rm lib.a 119 } 120 121 test6() 122 { 123 ROD ar -qc lib.a $TST_DATAROOT/file1.in \> ar.out 124 125 if [ -s ar.out ]; then 126 tst_res TFAIL "ar produced output unexpectedly (-qc)" 127 cat ar.out 128 else 129 tst_res TPASS "ar haven't produced output (-qc)" 130 fi 131 132 ROD rm lib.a 133 } 134 135 test7() 136 { 137 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 138 $TST_DATAROOT/file3.in 139 ROD ar -d lib.a file1.in file2.in 140 ROD ar -t lib.a \> ar.out 141 142 printf "file3.in\n" > ar.exp 143 144 if diff ar.out ar.exp > /dev/null; then 145 tst_res TPASS "ar deleted files correctly (-d)" 146 else 147 tst_res TFAIL "ar messed up when deleting files (-d)" 148 cat ar.out 149 fi 150 151 ROD rm lib.a 152 } 153 154 test8() 155 { 156 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 157 $TST_DATAROOT/file3.in 158 ROD ar -d lib.a 159 ROD ar -t lib.a \> ar.out 160 161 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 162 163 if diff ar.out ar.exp > /dev/null; then 164 tst_res TPASS "ar deleted nothing (-d with empty list)" 165 else 166 tst_res TFAIL "ar deleted files (-d with empty list)" 167 cat ar.out 168 fi 169 170 ROD rm lib.a 171 } 172 173 test9() 174 { 175 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in 176 ROD ar -ri file3.in lib.a $TST_DATAROOT/file2.in 177 ROD ar -t lib.a \> ar.out 178 179 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 180 181 if diff ar.out ar.exp >/dev/null; then 182 tst_res TPASS "ar added new file before another (-i)" 183 else 184 tst_res TFAIL "ar failed to add new file before another (-i" 185 cat ar.out 186 fi 187 188 ROD rm lib.a 189 } 190 191 test10() 192 { 193 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \ 194 $TST_DATAROOT/file2.in 195 ROD ar -mi file3.in lib.a file2.in 196 ROD ar -t lib.a \> ar.out 197 198 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 199 200 if diff ar.out ar.exp > /dev/null; then 201 tst_res TPASS "ar moved file correctly (-mi)" 202 else 203 tst_res TFAIL "ar failed to move file (-mi)" 204 cat ar.out 205 fi 206 207 ROD rm lib.a 208 } 209 210 test11() 211 { 212 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \ 213 $TST_DATAROOT/file2.in 214 ROD ar -m lib.a file3.in 215 ROD ar -t lib.a \> ar.out 216 217 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 218 219 if diff ar.out ar.exp > /dev/null; then 220 tst_res TPASS "ar moved file correctly (-m)" 221 else 222 tst_res TFAIL "ar failed to move file (-m)" 223 cat ar.out 224 fi 225 226 ROD rm lib.a 227 } 228 229 test12() 230 { 231 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 232 $TST_DATAROOT/file3.in 233 ROD ar -p lib.a \> ar.out 234 235 printf "This is file one\nThis is file two\nThis is file three\n" > ar.exp 236 237 if diff ar.out ar.exp > /dev/null; then 238 tst_res TPASS "ar printed file content correctly (-p)" 239 else 240 tst_res TFAIL "ar failed to print file content (-p)" 241 cat ar.out 242 fi 243 244 ROD rm lib.a 245 } 246 247 test13() 248 { 249 250 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 251 $TST_DATAROOT/file3.in 252 ROD ar -q lib.a $TST_DATAROOT/file4.in 253 ROD ar -t lib.a \> ar.out 254 255 printf "file1.in\nfile2.in\nfile3.in\nfile4.in\n" > ar.exp 256 257 if diff ar.out ar.exp > /dev/null; then 258 tst_res TPASS "ar appended file correctly (-q)" 259 else 260 tst_res TFAIL "ar failed to append file (-q)" 261 cat ar.out 262 fi 263 264 ROD rm lib.a 265 } 266 267 test14() 268 { 269 ROD touch file0.in 270 ROD ar -cr lib.a file0.in $TST_DATAROOT/file1.in 271 272 file0_mtime1=$(ar -tv lib.a | grep file0.in) 273 file1_mtime1=$(ar -tv lib.a | grep file1.in) 274 275 touch -c -t $(date --date='next day' +"%Y%m%d%H%M") file0.in 276 277 ROD ar -ru lib.a file0.in $TST_DATAROOT/file1.in 278 279 file0_mtime2=$(ar -tv lib.a | grep file0.in) 280 file1_mtime2=$(ar -tv lib.a | grep file1.in) 281 282 if [ "$file0_mtime1" = "$file0_mtime2" ]; then 283 tst_res TFAIL "ar haven't updated modified file0 (-u)" 284 else 285 tst_res TPASS "ar updated modified file0 (-u)" 286 fi 287 288 if [ "$file1_mtime1" = "$file1_mtime2" ]; then 289 tst_res TPASS "ar haven't updated unmodified file1 (-u)" 290 else 291 tst_res TFAIL "ar updated unmodified file1 (-u)" 292 fi 293 294 ROD rm lib.a file0.in 295 } 296 297 test15() 298 { 299 ROD ar -cr lib.a $TST_DATAROOT/file1.in 300 ROD ar -tv lib.a \> ar.out 301 302 if grep -q '[rwx-]\{9\} [0-9].*/[0-9].*\s*[0-9].*.*file1.in' ar.out; then 303 tst_res TPASS "ar verbose listing works (-tv)" 304 else 305 tst_res TFAIL "ar verbose listing failed (-tv)" 306 cat ar.out 307 fi 308 309 ROD rm lib.a 310 } 311 312 test16() 313 { 314 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 315 $TST_DATAROOT/file3.in 316 ROD ar -xv lib.a \> ar.out 317 318 printf "x - file1.in\nx - file2.in\nx - file3.in\n" > ar.exp 319 320 if diff ar.out ar.exp > /dev/null; then 321 tst_res TPASS "ar printed extracted filenames (-xv)" 322 else 323 tst_res TFAIL "ar failed to print extracted filenames (-xv)" 324 cat ar.out 325 fi 326 327 if [ -e file1.in -a -e file2.in -a -e file3.in ]; then 328 tst_res TPASS "ar extracted files correctly" 329 else 330 tst_res TFAIL "ar failed to extract files" 331 fi 332 333 ROD rm -f lib.a file1.in file2.in file3.in 334 } 335 336 test17() 337 { 338 ROD ar -cr lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in 339 ROD ar -xv lib.a file2.in \> ar.out 340 341 printf "x - file2.in\n" > ar.exp 342 343 if diff ar.out ar.exp > /dev/null; then 344 tst_res TPASS "ar printed extracted filename (-xv)" 345 else 346 tst_res TFAIL "ar failed to print extracted filename (-xv)" 347 cat ar.out 348 fi 349 350 if [ -e file2.in ]; then 351 tst_res TPASS "ar extracted file correctly" 352 else 353 tst_res TFAIL "ar failed to extract file" 354 fi 355 356 ROD rm -f lib.a file2.in 357 } 358 359 tst_run 360