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 9AR="${AR:=ar}" 10TST_CNT=17 11TST_SETUP=setup 12TST_TESTFUNC=test 13TST_NEEDS_TMPDIR=1 14TST_NEEDS_CMDS="$AR" 15 16. tst_test.sh 17 18setup() 19{ 20 MOD= 21 ar --help | grep "use zero for timestamps and uids/gids (default)" >/dev/null 22 [ $? -eq 0 ] && MOD="U" 23} 24 25test1() 26{ 27 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in 28 ROD ar -ra"$MOD" file1.in lib.a $TST_DATAROOT/file2.in 29 ROD ar -t lib.a \> ar.out 30 31 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 32 33 if diff ar.out ar.exp >/dev/null; then 34 tst_res TPASS "ar added new file after another (-a)" 35 else 36 tst_res TFAIL "ar failed to add new file after another (-a)" 37 cat ar.out 38 fi 39 40 ROD rm lib.a 41} 42 43test2() 44{ 45 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 46 $TST_DATAROOT/file3.in $TST_DATAROOT/file4.in 47 ROD ar -ma"$MOD" file1.in lib.a file4.in 48 ROD ar -t lib.a \> ar.out 49 50 printf "file1.in\nfile4.in\nfile2.in\nfile3.in\n" > ar.exp 51 52 if diff ar.out ar.exp > /dev/null; then 53 tst_res TPASS "ar moved file correctly (-ma)" 54 else 55 tst_res TFAIL "ar failed to move file (-ma)" 56 cat ar.out 57 fi 58 59 ROD rm lib.a 60} 61 62test3() 63{ 64 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in 65 ROD ar -rb"$MOD" file3.in lib.a $TST_DATAROOT/file2.in 66 ROD ar -t lib.a \> ar.out 67 68 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 69 70 if diff ar.out ar.exp; then 71 tst_res TPASS "ar added new file before another (-b)" 72 else 73 tst_res TFAIL "ar failed to add new file before another (-b)" 74 cat ar.out 75 fi 76 77 ROD rm lib.a 78} 79 80test4() 81{ 82 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \ 83 $TST_DATAROOT/file2.in 84 ROD ar -mb"$MOD" file3.in lib.a file2.in 85 ROD ar -t lib.a \> ar.out 86 87 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 88 89 if diff ar.out ar.exp > /dev/null; then 90 tst_res TPASS "ar moved file correctly (-mb)" 91 else 92 tst_res TFAIL "ar failed to move file (-mb)" 93 cat ar.out 94 fi 95 96 ROD rm lib.a 97} 98 99test5() 100{ 101 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in \> ar.out 102 103 if [ -s ar.out ]; then 104 tst_res TFAIL "ar produced output unexpectedly (-c)" 105 cat ar.out 106 else 107 tst_res TPASS "ar haven't produced output (-c)" 108 fi 109 110 ROD rm lib.a 111} 112 113test6() 114{ 115 ROD ar -qc"$MOD" lib.a $TST_DATAROOT/file1.in \> ar.out 116 117 if [ -s ar.out ]; then 118 tst_res TFAIL "ar produced output unexpectedly (-qc)" 119 cat ar.out 120 else 121 tst_res TPASS "ar haven't produced output (-qc)" 122 fi 123 124 ROD rm lib.a 125} 126 127test7() 128{ 129 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 130 $TST_DATAROOT/file3.in 131 ROD ar -d"$MOD" lib.a file1.in file2.in 132 ROD ar -t lib.a \> ar.out 133 134 printf "file3.in\n" > ar.exp 135 136 if diff ar.out ar.exp > /dev/null; then 137 tst_res TPASS "ar deleted files correctly (-d)" 138 else 139 tst_res TFAIL "ar messed up when deleting files (-d)" 140 cat ar.out 141 fi 142 143 ROD rm lib.a 144} 145 146test8() 147{ 148 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 149 $TST_DATAROOT/file3.in 150 ROD ar -d"$MOD" lib.a 151 ROD ar -t lib.a \> ar.out 152 153 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 154 155 if diff ar.out ar.exp > /dev/null; then 156 tst_res TPASS "ar deleted nothing (-d with empty list)" 157 else 158 tst_res TFAIL "ar deleted files (-d with empty list)" 159 cat ar.out 160 fi 161 162 ROD rm lib.a 163} 164 165test9() 166{ 167 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in 168 ROD ar -ri"$MOD" file3.in lib.a $TST_DATAROOT/file2.in 169 ROD ar -t lib.a \> ar.out 170 171 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 172 173 if diff ar.out ar.exp >/dev/null; then 174 tst_res TPASS "ar added new file before another (-i)" 175 else 176 tst_res TFAIL "ar failed to add new file before another (-i" 177 cat ar.out 178 fi 179 180 ROD rm lib.a 181} 182 183test10() 184{ 185 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \ 186 $TST_DATAROOT/file2.in 187 ROD ar -mi"$MOD" file3.in lib.a file2.in 188 ROD ar -t lib.a \> ar.out 189 190 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 191 192 if diff ar.out ar.exp > /dev/null; then 193 tst_res TPASS "ar moved file correctly (-mi)" 194 else 195 tst_res TFAIL "ar failed to move file (-mi)" 196 cat ar.out 197 fi 198 199 ROD rm lib.a 200} 201 202test11() 203{ 204 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file3.in \ 205 $TST_DATAROOT/file2.in 206 ROD ar -m"$MOD" lib.a file3.in 207 ROD ar -t lib.a \> ar.out 208 209 printf "file1.in\nfile2.in\nfile3.in\n" > ar.exp 210 211 if diff ar.out ar.exp > /dev/null; then 212 tst_res TPASS "ar moved file correctly (-m)" 213 else 214 tst_res TFAIL "ar failed to move file (-m)" 215 cat ar.out 216 fi 217 218 ROD rm lib.a 219} 220 221test12() 222{ 223 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 224 $TST_DATAROOT/file3.in 225 ROD ar -p"$MOD" lib.a \> ar.out 226 227 printf "This is file one\nThis is file two\nThis is file three\n" > ar.exp 228 229 if diff ar.out ar.exp > /dev/null; then 230 tst_res TPASS "ar printed file content correctly (-p)" 231 else 232 tst_res TFAIL "ar failed to print file content (-p)" 233 cat ar.out 234 fi 235 236 ROD rm lib.a 237} 238 239test13() 240{ 241 242 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 243 $TST_DATAROOT/file3.in 244 ROD ar -q"$MOD" lib.a $TST_DATAROOT/file4.in 245 ROD ar -t lib.a \> ar.out 246 247 printf "file1.in\nfile2.in\nfile3.in\nfile4.in\n" > ar.exp 248 249 if diff ar.out ar.exp > /dev/null; then 250 tst_res TPASS "ar appended file correctly (-q)" 251 else 252 tst_res TFAIL "ar failed to append file (-q)" 253 cat ar.out 254 fi 255 256 ROD rm lib.a 257} 258 259test14() 260{ 261 ROD touch file0.in 262 ROD ar -cr"$MOD" lib.a file0.in $TST_DATAROOT/file1.in 263 264 file0_mtime1=$(ar -tv lib.a | grep file0.in) 265 file1_mtime1=$(ar -tv lib.a | grep file1.in) 266 267 touch -c -t $(date --date='next day' +"%Y%m%d%H%M") file0.in 268 269 ROD ar -ru"$MOD" lib.a file0.in $TST_DATAROOT/file1.in 270 271 file0_mtime2=$(ar -tv lib.a | grep file0.in) 272 file1_mtime2=$(ar -tv lib.a | grep file1.in) 273 274 if [ "$file0_mtime1" = "$file0_mtime2" ]; then 275 tst_res TFAIL "ar haven't updated modified file0 (-u)" 276 else 277 tst_res TPASS "ar updated modified file0 (-u)" 278 fi 279 280 if [ "$file1_mtime1" = "$file1_mtime2" ]; then 281 tst_res TPASS "ar haven't updated unmodified file1 (-u)" 282 else 283 tst_res TFAIL "ar updated unmodified file1 (-u)" 284 fi 285 286 ROD rm lib.a file0.in 287} 288 289test15() 290{ 291 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in 292 ROD ar -tv lib.a \> ar.out 293 294 if grep -q '[rwx-]\{9\} [0-9].*/[0-9].*\s*[0-9].*.*file1.in' ar.out; then 295 tst_res TPASS "ar verbose listing works (-tv)" 296 else 297 tst_res TFAIL "ar verbose listing failed (-tv)" 298 cat ar.out 299 fi 300 301 ROD rm lib.a 302} 303 304test16() 305{ 306 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in \ 307 $TST_DATAROOT/file3.in 308 ROD ar -xv"$MOD" lib.a \> ar.out 309 310 printf "x - file1.in\nx - file2.in\nx - file3.in\n" > ar.exp 311 312 if diff ar.out ar.exp > /dev/null; then 313 tst_res TPASS "ar printed extracted filenames (-xv)" 314 else 315 tst_res TFAIL "ar failed to print extracted filenames (-xv)" 316 cat ar.out 317 fi 318 319 if [ -e file1.in -a -e file2.in -a -e file3.in ]; then 320 tst_res TPASS "ar extracted files correctly" 321 else 322 tst_res TFAIL "ar failed to extract files" 323 fi 324 325 ROD rm -f lib.a file1.in file2.in file3.in 326} 327 328test17() 329{ 330 ROD ar -cr"$MOD" lib.a $TST_DATAROOT/file1.in $TST_DATAROOT/file2.in 331 ROD ar -xv"$MOD" lib.a file2.in \> ar.out 332 333 printf "x - file2.in\n" > ar.exp 334 335 if diff ar.out ar.exp > /dev/null; then 336 tst_res TPASS "ar printed extracted filename (-xv)" 337 else 338 tst_res TFAIL "ar failed to print extracted filename (-xv)" 339 cat ar.out 340 fi 341 342 if [ -e file2.in ]; then 343 tst_res TPASS "ar extracted file correctly" 344 else 345 tst_res TFAIL "ar failed to extract file" 346 fi 347 348 ROD rm -f lib.a file2.in 349} 350 351tst_run 352