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