summaryrefslogtreecommitdiffstats
path: root/testsuite/check.sh
blob: 56aafdb90d7d4fcf3c5134d41662ad945bb542a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
#! /bin/sh
# check script for Tarlz - Archiver with multimember lzip compression
# Copyright (C) 2013-2022 Antonio Diaz Diaz.
#
# This script is free software: you have unlimited permission
# to copy, distribute, and modify it.

LC_ALL=C
export LC_ALL
objdir=`pwd`
testdir=`cd "$1" ; pwd`
TARLZ="${objdir}"/tarlz
framework_failure() { echo "failure in testing framework" ; exit 1 ; }

if [ ! -f "${TARLZ}" ] || [ ! -x "${TARLZ}" ] ; then
	echo "${TARLZ}: cannot execute"
	exit 1
fi

[ -e "${TARLZ}" ] 2> /dev/null ||
	{
	echo "$0: a POSIX shell is required to run the tests"
	echo "Try bash -c \"$0 $1 $2\""
	exit 1
	}

if [ -d tmp ] ; then rm -rf tmp ; fi
mkdir tmp
cd "${objdir}"/tmp || framework_failure

in="${testdir}"/test.txt
in_lz="${testdir}"/test.txt.lz
in_tar="${testdir}"/test.txt.tar
in_tar_lz="${testdir}"/test.txt.tar.lz
inbad1="${testdir}"/test_bad1.txt
inbad2="${testdir}"/test_bad2.txt
test3="${testdir}"/test3.tar
test3_lz="${testdir}"/test3.tar.lz
test3dir="${testdir}"/test3_dir.tar
test3dir_lz="${testdir}"/test3_dir.tar.lz
test3dot_lz="${testdir}"/test3_dot.tar.lz
t155="${testdir}"/t155.tar
t155_lz="${testdir}"/t155.tar.lz
tlzit1="${testdir}"/tlz_in_tar1.tar
tlzit2="${testdir}"/tlz_in_tar2.tar
bad1="${testdir}"/test3_bad1.tar
bad2="${testdir}"/test3_bad2.tar
bad3="${testdir}"/test3_bad3.tar
bad4="${testdir}"/test3_bad4.tar
bad5="${testdir}"/test3_bad5.tar
bad1_lz="${testdir}"/test3_bad1.tar.lz
bad2_lz="${testdir}"/test3_bad2.tar.lz
bad3_lz="${testdir}"/test3_bad3.tar.lz
bad4_lz="${testdir}"/test3_bad4.tar.lz
bad5_lz="${testdir}"/test3_bad5.tar.lz
bad6_lz="${testdir}"/test3_bad6.tar.lz
eof="${testdir}"/eof.tar
eof_lz="${testdir}"/eof.tar.lz
fail=0
lwarnc=0
test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
cyg_symlink() { [ ${lwarnc} = 0 ] &&
	printf "\nwarning: your OS follows symbolic links to directories even when tarlz asks it not to\n$1"
	lwarnc=1 ; }

# Description of test files for tarlz:
# test.txt.tar.lz:   1 member (test.txt).
# t155.tar[.lz]:     directory + 3 links + file + eof, all with 155 char names
# t155_fv?.tar[.lz]: like t155.tar but with 3 kinds of format violations
# t155_fv1.tar[.lz]: extended header followed by EOF blocks
# t155_fv2.tar[.lz]: extended header followed by global header
# t155_fv3.tar[.lz]: consecutive extended headers
# t155_fv[456].tar.lz: like t155_fv[123].tar.lz but violation starts member
# tar_in_tlz1.tar.lz: 2 members (test.txt.tar test3.tar) 3 lzip members
# tar_in_tlz2.tar.lz: 2 members (test.txt.tar test3.tar) 5 lzip members
# ts_in_link.tar.lz: 4 symbolic links (link[1-4]) to / /dir/ dir/ dir(107/)
# test_bad1.txt.tar.lz: truncated at offset 6000 (of 7495)
# test_bad2.txt.tar.lz: byte at offset 6000 changed from 0x56 to 0x46
# test3.tar[.lz]:    3 members (foo bar baz) + 2 zeroed 512-byte blocks
# test3_dir.tar[.lz] like test3.tar but members /dir/foo /dir/bar /dir/baz
# test3_dot.tar.lz:  3 times 3 members ./foo ././bar ./././baz
#                    the 3 central members with filename in extended header
# test3_bad1.tar:    byte at offset  259 changed from 't' to '0' (magic)
# test3_bad2.tar:    byte at offset 1283 changed from 't' to '0' (magic)
# test3_bad3.tar:    byte at offset 2559 changed from 0x00 to 0x20 (padding)
# test3_bad4.tar:    byte at offset 1283 changed from 't' to '0' (magic)
#                    byte at offset 2307 changed from 't' to '0' (magic)
# test3_bad5.tar:    510 zeros + "LZ" prepended to test3.tar (bogus lz header)
# test3_bad1.tar.lz: byte at offset    2 changed from 'I' to 'i' (magic)
# test3_bad2.tar.lz: byte at offset   49 changed from 0x49 to 0x69 (mid stream)
# test3_bad3.tar.lz: byte at offset  176 changed from 0x7D to 0x6D (mid stream)
# test3_bad4.tar.lz: combined damage of test3_bad2.tar.lz and test3_bad3.tar.lz
# test3_bad5.tar.lz: [71-134] --> zeroed (first trailer + seconf header)
# test3_bad6.tar.lz: 510 zeros prepended to test3.tar.lz (header in two blocks)
# test3_eof?.tar:    like test3_eof?.tar.lz but uncompressed
# test3_eof1.tar.lz: test3.tar.lz without eof blocks
# test3_eof2.tar.lz: test3.tar.lz with only one eof block
# test3_eof3.tar.lz: test3.tar.lz with one zeroed block between foo and bar
# test3_eof4.tar.lz: test3.tar.lz ended by extended header without eof blocks
# test3_eof5.tar.lz: test3.tar.lz split ext first member, without eof blocks
# test3_em?.tar.lz:  test3.tar.lz with one empty lzip member at each position
# test3_em6.tar.lz:  test3.tar.lz preceded by four empty lzip members
# test3_gh?.tar:     test3.tar with global header at each position
# test3_gh?.tar.lz:  test3.tar.lz with global before bar split in 4 ways
# test3_gh5.tar.lz:  test3.tar.lz with global in lzip member before foo
# test3_gh6.tar.lz:  test3.tar.lz with global before foo in same member
# test3_nn.tar[.lz]: test3.tar[.lz] with no name in bar member
# test3_sm?.tar.lz:  test3.tar.lz with extended bar member split in 4 ways
# tlz_in_tar1.tar:   1 member (test3.tar.lz) first magic damaged
# tlz_in_tar2.tar:   2 members (foo test3.tar.lz) first magic damaged
# ug32chars.tar.lz:  1 member (foo) with 32-character owner and group names
# ug32767.tar.lz:    1 member (foo) with numerical-only owner and group

# Note that multi-threaded --list succeeds with test_bad2.txt.tar.lz and
# test3_bad3.tar.lz because their headers are intact.

"${TARLZ}" --check-lib				# just print warning
[ $? != 2 ] || test_failed $LINENO		# unless bad lzlib.h
printf "testing tarlz-%s..." "$2"

"${TARLZ}" -q -tf "${in}"
[ $? = 2 ] || test_failed $LINENO
"${TARLZ}" -q -tf "${in_lz}"
[ $? = 2 ] || test_failed $LINENO
"${TARLZ}" -q -tf "${in_tar_lz}" -f "${in_tar_lz}"
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -tf nx_file
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -tf 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -cf out.tar.lz
[ $? = 1 ] || test_failed $LINENO
[ ! -e out.tar.lz ] || test_failed $LINENO
"${TARLZ}" -rf out.tar.lz || test_failed $LINENO
[ ! -e out.tar.lz ] || test_failed $LINENO
"${TARLZ}" -r || test_failed $LINENO
"${TARLZ}" --uncompressed -q -rf out.tar "${in}"
[ $? = 1 ] || test_failed $LINENO
[ ! -e out.tar ] || test_failed $LINENO
cat "${test3_lz}" > test.tar.lz || framework_failure
"${TARLZ}" --uncompressed -q -rf test.tar.lz "${in}"
[ $? = 2 ] || test_failed $LINENO
cmp "${test3_lz}" test.tar.lz || test_failed $LINENO
rm -f test.tar.lz || framework_failure
cat "${test3}" > test.tar || framework_failure
"${TARLZ}" -q -rf test.tar "${in}"
[ $? = 2 ] || test_failed $LINENO
cmp "${test3}" test.tar || test_failed $LINENO
rm -f test.tar || framework_failure
"${TARLZ}" -q -c "${in}" nx_file > /dev/null
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -c -C nx_dir "${in}"
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -x -C nx_dir "${test3_lz}"
[ $? = 1 ] || test_failed $LINENO
touch empty.tar.lz empty.tlz			# list an empty lz file
"${TARLZ}" -q -tf empty.tar.lz
[ $? = 2 ] || test_failed $LINENO
"${TARLZ}" -q -tf empty.tlz
[ $? = 2 ] || test_failed $LINENO
rm -f empty.tar.lz empty.tlz || framework_failure
"${TARLZ}" -q -cd				# test mixed operations
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -cr
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -ct
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -cx
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -tx
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -ctx
[ $? = 1 ] || test_failed $LINENO
for i in A c d r t x -delete ; do	# test -o with operations other than -z
	"${TARLZ}" -q -$i -o -
	[ $? = 1 ] || test_failed $LINENO $i
done
"${TARLZ}" -q -z -f -
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -z .
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -q -tf "${in_tar_lz}" ""
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" --help > /dev/null || test_failed $LINENO
"${TARLZ}" -V > /dev/null || test_failed $LINENO
"${TARLZ}" --bad_option -tf "${test3_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" -tf 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" --owner=invalid_oner_name -tf "${test3_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO
"${TARLZ}" --group=invalid_goup_name -tf "${test3_lz}" 2> /dev/null
[ $? = 1 ] || test_failed $LINENO

printf "\ntesting --list and --extract..."

# test --list and --extract
"${TARLZ}" -tf "${eof_lz}" --missing-crc || test_failed $LINENO
"${TARLZ}" -xf "${eof_lz}" --missing-crc || test_failed $LINENO
"${TARLZ}" -C nx_dir -tf "${in_tar}" > /dev/null || test_failed $LINENO
"${TARLZ}" -xf "${in_tar}" --missing-crc || test_failed $LINENO
cmp "${in}" test.txt || test_failed $LINENO
rm -f test.txt || framework_failure
"${TARLZ}" -tf "${in_tar_lz}" --missing-crc > /dev/null || test_failed $LINENO
for i in 0 2 6 ; do
	"${TARLZ}" -n$i -xf "${in_tar_lz}" --missing-crc || test_failed $LINENO $i
	cmp "${in}" test.txt || test_failed $LINENO $i
	rm -f test.txt || framework_failure
done

# test3 reference files for -t and -tv (list3, vlist3)
"${TARLZ}" -tf "${test3}" > list3 || test_failed $LINENO
"${TARLZ}" -tvf "${test3}" > vlist3 || test_failed $LINENO
for i in 0 2 6 ; do
	"${TARLZ}" -n$i -tf "${test3_lz}" > out || test_failed $LINENO $i
	diff -u list3 out || test_failed $LINENO $i
	"${TARLZ}" -n$i -tvf "${test3_lz}" > out || test_failed $LINENO $i
	diff -u vlist3 out || test_failed $LINENO $i
done
rm -f out || framework_failure

# test3 reference files for cmp
cat "${testdir}"/rfoo > cfoo || framework_failure
cat "${testdir}"/rbar > cbar || framework_failure
cat "${testdir}"/rbaz > cbaz || framework_failure

# test --list and --extract test3
rm -f foo bar baz || framework_failure
"${TARLZ}" -xf "${test3}" --missing-crc || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
for i in 0 2 6 ; do
  "${TARLZ}" -n$i -xf "${test3_lz}" --missing-crc || test_failed $LINENO $i
  cmp cfoo foo || test_failed $LINENO $i
  cmp cbar bar || test_failed $LINENO $i
  cmp cbaz baz || test_failed $LINENO $i
  rm -f foo bar baz || framework_failure
  "${TARLZ}" -n$i -tvf "${test3_lz}" ./foo ./bar ./baz > out 2> /dev/null ||
	  test_failed $LINENO $i
  diff -u vlist3 out || test_failed $LINENO $i
  rm -f out || framework_failure
  "${TARLZ}" -q -n$i -xf "${test3_lz}" ./foo ./bar ./baz || test_failed $LINENO $i
  cmp cfoo foo || test_failed $LINENO $i
  cmp cbar bar || test_failed $LINENO $i
  cmp cbaz baz || test_failed $LINENO $i
  rm -f foo bar baz || framework_failure
  "${TARLZ}" -n$i -xf "${test3_lz}" foo/ bar// baz/// || test_failed $LINENO $i
  cmp cfoo foo || test_failed $LINENO $i
  cmp cbar bar || test_failed $LINENO $i
  cmp cbaz baz || test_failed $LINENO $i
  rm -f foo bar baz || framework_failure
  "${TARLZ}" -q -n$i -xf "${test3dot_lz}" --missing-crc || test_failed $LINENO $i
  cmp cfoo foo || test_failed $LINENO $i
  cmp cbar bar || test_failed $LINENO $i
  cmp cbaz baz || test_failed $LINENO $i
  rm -f foo bar baz || framework_failure
  "${TARLZ}" -q -n$i -tf "${test3dot_lz}" foo bar baz || test_failed $LINENO $i
  "${TARLZ}" -q -n$i -xf "${test3dot_lz}" foo bar baz || test_failed $LINENO $i
  cmp cfoo foo || test_failed $LINENO $i
  cmp cbar bar || test_failed $LINENO $i
  cmp cbaz baz || test_failed $LINENO $i
  rm -f foo bar baz || framework_failure
done

for i in "${test3dir}" "${test3dir_lz}" ; do
	"${TARLZ}" -q -tf "$i" --missing-crc || test_failed $LINENO "$i"
	"${TARLZ}" -q -xf "$i" --missing-crc || test_failed $LINENO "$i"
	cmp cfoo dir/foo || test_failed $LINENO "$i"
	cmp cbar dir/bar || test_failed $LINENO "$i"
	cmp cbaz dir/baz || test_failed $LINENO "$i"
	rm -rf dir || framework_failure
	"${TARLZ}" -q -tf "$i" dir || test_failed $LINENO "$i"
	"${TARLZ}" -q -xf "$i" dir || test_failed $LINENO "$i"
	cmp cfoo dir/foo || test_failed $LINENO "$i"
	cmp cbar dir/bar || test_failed $LINENO "$i"
	cmp cbaz dir/baz || test_failed $LINENO "$i"
	rm -rf dir || framework_failure
	"${TARLZ}" -q -tf "$i" dir/foo dir/baz || test_failed $LINENO "$i"
	"${TARLZ}" -q -xf "$i" dir/foo dir/baz || test_failed $LINENO "$i"
	cmp cfoo dir/foo || test_failed $LINENO "$i"
	[ ! -e dir/bar ] || test_failed $LINENO "$i"
	cmp cbaz dir/baz || test_failed $LINENO "$i"
	rm -rf dir || framework_failure
done

# test --extract --exclude
"${TARLZ}" -xf "${test3}" --exclude='f*o' --exclude=baz || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f foo bar baz || framework_failure
for i in 0 2 6 ; do
  "${TARLZ}" -n$i -xf "${test3_lz}" --exclude=bar || test_failed $LINENO $i
  cmp cfoo foo || test_failed $LINENO $i
  [ ! -e bar ] || test_failed $LINENO $i
  cmp cbaz baz || test_failed $LINENO $i
  rm -f foo bar baz || framework_failure
  "${TARLZ}" -q -n$i -xf "${test3dir_lz}" --exclude='?ar' || test_failed $LINENO $i
  cmp cfoo dir/foo || test_failed $LINENO $i
  [ ! -e dir/bar ] || test_failed $LINENO $i
  cmp cbaz dir/baz || test_failed $LINENO $i
  rm -rf dir || framework_failure
  "${TARLZ}" -q -n$i -xf "${test3dir_lz}" --exclude=dir/bar || test_failed $LINENO $i
  cmp cfoo dir/foo || test_failed $LINENO $i
  [ ! -e dir/bar ] || test_failed $LINENO $i
  cmp cbaz dir/baz || test_failed $LINENO $i
  rm -rf dir || framework_failure
  "${TARLZ}" -q -n$i -xf "${test3dir_lz}" --exclude=dir || test_failed $LINENO $i
  [ ! -e dir ] || test_failed $LINENO $i
  rm -rf dir || framework_failure
  "${TARLZ}" -q -n$i -xf "${test3dir_lz}" --exclude='dir/*' || test_failed $LINENO $i
  [ ! -e dir ] || test_failed $LINENO $i
  rm -rf dir || framework_failure
  "${TARLZ}" -q -n$i -xf "${test3dir_lz}" --exclude='[bf][ao][orz]' ||
    test_failed $LINENO $i
  [ ! -e dir ] || test_failed $LINENO $i
  rm -rf dir || framework_failure
  "${TARLZ}" -q -n$i -xf "${test3dir_lz}" --exclude='*o' dir/foo ||
    test_failed $LINENO $i
  [ ! -e dir ] || test_failed $LINENO $i
  rm -rf dir || framework_failure
done

# test --list and --extract eof
"${TARLZ}" -tvf "${testdir}"/test3_eof1.tar > out 2> /dev/null
[ $? = 2 ] || test_failed $LINENO
diff -u vlist3 out || test_failed $LINENO
"${TARLZ}" -tvf "${testdir}"/test3_eof2.tar > out || test_failed $LINENO
diff -u vlist3 out || test_failed $LINENO
"${TARLZ}" -q -tf "${testdir}"/test3_eof3.tar || test_failed $LINENO
"${TARLZ}" -tvf "${testdir}"/test3_eof4.tar > out 2> /dev/null
[ $? = 2 ] || test_failed $LINENO
diff -u vlist3 out || test_failed $LINENO
for i in 0 2 6 ; do
	"${TARLZ}" -n$i -tvf "${testdir}"/test3_eof1.tar.lz > out 2> /dev/null
	[ $? = 2 ] || test_failed $LINENO $i
	diff -u vlist3 out || test_failed $LINENO
	"${TARLZ}" -n$i -tvf "${testdir}"/test3_eof2.tar.lz > out ||
		test_failed $LINENO $i
	diff -u vlist3 out || test_failed $LINENO
	"${TARLZ}" -q -n$i -tf "${testdir}"/test3_eof3.tar.lz ||
		test_failed $LINENO $i
	"${TARLZ}" -n$i -tvf "${testdir}"/test3_eof4.tar.lz > out 2> /dev/null
	[ $? = 2 ] || test_failed $LINENO $i
	diff -u vlist3 out || test_failed $LINENO
	"${TARLZ}" -n$i -tvf "${testdir}"/test3_eof5.tar.lz > out 2> /dev/null
	[ $? = 2 ] || test_failed $LINENO $i
	diff -u vlist3 out || test_failed $LINENO
done
rm -f out || framework_failure
#
"${TARLZ}" -q -xf "${testdir}"/test3_eof1.tar
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -xf "${testdir}"/test3_eof2.tar || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -xf "${testdir}"/test3_eof3.tar || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -xf "${testdir}"/test3_eof4.tar
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
#
for i in 0 2 6 ; do
	"${TARLZ}" -q -n$i -xf "${testdir}"/test3_eof1.tar.lz
	[ $? = 2 ] || test_failed $LINENO $i
	cmp cfoo foo || test_failed $LINENO $i
	cmp cbar bar || test_failed $LINENO $i
	cmp cbaz baz || test_failed $LINENO $i
	rm -f foo bar baz || framework_failure
	"${TARLZ}" -n$i -xf "${testdir}"/test3_eof2.tar.lz ||
		test_failed $LINENO $i
	cmp cfoo foo || test_failed $LINENO $i
	cmp cbar bar || test_failed $LINENO $i
	cmp cbaz baz || test_failed $LINENO $i
	rm -f foo bar baz || framework_failure
	"${TARLZ}" -q -n$i -xf "${testdir}"/test3_eof4.tar.lz
	[ $? = 2 ] || test_failed $LINENO $i
	cmp cfoo foo || test_failed $LINENO $i
	cmp cbar bar || test_failed $LINENO $i
	cmp cbaz baz || test_failed $LINENO $i
	rm -f foo bar baz || framework_failure
	"${TARLZ}" -q -n$i -xf "${testdir}"/test3_eof5.tar.lz
	[ $? = 2 ] || test_failed $LINENO $i
	cmp cfoo foo || test_failed $LINENO $i
	cmp cbar bar || test_failed $LINENO $i
	cmp cbaz baz || test_failed $LINENO $i
	rm -f foo bar baz || framework_failure
done
"${TARLZ}" -n0 -xf "${testdir}"/test3_eof3.tar.lz || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO $i
[ ! -e bar ] || test_failed $LINENO $i
[ ! -e baz ] || test_failed $LINENO $i
rm -f foo bar baz || framework_failure

# test --list and --extract tar in tar.lz
for i in "${testdir}"/tar_in_tlz1.tar.lz "${testdir}"/tar_in_tlz2.tar.lz ; do
	for j in 0 2 6 ; do
		"${TARLZ}" -tf "$i" -n$j > out$j ||
			test_failed $LINENO "$i $j"
		"${TARLZ}" -tvf "$i" -n$j > outv$j ||
			test_failed $LINENO "$i $j"
	done
	diff -u out0 out2 || test_failed $LINENO "$i"
	diff -u out0 out6 || test_failed $LINENO "$i"
	diff -u out2 out6 || test_failed $LINENO "$i"
	diff -u outv0 outv2 || test_failed $LINENO "$i"
	diff -u outv0 outv6 || test_failed $LINENO "$i"
	diff -u outv2 outv6 || test_failed $LINENO "$i"
	rm -f out0 out2 out6 outv0 outv2 outv6 || framework_failure
	for j in 0 2 6 ; do
		"${TARLZ}" -xf "$i" -n$j || test_failed $LINENO "$i $j"
		cmp "${in_tar}" test.txt.tar || test_failed $LINENO "$i $j"
		cmp "${test3}" test3.tar || test_failed $LINENO "$i $j"
		rm -f test.txt.tar test3.tar || framework_failure
	done
done

# test --list and --extract with global headers uncompressed
for i in gh1 gh2 gh3 gh4 ; do
	"${TARLZ}" -tf "${testdir}"/test3_${i}.tar > out ||
		test_failed $LINENO $i
	diff -u list3 out || test_failed $LINENO $i
	"${TARLZ}" -tvf "${testdir}"/test3_${i}.tar > out ||
		test_failed $LINENO $i
	diff -u vlist3 out || test_failed $LINENO $i
	"${TARLZ}" -xf "${testdir}"/test3_${i}.tar || test_failed $LINENO $i
	cmp cfoo foo || test_failed $LINENO $i
	cmp cbar bar || test_failed $LINENO $i
	cmp cbaz baz || test_failed $LINENO $i
	rm -f foo bar baz out || framework_failure
done

# test --list and --extract with empty lzip members, global headers and
# extended tar members split among lzip members
for i in em1 em2 em3 em4 em5 em6 gh1 gh2 gh3 gh4 gh5 gh6 sm1 sm2 sm3 sm4 ; do
	for j in 0 2 6 ; do
		"${TARLZ}" -n$j -tf "${testdir}"/test3_${i}.tar.lz > out ||
			test_failed $LINENO "$i $j"
		diff -u list3 out || test_failed $LINENO "$i $j"
		"${TARLZ}" -n$j -tvf "${testdir}"/test3_${i}.tar.lz > out ||
			test_failed $LINENO "$i $j"
		diff -u vlist3 out || test_failed $LINENO "$i $j"
	done
	rm -f out || framework_failure
	for j in 0 2 6 ; do
		"${TARLZ}" -n$j -xf "${testdir}"/test3_${i}.tar.lz ||
			test_failed $LINENO "$i $j"
		cmp cfoo foo || test_failed $LINENO "$i $j"
		cmp cbar bar || test_failed $LINENO "$i $j"
		cmp cbaz baz || test_failed $LINENO "$i $j"
		rm -f foo bar baz || framework_failure
	done
done
rm -f list3 vlist3 || framework_failure

printf "\ntesting --concatenate..."

# test --concatenate compressed
cat "${in}" > out.tar.lz || framework_failure		# invalid tar.lz
"${TARLZ}" -Aqf out.tar.lz "${test3_lz}"
[ $? = 2 ] || test_failed $LINENO
cat "${in_tar_lz}" > out.tar.lz || framework_failure
"${TARLZ}" -Af out.tar.lz "${test3_lz}" || test_failed $LINENO
"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
cmp "${in}" test.txt || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f test.txt foo bar baz || framework_failure
touch aout.tar.lz || framework_failure		# concatenate to empty file
"${TARLZ}" -Aqf aout.tar.lz "${in_tar}"
[ $? = 2 ] || test_failed $LINENO
"${TARLZ}" -Af aout.tar.lz "${in_tar_lz}" "${test3_lz}" || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -Af aout.tar.lz || test_failed $LINENO	# concatenate nothing
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -Aqf aout.tar.lz aout.tar.lz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -Aq "${in_tar_lz}" "${test3}" > aout.tar.lz		# to stdout
[ $? = 2 ] || test_failed $LINENO
cmp "${in_tar_lz}" aout.tar.lz || test_failed $LINENO
"${TARLZ}" -A "${in_tar_lz}" "${test3_lz}" > aout.tar.lz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
cat "${eof_lz}" > aout.tar.lz || framework_failure
"${TARLZ}" -Aqf aout.tar.lz "${in_tar}"		# concatenate to empty archive
[ $? = 2 ] || test_failed $LINENO
"${TARLZ}" -Af aout.tar.lz "${in_tar_lz}" "${test3_lz}" || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
cat "${in_tar_lz}" > aout.tar.lz || framework_failure
"${TARLZ}" -Aqf aout.tar.lz "${test3_lz}" "${test3}"
[ $? = 2 ] || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
rm -f aout.tar.lz || framework_failure
touch aout.tar.lz || framework_failure			# --exclude
"${TARLZ}" -Af aout.tar.lz "${in_tar_lz}" "${test3_lz}" --exclude 'test3*' ||
	test_failed $LINENO
"${TARLZ}" -Af aout.tar.lz "${in_tar_lz}" "${test3_lz}" --exclude '*txt*' ||
	test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
rm -f out.tar.lz aout.tar.lz || framework_failure

# test --concatenate uncompressed
cat "${in}" > out.tar || framework_failure		# invalid tar
"${TARLZ}" -Aqf out.tar "${test3}"
[ $? = 2 ] || test_failed $LINENO
cat "${in_tar}" > out.tar || framework_failure
"${TARLZ}" -Af out.tar "${test3}" || test_failed $LINENO
"${TARLZ}" -xf out.tar || test_failed $LINENO
cmp "${in}" test.txt || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f test.txt foo bar baz || framework_failure
touch aout.tar || framework_failure		# concatenate to empty file
"${TARLZ}" -Aqf aout.tar "${in_tar_lz}"
[ $? = 2 ] || test_failed $LINENO
"${TARLZ}" -Af aout.tar "${in_tar}" "${test3}" || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" -Af aout.tar || test_failed $LINENO	# concatenate nothing
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" -Aqf aout.tar aout.tar || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" -Aq "${in_tar}" "${test3_lz}" > aout.tar		# to stdout
[ $? = 2 ] || test_failed $LINENO
cmp "${in_tar}" aout.tar || test_failed $LINENO
"${TARLZ}" -A "${in_tar}" "${test3}" > aout.tar || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
cat "${eof}" > aout.tar || framework_failure	# concatenate to empty archive
"${TARLZ}" -Aqf aout.tar "${in_tar_lz}"
[ $? = 2 ] || test_failed $LINENO
"${TARLZ}" -Af aout.tar "${in_tar}" "${test3}" || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
cat "${in_tar}" > aout.tar || framework_failure
"${TARLZ}" -Aqf aout.tar "${test3}" "${test3_lz}"
[ $? = 2 ] || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
rm -f aout.tar || framework_failure
touch aout.tar || framework_failure			# --exclude
"${TARLZ}" -Af aout.tar "${test3}" "${in_tar}" --exclude 'test3*' ||
	test_failed $LINENO
"${TARLZ}" -Af aout.tar "${test3}" "${in_tar}" --exclude '*txt*' ||
	test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
rm -f out.tar aout.tar || framework_failure

printf "\ntesting --create..."

# test --create
cat "${in}" > test.txt || framework_failure
"${TARLZ}" --warn-newer -0 -cf out.tar.lz test.txt || test_failed $LINENO
rm -f test.txt || framework_failure
"${TARLZ}" -xf out.tar.lz --missing-crc || test_failed $LINENO
cmp "${in}" test.txt || test_failed $LINENO
cat "${in}" > test.txt || framework_failure
"${TARLZ}" --warn-newer --uncompressed -cf out.tar test.txt || test_failed $LINENO
rm -f test.txt || framework_failure
"${TARLZ}" -xf out.tar --missing-crc || test_failed $LINENO
cmp "${in}" test.txt || test_failed $LINENO
rm -f test.txt out.tar out.tar.lz || framework_failure

cat cfoo > foo || framework_failure
rm -f bar || framework_failure
cat cbaz > baz || framework_failure
"${TARLZ}" -0 -q -cf out.tar.lz foo bar baz
[ $? = 1 ] || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -xf out.tar.lz --missing-crc || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -xf out.tar.lz bar
[ $? = 1 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f out.tar.lz || framework_failure

cat cfoo > foo || framework_failure
cat cbar > bar || framework_failure
cat cbaz > baz || framework_failure
"${TARLZ}" -0 -cf out.tar.lz foo bar baz --out-slots=1 || test_failed $LINENO
"${TARLZ}" -0 -q -cf aout.tar.lz foo bar aout.tar.lz baz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO	# test reproducible
rm -f aout.tar.lz || framework_failure
#
"${TARLZ}" -0 -cf aout.tar.lz foo bar baz -C / || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
rm -f aout.tar.lz || framework_failure
"${TARLZ}" -0 -C / -cf aout.tar.lz -C "${objdir}"/tmp foo bar baz ||
	test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
rm -f aout.tar.lz || framework_failure
"${TARLZ}" --asolid -0 -cf aout.tar.lz foo bar baz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
rm -f aout.tar.lz || framework_failure
"${TARLZ}" -0 -q -cf aout.tar.lz foo/ ./bar ./baz/ || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
rm -f aout.tar.lz || framework_failure
mkdir dir1 || framework_failure
"${TARLZ}" -C dir1 -xf out.tar.lz || test_failed $LINENO
cmp cfoo dir1/foo || test_failed $LINENO
cmp cbar dir1/bar || test_failed $LINENO
cmp cbaz dir1/baz || test_failed $LINENO
rm -f aout.tar.lz foo bar baz || framework_failure
"${TARLZ}" -C dir1 -0 -cf aout.tar.lz foo bar baz || test_failed $LINENO
"${TARLZ}" -xf aout.tar.lz || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f aout.tar.lz foo bar baz || framework_failure
"${TARLZ}" -C dir1 -0 -c foo bar baz | "${TARLZ}" -x || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f dir1/foo dir1/bar dir1/baz || framework_failure
"${TARLZ}" -0 -c foo bar baz | "${TARLZ}" -C dir1 -x || test_failed $LINENO
cmp cfoo dir1/foo || test_failed $LINENO
cmp cbar dir1/bar || test_failed $LINENO
cmp cbaz dir1/baz || test_failed $LINENO
rm -f dir1/foo dir1/bar dir1/baz || framework_failure
"${TARLZ}" -0 -c foo bar baz | "${TARLZ}" -x foo bar baz -C dir1 ||
	test_failed $LINENO
cmp cfoo dir1/foo || test_failed $LINENO
cmp cbar dir1/bar || test_failed $LINENO
cmp cbaz dir1/baz || test_failed $LINENO
rm -f foo dir1/bar baz || framework_failure
"${TARLZ}" -0 -cf aout.tar.lz -C dir1 foo -C .. bar -C dir1 baz ||
	test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -0 -cf aout.tar.lz dir1/foo dir1/baz || test_failed $LINENO
rm -rf dir1 bar || framework_failure
"${TARLZ}" -xf aout.tar.lz dir1 || test_failed $LINENO
cmp cfoo dir1/foo || test_failed $LINENO
cmp cbaz dir1/baz || test_failed $LINENO
rm -rf dir1 || framework_failure
rm -f out.tar.lz aout.tar.lz || framework_failure

# test --create --exclude
cat cfoo > foo || framework_failure
cat cbar > bar || framework_failure
cat cbaz > baz || framework_failure
"${TARLZ}" -0 -cf out.tar.lz foo bar baz --exclude 'ba?' || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f out.tar.lz foo bar baz || framework_failure
cat cfoo > foo || framework_failure
cat cbar > bar || framework_failure
cat cbaz > baz || framework_failure
"${TARLZ}" --un -cf out.tar foo bar baz --exclude 'ba*' || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -xf out.tar || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f out.tar foo bar baz || framework_failure

printf "\ntesting --diff..."

# test --diff
"${TARLZ}" -xf "${test3_lz}" || test_failed $LINENO
"${TARLZ}" --uncompressed -cf out.tar foo || test_failed $LINENO
"${TARLZ}" --uncompressed -cf aout.tar foo --anonymous || test_failed $LINENO
if cmp out.tar aout.tar > /dev/null ; then
  printf "\nwarning: '--diff' test can't be run as root.\n"
else
  for i in 0 2 6 ; do
    "${TARLZ}" -n$i -xf "${test3_lz}" || test_failed $LINENO
    "${TARLZ}" -n$i -df "${test3_lz}" > out$i
    [ $? = 1 ] || test_failed $LINENO $i
    "${TARLZ}" -n$i -df "${test3_lz}" --ignore-ids || test_failed $LINENO $i
    "${TARLZ}" -n$i -df "${test3_lz}" --exclude '*' || test_failed $LINENO $i
    "${TARLZ}" -n$i -df "${in_tar_lz}" --exclude '*' || test_failed $LINENO $i
    rm -f bar || framework_failure
    "${TARLZ}" -n$i -df "${test3_lz}" foo baz --ignore-ids ||
      test_failed $LINENO $i
    "${TARLZ}" -n$i -df "${test3_lz}" --exclude bar --ignore-ids ||
      test_failed $LINENO $i
    rm -f foo baz || framework_failure
    "${TARLZ}" -q -n$i -xf "${test3dir_lz}" || test_failed $LINENO $i
    "${TARLZ}" -q -n$i -df "${test3dir_lz}" --ignore-ids ||
      test_failed $LINENO $i
    "${TARLZ}" -q -n$i -df "${test3dir_lz}" dir --ignore-ids ||
      test_failed $LINENO $i
    "${TARLZ}" -n$i -df "${test3_lz}" --ignore-ids -C dir ||
      test_failed $LINENO $i
    rm -rf dir || framework_failure
  done
  cmp out0 out2 || test_failed $LINENO
  cmp out0 out6 || test_failed $LINENO
  rm -f out0 out2 out6 || framework_failure
fi
rm -f out.tar aout.tar foo bar baz || framework_failure

printf "\ntesting --delete..."

# test --delete
for e in "" .lz ; do
  "${TARLZ}" -A "${in_tar}"$e "${test3}"$e > out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -f out.tar$e --delete test.txt || test_failed $LINENO $e
  cmp "${test3}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -f out.tar$e --delete || test_failed $LINENO $e	# delete nothing
  cmp "${test3}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -qf out.tar$e --delete nx_file
  [ $? = 1 ] || test_failed $LINENO $e
  cmp "${test3}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${test3dir}"$e > out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -qf out.tar$e --delete test.txt || test_failed $LINENO $e
  cmp "${test3dir}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${test3dir}"$e > out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -qf out.tar$e --delete dir || test_failed $LINENO $e
  cmp "${in_tar}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${test3dir}"$e > out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -qf out.tar$e --del dir/foo dir/bar dir/baz || test_failed $LINENO $e
  cmp "${in_tar}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${test3dir}"$e > out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -qf out.tar$e --del dir/foo dir/baz || test_failed $LINENO $e
  cmp "${in_tar}"$e out.tar$e > /dev/null && test_failed $LINENO $e
  "${TARLZ}" -qf out.tar$e --del dir/bar || test_failed $LINENO $e
  cmp "${in_tar}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${test3}"$e > out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -f out.tar$e --delete foo bar baz || test_failed $LINENO $e
  cmp "${in_tar}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${test3}"$e > out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -f out.tar$e --del test.txt foo bar baz || test_failed $LINENO $e
  cmp "${eof}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${test3}"$e > out.tar$e || test_failed $LINENO $e
  for i in test.txt foo bar baz ; do
    "${TARLZ}" -f out.tar$e --delete $i || test_failed $LINENO "$e $i"
  done
  cmp "${eof}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${test3}"$e > out.tar$e || test_failed $LINENO $e
  for i in baz bar foo test.txt ; do
    "${TARLZ}" -f out.tar$e --delete $i || test_failed $LINENO "$e $i"
  done
  cmp "${eof}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${test3}"$e > out.tar$e || test_failed $LINENO $e
  for i in foo bar test.txt baz ; do
    "${TARLZ}" -f out.tar$e --delete $i || test_failed $LINENO "$e $i"
  done
  cmp "${eof}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -A "${in_tar}"$e "${t155}"$e "${test3}"$e > out.tar$e ||
    test_failed $LINENO $e
  "${TARLZ}" -f out.tar$e --del baz foo test.txt bar || test_failed $LINENO $e
  cmp "${t155}"$e out.tar$e || test_failed $LINENO $e
  "${TARLZ}" -f out.tar$e --delete link || test_failed $LINENO $e
  "${TARLZ}" -q -tf out.tar$e || test_failed $LINENO
  cmp "${t155}"$e out.tar$e > /dev/null && test_failed $LINENO $e
  rm -f out.tar$e || framework_failure
done

# test --delete individual member after collective member
cat cfoo > foo || framework_failure
cat cbar > bar || framework_failure
cat cbaz > baz || framework_failure
cat "${in}" > test.txt || framework_failure
"${TARLZ}" -0 -cf out.tar.lz foo bar baz --asolid || test_failed $LINENO
"${TARLZ}" -0 -rf out.tar.lz test.txt || test_failed $LINENO
rm -f foo bar baz test.txt || framework_failure
for i in foo bar baz ; do
	"${TARLZ}" -qf out.tar.lz --delete $i
	[ $? = 2 ] || test_failed $LINENO
done
"${TARLZ}" -f out.tar.lz --delete test.txt || test_failed $LINENO
"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
[ ! -e test.txt ] || test_failed $LINENO
rm -f out.tar.lz foo bar baz test.txt || framework_failure

# test --delete with empty lzip member, global header
for i in 1 2 3 4 5 6 ; do
	cat "${testdir}"/test3_em${i}.tar.lz > out.tar.lz || framework_failure
	for j in foo bar baz ; do
		"${TARLZ}" -f out.tar.lz --delete $j || test_failed $LINENO "$i $j"
	done
	rm -f out.tar.lz || framework_failure
done
cat "${testdir}"/test3_gh5.tar.lz > out.tar.lz || framework_failure
for i in foo bar baz ; do
	"${TARLZ}" -f out.tar.lz --delete $i || test_failed $LINENO $i
done
rm -f out.tar.lz || framework_failure
for i in 1 2 3 4 ; do
	cat "${testdir}"/test3_gh${i}.tar > out.tar || framework_failure
	for j in foo bar baz ; do
		"${TARLZ}" -f out.tar --delete $j || test_failed $LINENO "$i $j"
	done
	rm -f out.tar || framework_failure
done

printf "\ntesting --dereference..."

# test --dereference
touch dummy_file || framework_failure
if ln dummy_file dummy_link 2> /dev/null &&
   ln -s dummy_file dummy_slink 2> /dev/null ; then
	ln_works=yes
else
	printf "\nwarning: skipping link test: 'ln' does not work on your system.\n"
fi
rm -f dummy_slink dummy_link dummy_file || framework_failure
#
if [ "${ln_works}" = yes ] ; then
	mkdir dir || framework_failure
	cat cfoo > dir/foo || framework_failure
	cat cbar > dir/bar || framework_failure
	cat cbaz > dir/baz || framework_failure
	ln -s dir dir_link || framework_failure
	"${TARLZ}" -0 -cf out1 dir_link || test_failed $LINENO
	"${TARLZ}" --un -cf out2 dir_link || test_failed $LINENO
	"${TARLZ}" -0 -n0 -cf out3 dir_link || test_failed $LINENO
	"${TARLZ}" -0 -h -cf hout1 dir_link || test_failed $LINENO
	"${TARLZ}" --un -h -cf hout2 dir_link || test_failed $LINENO
	"${TARLZ}" -0 -n0 -h -cf hout3 dir_link || test_failed $LINENO
	rm -rf dir dir_link || framework_failure
	for i in 1 2 3 ; do
		"${TARLZ}" -xf out$i --exclude='dir_link/*' dir_link ||
			test_failed $LINENO $i	# Cygwin stores dir_link/*
		[ -h dir_link ] || test_failed $LINENO $i
		"${TARLZ}" -q -tf out$i dir_link/foo && cyg_symlink $LINENO $i
		"${TARLZ}" -q -tf out$i dir_link/bar && cyg_symlink $LINENO $i
		"${TARLZ}" -q -tf out$i dir_link/baz && cyg_symlink $LINENO $i
		rm -rf dir_link out$i || framework_failure
		"${TARLZ}" -xf hout$i || test_failed $LINENO $i
		[ -d dir_link ] || test_failed $LINENO $i
		cmp cfoo dir_link/foo || test_failed $LINENO $i
		cmp cbar dir_link/bar || test_failed $LINENO $i
		cmp cbaz dir_link/baz || test_failed $LINENO $i
		rm -rf dir_link hout$i || framework_failure
	done
fi

printf "\ntesting --append..."

# test --append compressed
cat cfoo > foo || framework_failure
cat cbar > bar || framework_failure
cat cbaz > baz || framework_failure
"${TARLZ}" -0 -cf out.tar.lz foo bar baz --out-slots=1024 || test_failed $LINENO
"${TARLZ}" -0 -cf nout.tar.lz foo bar baz --no-solid || test_failed $LINENO
"${TARLZ}" -0 -cf aout.tar.lz foo || test_failed $LINENO
"${TARLZ}" -0 -rf aout.tar.lz bar baz --no-solid || test_failed $LINENO
cmp nout.tar.lz aout.tar.lz || test_failed $LINENO
rm -f nout.tar.lz aout.tar.lz || framework_failure
touch aout.tar || framework_failure		# wrong extension empty file
"${TARLZ}" -0 -rf aout.tar foo bar baz || test_failed $LINENO
cmp out.tar.lz aout.tar || test_failed $LINENO
rm -f aout.tar || framework_failure
touch aout.tar.lz || framework_failure		# append to empty file
"${TARLZ}" -0 -rf aout.tar.lz foo bar baz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -0 -rf aout.tar.lz || test_failed $LINENO	# append nothing
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -0 -rf aout.tar.lz -C nx_dir || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -0 -q -rf aout.tar.lz nx_file
[ $? = 1 ] || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -0 -q -rf aout.tar.lz aout.tar.lz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" -0 -r foo bar baz > aout.tar.lz || test_failed $LINENO  # to stdout
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" --un -q -rf aout.tar.lz foo bar baz	# wrong extension archive
[ $? = 2 ] || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
cat "${eof_lz}" > aout.tar.lz || framework_failure  # append to empty archive
"${TARLZ}" -0 -rf aout.tar.lz foo bar baz || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
"${TARLZ}" --un -q -rf aout.tar.lz foo bar baz	# wrong extension empty archive
[ $? = 2 ] || test_failed $LINENO
cmp out.tar.lz aout.tar.lz || test_failed $LINENO
rm -f out.tar.lz aout.tar.lz || framework_failure

# test --append --uncompressed
"${TARLZ}" --un -cf out.tar foo bar baz || test_failed $LINENO
"${TARLZ}" --un -cf aout.tar foo || test_failed $LINENO
"${TARLZ}" --un -rf aout.tar foo bar baz --exclude foo || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
rm -f aout.tar || framework_failure
touch aout.tar.lz empty || framework_failure	# wrong extension empty file
"${TARLZ}" --un -q -rf aout.tar.lz foo bar baz
[ $? = 2 ] || test_failed $LINENO
cmp aout.tar.lz empty || test_failed $LINENO
rm -f aout.tar.lz empty || framework_failure
touch aout.tar || framework_failure		# append to empty file
"${TARLZ}" --un -rf aout.tar foo bar baz || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" --un -rf aout.tar || test_failed $LINENO	# append nothing
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" --un -rf aout.tar -C nx_dir || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" --un -q -rf aout.tar nx_file
[ $? = 1 ] || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" --un -q -rf aout.tar aout.tar || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" --un -r foo bar baz > aout.tar || test_failed $LINENO  # to stdout
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" -0 -q -rf aout.tar foo bar baz	# wrong extension archive
[ $? = 2 ] || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
cat "${eof}" > aout.tar || framework_failure	# append to empty archive
"${TARLZ}" --un -rf aout.tar foo bar baz || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
"${TARLZ}" -0 -q -rf aout.tar foo bar baz	# wrong extension empty archive
[ $? = 2 ] || test_failed $LINENO
cmp out.tar aout.tar || test_failed $LINENO
rm -f out.tar aout.tar || framework_failure

# test --append to solid archive
"${TARLZ}" --solid -q -0 -cf out.tar.lz "${in}" foo bar || test_failed $LINENO
"${TARLZ}" -q -tf out.tar.lz || test_failed $LINENO	# compressed seekable
cat out.tar.lz > aout.tar.lz || framework_failure
for i in --asolid --bsolid --dsolid --solid -0 ; do
	"${TARLZ}" $i -q -rf out.tar.lz baz
	[ $? = 2 ] || test_failed $LINENO $i
	cmp out.tar.lz aout.tar.lz || test_failed $LINENO $i
done
rm -f out.tar.lz aout.tar.lz || framework_failure
for i in --asolid --bsolid --dsolid -0 ; do
	for j in --asolid --bsolid --dsolid --solid -0 ; do
		"${TARLZ}" $i -0 -cf out.tar.lz foo ||
			test_failed $LINENO "$i $j"
		"${TARLZ}" $j -0 -rf out.tar.lz bar baz ||
			test_failed $LINENO "$i $j"
		rm -f foo bar baz || framework_failure
		"${TARLZ}" -xf out.tar.lz || test_failed $LINENO "$i $j"
		cmp cfoo foo || test_failed $LINENO "$i $j"
		cmp cbar bar || test_failed $LINENO "$i $j"
		cmp cbaz baz || test_failed $LINENO "$i $j"
		rm -f out.tar.lz || framework_failure
	done
done
rm -f foo bar baz || framework_failure

printf "\ntesting dirs and links..."

# test -c -d -x on directories and links
mkdir dir1 || framework_failure
"${TARLZ}" -0 -cf out.tar.lz dir1 || test_failed $LINENO
rmdir dir1 || framework_failure
"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
[ -d dir1 ] || test_failed $LINENO
rmdir dir1
rm -f out.tar.lz || framework_failure
mkdir dir1 || framework_failure
"${TARLZ}" --uncompressed -cf out.tar dir1 || test_failed $LINENO
rmdir dir1 || framework_failure
"${TARLZ}" -xf out.tar || test_failed $LINENO
[ -d dir1 ] || test_failed $LINENO
rmdir dir1
rm -f out.tar || framework_failure

if [ "${ln_works}" = yes ] ; then
	name_100=name_100_bytes_long_nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
	path_100=dir1/dir2/dir3/path_100_bytes_long_nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
	path_106=dir1/dir2/dir3/path_longer_than_100_bytes_nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
	mkdir dir1 || framework_failure
	mkdir dir1/dir2 || framework_failure
	mkdir dir1/dir2/dir3 || framework_failure
	cat "${in}" > dir1/dir2/dir3/in || framework_failure
	ln dir1/dir2/dir3/in dir1/dir2/dir3/"${name_100}" || framework_failure
	ln dir1/dir2/dir3/in "${path_100}" || framework_failure
	ln dir1/dir2/dir3/in "${path_106}" || framework_failure
	ln -s dir2/ dir1/dir2_link || framework_failure
	ln -s in dir1/dir2/dir3/link || framework_failure
	ln -s "${name_100}" dir1/dir2/dir3/link_100 || framework_failure
	"${TARLZ}" -0 -cf out.tar.lz dir1 || test_failed $LINENO
	"${TARLZ}" -df out.tar.lz || test_failed $LINENO
	rm -rf dir1 || framework_failure
	"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
	"${TARLZ}" -df out.tar.lz || test_failed $LINENO
	cmp "${in}" dir1/dir2/dir3/in || test_failed $LINENO
	cmp "${in}" dir1/dir2_link/dir3/in || test_failed $LINENO
	cmp "${in}" dir1/dir2/dir3/"${name_100}" || test_failed $LINENO
	cmp "${in}" "${path_100}" || test_failed $LINENO
	cmp "${in}" "${path_106}" || test_failed $LINENO
	cmp "${in}" dir1/dir2/dir3/link || test_failed $LINENO
	cmp "${in}" dir1/dir2/dir3/link_100 || test_failed $LINENO
	rm -f dir1/dir2/dir3/in || framework_failure
	cmp "${in}" dir1/dir2/dir3/link 2> /dev/null && test_failed $LINENO
	cmp "${in}" dir1/dir2/dir3/link_100 || test_failed $LINENO
	"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
	rm -f out.tar.lz || framework_failure
	cmp "${in}" dir1/dir2/dir3/in || test_failed $LINENO
	cmp "${in}" dir1/dir2/dir3/link || test_failed $LINENO
	"${TARLZ}" -0 -q -c ../tmp/dir1 | "${TARLZ}" -x || test_failed $LINENO
	diff -ru tmp/dir1 dir1 || test_failed $LINENO
	rm -rf tmp dir1 || framework_failure
	"${TARLZ}" -xf "${testdir}"/ts_in_link.tar.lz || test_failed $LINENO
	"${TARLZ}" -df "${testdir}"/ts_in_link.tar.lz --ignore-ids ||
		test_failed $LINENO
	rm -f link1 link2 link3 link4 || framework_failure
fi

printf "\ntesting long names..."

"${TARLZ}" -q -tf "${t155}" || test_failed $LINENO
"${TARLZ}" -q -tf "${t155_lz}" || test_failed $LINENO
if [ "${ln_works}" = yes ] ; then
	mkdir dir1 || framework_failure
	"${TARLZ}" -C dir1 -xf "${t155}" || test_failed $LINENO
	mkdir dir2 || framework_failure
	"${TARLZ}" -C dir2 -xf "${t155_lz}" || test_failed $LINENO
	diff -ru dir1 dir2 || test_failed $LINENO
	"${TARLZ}" -cf out.tar.lz dir2 || test_failed $LINENO
	rm -rf dir2 || framework_failure
	"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
	diff -ru dir1 dir2 || test_failed $LINENO
	rmdir dir2 2> /dev/null && test_failed $LINENO
	rmdir dir1 2> /dev/null && test_failed $LINENO
	rm -rf out.tar.lz dir2 dir1 || framework_failure
fi

"${TARLZ}" -tvf "${testdir}"/ug32chars.tar.lz | grep -q \
	-e very_long_owner_name_of_32_chars/very_long_group_name_of_32_chars ||
	test_failed $LINENO
"${TARLZ}" -tvf "${testdir}"/ug32chars.tar.lz | grep -q \
	-e very_long_owner_name_of_32_charsvery_long_group_name_of_32_chars &&
	test_failed $LINENO
"${TARLZ}" -tvf "${testdir}"/ug32chars.tar.lz | grep -q \
	-e very_long_group_name_of_32_chars/very_long_group_name_of_32_chars &&
	test_failed $LINENO
"${TARLZ}" -xf "${testdir}"/ug32chars.tar.lz || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
rm -f foo || framework_failure
"${TARLZ}" -tvf "${testdir}"/ug32767.tar.lz | grep -q -e 32767/32767 ||
	test_failed $LINENO
"${TARLZ}" -xf "${testdir}"/ug32767.tar.lz || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
rm -f foo || framework_failure

printf "\ntesting --compress..."

cat cfoo > foo || framework_failure
cat cbar > bar || framework_failure
cat cbaz > baz || framework_failure
cat "${in}" > test.txt || framework_failure
"${TARLZ}" --un -cf out.tar test.txt foo bar baz test.txt || test_failed $LINENO
"${TARLZ}" --un -cf out3.tar foo bar baz || test_failed $LINENO
cat out.tar > outz.tar || framework_failure
cat out3.tar > out3z.tar || framework_failure
#
"${TARLZ}" -0 -z outz.tar out3z.tar || test_failed $LINENO
"${TARLZ}" -q -tf outz.tar.lz || test_failed $LINENO
"${TARLZ}" -q -tf out3z.tar.lz || test_failed $LINENO
cat outz.tar.lz > out || test_failed $LINENO
cat out3z.tar.lz > out3 || test_failed $LINENO
rm -f out3z.tar.lz || framework_failure
"${TARLZ}" -q -0 -z outz.tar out3z.tar
[ $? = 1 ] || test_failed $LINENO
cmp out outz.tar.lz || test_failed $LINENO
cmp out3 out3z.tar.lz || test_failed $LINENO
if [ "${ln_works}" = yes ] ; then
	ln -s outz.tar loutz.tar || framework_failure
	"${TARLZ}" -0 -z loutz.tar || test_failed $LINENO
	cmp loutz.tar.lz outz.tar.lz || test_failed $LINENO
	rm -f loutz.tar.lz loutz.tar || framework_failure
fi
rm -f out out3 outz.tar.lz out3z.tar.lz || framework_failure
#
for i in --solid --no-solid ; do
  "${TARLZ}" -0 -n0 $i -cf out.tar.lz test.txt foo bar baz test.txt || test_failed $LINENO $i
  "${TARLZ}" -0 -z -o - $i out.tar | cmp out.tar.lz - || test_failed $LINENO $i
  "${TARLZ}" -0 -n0 $i -cf out3.tar.lz foo bar baz || test_failed $LINENO $i
  "${TARLZ}" -0 -z -o - $i out3.tar | cmp out3.tar.lz - || test_failed $LINENO $i
  "${TARLZ}" -0 -z $i outz.tar out3z.tar || test_failed $LINENO $i
  cmp out.tar.lz outz.tar.lz || test_failed $LINENO $i
  cmp out3.tar.lz out3z.tar.lz || test_failed $LINENO $i
  rm -f outz.tar.lz out3z.tar.lz || framework_failure
done
#
"${TARLZ}" -0 -B8KiB -n0 --bsolid -cf out.tar.lz test.txt foo bar baz test.txt || test_failed $LINENO
"${TARLZ}" -0 -B8KiB -z -o - --bsolid out.tar | cmp out.tar.lz - || test_failed $LINENO
"${TARLZ}" -0 -B8KiB -z -o out --bsolid out.tar || test_failed $LINENO
cmp out.tar.lz out || test_failed $LINENO
"${TARLZ}" -0 -B8KiB -z --bsolid outz.tar || test_failed $LINENO
cmp out.tar.lz outz.tar.lz || test_failed $LINENO
rm -f out outz.tar.lz || framework_failure
#
"${TARLZ}" -0 -n0 --asolid -cf out.tar.lz test.txt foo bar baz test.txt || test_failed $LINENO
"${TARLZ}" -0 -n0 --asolid -cf out3.tar.lz foo bar baz || test_failed $LINENO
for i in --asolid --bsolid --dsolid ; do
  cat out.tar | "${TARLZ}" -0 -z $i | cmp out.tar.lz - || test_failed $LINENO $i
  "${TARLZ}" -0 -z -o out $i out.tar || test_failed $LINENO $i
  cmp out.tar.lz out || test_failed $LINENO $i
  "${TARLZ}" -0 -z $i outz.tar out3z.tar || test_failed $LINENO $i
  cmp out.tar.lz outz.tar.lz || test_failed $LINENO $i
  cmp out3.tar.lz out3z.tar.lz || test_failed $LINENO $i
  rm -f out outz.tar.lz out3z.tar.lz || framework_failure
done
rm -f foo bar baz test.txt out.tar.lz out3.tar.lz out.tar outz.tar out3z.tar ||
  framework_failure

printf "\ntesting bad input..."

# test --extract ".."
mkdir dir1 || framework_failure
cd dir1 || framework_failure
"${TARLZ}" -q -xf "${testdir}"/dotdot1.tar.lz || test_failed $LINENO
[ ! -e ../dir ] || test_failed $LINENO
"${TARLZ}" -q -xf "${testdir}"/dotdot2.tar.lz || test_failed $LINENO
[ ! -e ../dir ] || test_failed $LINENO
"${TARLZ}" -q -xf "${testdir}"/dotdot3.tar.lz || test_failed $LINENO
[ ! -e dir ] || test_failed $LINENO
"${TARLZ}" -q -xf "${testdir}"/dotdot4.tar.lz || test_failed $LINENO
[ ! -e dir ] || test_failed $LINENO
"${TARLZ}" -q -xf "${testdir}"/dotdot5.tar.lz || test_failed $LINENO
[ ! -e dir ] || test_failed $LINENO
cd .. || framework_failure
rm -rf dir1 || framework_failure

# test --list and --extract truncated tar
dd if="${in_tar}" of=truncated.tar bs=1000 count=1 2> /dev/null
"${TARLZ}" -q -tf truncated.tar > /dev/null
[ $? = 2 ] || test_failed $LINENO
"${TARLZ}" -q -xf truncated.tar
[ $? = 2 ] || test_failed $LINENO
[ ! -e test.txt ] || test_failed $LINENO
rm -f truncated.tar || framework_failure

# test --delete with split 'bar' tar member
for i in 1 2 3 4 ; do
	cat "${testdir}"/test3_sm${i}.tar.lz > out.tar.lz || framework_failure
	for j in bar baz ; do
		"${TARLZ}" -q -f out.tar.lz --delete $j
		[ $? = 2 ] || test_failed $LINENO "$i $j"
	done
	cmp "${testdir}"/test3_sm${i}.tar.lz out.tar.lz || test_failed $LINENO $i
	"${TARLZ}" -q -f out.tar.lz --delete foo
	[ $? = 2 ] || test_failed $LINENO $i
	"${TARLZ}" -xf out.tar.lz || test_failed $LINENO
	[ ! -e foo ] || test_failed $LINENO
	cmp cbar bar || test_failed $LINENO
	cmp cbaz baz || test_failed $LINENO
	rm -f out.tar.lz foo bar baz || framework_failure
done

# test --list and --extract format violations
if [ "${ln_works}" = yes ] ; then
	mkdir dir1 || framework_failure
	"${TARLZ}" -C dir1 -xf "${t155}" || test_failed $LINENO
fi
for i in 1 2 3 ; do
  "${TARLZ}" -q -tf "${testdir}"/t155_fv${i}.tar
  [ $? = 2 ] || test_failed $LINENO $i
  "${TARLZ}" -q -tf "${testdir}"/t155_fv${i}.tar --permissive ||
    test_failed $LINENO $i
  if [ "${ln_works}" = yes ] ; then
    mkdir dir2 || framework_failure
    "${TARLZ}" -C dir2 -xf "${testdir}"/t155_fv${i}.tar --permissive ||
      test_failed $LINENO $i
    diff -ru dir1 dir2 || test_failed $LINENO $i
    rm -rf dir2 || framework_failure
  fi
done
for i in 1 2 3 4 5 6 ; do
  "${TARLZ}" -q -tf "${testdir}"/t155_fv${i}.tar.lz
  [ $? = 2 ] || test_failed $LINENO $i
  "${TARLZ}" -q -tf "${testdir}"/t155_fv${i}.tar.lz --permissive ||
    test_failed $LINENO $i
  if [ "${ln_works}" = yes ] ; then
    mkdir dir2 || framework_failure
    "${TARLZ}" -n4 -C dir2 -xf "${testdir}"/t155_fv${i}.tar.lz --permissive ||
      test_failed $LINENO $i
    diff -ru dir1 dir2 || test_failed $LINENO $i
    rm -rf dir2 || framework_failure
  fi
done
if [ "${ln_works}" = yes ] ; then rm -rf dir1 || framework_failure ; fi

for i in "${testdir}"/test3_nn.tar "${testdir}"/test3_nn.tar.lz ; do
  "${TARLZ}" -q -n0 -tf "$i" || test_failed $LINENO $i
  "${TARLZ}" -q -n4 -tf "$i" || test_failed $LINENO $i
  "${TARLZ}" -q -n0 -xf "$i" || test_failed $LINENO $i
  "${TARLZ}" -n0 -df "$i" --ignore-ids || test_failed $LINENO $i
  cmp cfoo foo || test_failed $LINENO $i
  [ ! -e bar ] || test_failed $LINENO $i
  cmp cbaz baz || test_failed $LINENO $i
  rm -f foo bar baz || framework_failure
  "${TARLZ}" -q -n4 -xf "$i" || test_failed $LINENO $i
  "${TARLZ}" -n4 -df "$i" --ignore-ids || test_failed $LINENO $i
  cmp cfoo foo || test_failed $LINENO $i
  [ ! -e bar ] || test_failed $LINENO $i
  cmp cbaz baz || test_failed $LINENO $i
  rm -f foo bar baz || framework_failure
done

printf "\ntesting --keep-damaged..."

# test --extract and --keep-damaged compressed
rm -f test.txt || framework_failure
for i in "${inbad1}" "${inbad2}" ; do
	"${TARLZ}" -q -xf "${i}.tar.lz"
	[ $? = 2 ] || test_failed $LINENO "$i"
	[ ! -e test.txt ] || test_failed $LINENO "$i"
	rm -f test.txt || framework_failure
	"${TARLZ}" -q -n0 -xf "${i}.tar.lz" --keep-damaged
	[ $? = 2 ] || test_failed $LINENO "$i"
	[ -e test.txt ] || test_failed $LINENO "$i"
	cmp "$i" test.txt 2> /dev/null || test_failed $LINENO $i
	rm -f test.txt || framework_failure
done
#
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -n0 -xf "${bad1_lz}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -n0 -xf "${bad2_lz}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -n0 -xf "${bad3_lz}"
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -n0 -xf "${bad3_lz}" --keep-damaged
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar 2> /dev/null || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -n0 -xf "${bad4_lz}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -n0 -xf "${bad4_lz}" --keep-damaged
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
cmp cbar bar 2> /dev/null || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -n0 -xf "${bad5_lz}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -n0 -xf "${bad5_lz}" --keep-damaged
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo 2> /dev/null || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -n0 -xf "${bad6_lz}"
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO

# test --extract and --keep-damaged uncompressed
rm -f test.txt || framework_failure
"${TARLZ}" -q -xf "${inbad1}.tar"
[ $? = 2 ] || test_failed $LINENO
[ ! -e test.txt ] || test_failed $LINENO
rm -f test.txt || framework_failure
"${TARLZ}" -q -xf "${inbad1}.tar" --keep-damaged
[ $? = 2 ] || test_failed $LINENO
[ -e test.txt ] || test_failed $LINENO
cmp "${inbad1}" test.txt 2> /dev/null || test_failed $LINENO
rm -f test.txt || framework_failure
#
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -xf "${bad1}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -xf "${bad2}"
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -xf "${bad3}"
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -xf "${bad4}"
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
rm -f foo bar baz || framework_failure
"${TARLZ}" -q -xf "${bad5}"
[ $? = 2 ] || test_failed $LINENO
cmp cfoo foo || test_failed $LINENO
cmp cbar bar || test_failed $LINENO
cmp cbaz baz || test_failed $LINENO
rm -f cfoo cbar cbaz foo bar baz || framework_failure
#
rm -f test3.tar.lz || framework_failure
"${TARLZ}" -q -xf "${tlzit1}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
[ ! -e test3.tar.lz ] || test_failed $LINENO
rm -f foo bar baz test3.tar.lz || framework_failure
"${TARLZ}" -q -xf "${tlzit2}"
[ $? = 2 ] || test_failed $LINENO
[ ! -e foo ] || test_failed $LINENO
[ ! -e bar ] || test_failed $LINENO
[ ! -e baz ] || test_failed $LINENO
cmp "${test3_lz}" test3.tar.lz || test_failed $LINENO
rm -f foo bar baz test3.tar.lz || framework_failure

echo
if [ ${fail} = 0 ] ; then
	echo "tests completed successfully."
	cd "${objdir}" && rm -r tmp
else
	echo "tests failed."
fi
exit ${fail}