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