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
|
#!/bin/bash
# Copyright 2014, Rafael Laboissiere <rafael@laboissiere.net>
# Copyright 2015, James McCoy <jamessan@debian.org>
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# On Debian systems, the complete text of the GNU General Public License
# version 3 can be found in the /usr/share/common-licenses/GPL-3 file.
set -u
# Load GPG
TESTTYPE=MkOrigTarGz
. ./lib_test_uscan
if test "${1:-}" = --installed; then
MK_ORIGTARGZ="mk-origtargz"
shift
else
top_srcdir=$(readlink -f "${0%/*}/..")
make -C "$top_srcdir/scripts" mk-origtargz
MK_ORIGTARGZ="perl -I $top_srcdir/lib $top_srcdir/scripts/mk-origtargz"
PATH="$top_srcdir/scripts:$PATH"
export PATH
PERL5LIB="$top_srcdir/lib"
export PERL5LIB
fi
PROGNAME="mk-origtargz"
LC_ALL=C
export LC_ALL
setUp () {
TMPDIR=$(mktemp -d -p "$SHUNIT_TMPDIR" test_mk-origtargz.XXXX)
}
makeSubDir () {
dir=$1
shift
mkdir -p "$TMPDIR/foo-0.1/$dir"
touch "$TMPDIR/foo-0.1/$dir/a-file"
mkdir "$TMPDIR/foo-0.1/$dir/a-subdir"
touch "$TMPDIR/foo-0.1/$dir/a-subdir/a-file"
}
makeUpstreamFiles () {
mkdir -p "$TMPDIR/foo-0.1"
touch "$TMPDIR/foo-0.1/include-this-file"
touch "$TMPDIR/foo-0.1/exclude-this-file"
touch "$TMPDIR/foo-0.1/.include-this-hidden-file"
touch "$TMPDIR/foo-0.1/.exclude-this-hidden-file"
makeSubDir "include-this-dir"
makeSubDir "exclude-this-dir"
makeSubDir "exclude-dir1"
makeSubDir "exclude-dir2"
makeSubDir ".include-this-hidden-dir"
makeSubDir ".exclude-this-hidden-dir"
makeSubDir "a-dir/include-this-subdir"
# Expected not to be removed since exclusion is anchored to top-level
makeSubDir "a-dir/exclude-this-subdir"
touch "$TMPDIR/foo-0.1/; echo strange-file; #"
}
makeGolangLikeVendorFiles() {
makeSubDir "vendor"
mkdir -p "$TMPDIR/foo-0.1/vendor/includeme"
touch "$TMPDIR/foo-0.1/vendor/includeme/important.go"
}
makeTarBall () {
comp="$1"
mkgpg="${2:-none}"
makeUpstreamFiles
COMP="--auto-compress"
if [ "$comp" = "zst" ]; then
COMP=--zstd
fi
tar --create $COMP --file "$TMPDIR/foo-0.1.tar.$comp" --directory "$TMPDIR" foo-0.1
local gpgopts=(
chronic_sh $GPG
--homedir "$GPGHOME"
--no-options -q --batch --no-default-keyring
--secret-keyring "$PRIVATE_KEYRING"
--default-key 72544FAF
--detach-sign
)
case "$mkgpg" in
sig)
"${gpgopts[@]}" "$TMPDIR/foo-0.1.tar.$comp"
;;
asc)
"${gpgopts[@]}" --armor "$TMPDIR/foo-0.1.tar.$comp"
;;
none)
;;
*)
fail "unknown parameter in makeTarBall()"
;;
esac
rm -rf "$TMPDIR/foo-0.1"
}
makeSimpleTar () {
makeUpstreamFiles
tar --create --file "$TMPDIR/foo-0.1.tar" --directory "$TMPDIR" foo-0.1
rm -rf "$TMPDIR/foo-0.1"
}
makeBrokenTarBall () {
echo foo > foo.txt
tar cf - foo.txt | sed -e 's/^/foo/' | gzip > "$TMPDIR/foo-0.1.tar.gz"
rm -f foo.txt
}
makeZipFile () {
makeUpstreamFiles
(cd $TMPDIR >/dev/null; zip -q -r "foo-0.1.zip" foo-0.1 )
rm -rf "$TMPDIR/foo-0.1"
}
makeJarFile () {
makeUpstreamFiles
cat > "$TMPDIR/MANIFEST.MF" <<END
Manifest-Version: 1.0
Main-Class: foo.bar
END
(cd $TMPDIR >/dev/null; jar cf "foo-0.1.jar" MANIFEST.MF foo-0.1 )
rm -rf "$TMPDIR/foo-0.1" "$TMPDIR/MANIFEST.MF"
}
makeDebianChangelog() {
mkdir -p $TMPDIR/foo/debian
cat <<END > $TMPDIR/foo/debian/changelog
foo (0.1-1) unstable; urgency=low
* Initial release
-- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100
END
}
makeDebianOldDir() {
makeDebianChangelog
}
makeDebianDir() {
makeDebianChangelog
mkdir -p $TMPDIR/foo/debian/source
echo -n "3.0 (quilt)" > $TMPDIR/foo/debian/source/format
}
makeDebianCopyright() {
cat <<'END' > $TMPDIR/foo/debian/copyright
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Files-Excluded: exclude-this*
.exclude-this*
exclude-dir1
exclude-dir2/
;?echo?strange-file;?#
END
}
makeWrongDebianCopyright() {
cat <<'END' > $TMPDIR/foo/debian/copyright
Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=174
Files-Excluded: exclude-this*
.exclude-this*
exclude-dir1
exclude-dir2/
;?echo?strange-file;?#
END
}
makeUnmatchedExcludeCopyright() {
cat <<'END' > $TMPDIR/foo/debian/copyright
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Files-Excluded: exclude-this*
.exclude-this*
exclude-dir1
exclude-dir2
;?echo?strange-file;?#
nomatch
END
}
makeDuplicatePatternCopyright() {
cat <<'END' > $TMPDIR/foo/debian/copyright
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Files-Excluded: exclude-this*
.exclude-this*
exclude-dir1
exclude-dir*
;?echo?strange-file;?#
END
}
expected_stderr_after_removal="mk-origtargz warn: Files-Excluded pattern (exclude-dir2/) should not have a trailing /"
expected_files_after_removal=$(LC_ALL=C sort <<END
foo-0.1/
foo-0.1/a-dir/
foo-0.1/a-dir/exclude-this-subdir/
foo-0.1/a-dir/exclude-this-subdir/a-file
foo-0.1/a-dir/exclude-this-subdir/a-subdir/
foo-0.1/a-dir/exclude-this-subdir/a-subdir/a-file
foo-0.1/a-dir/include-this-subdir/
foo-0.1/a-dir/include-this-subdir/a-file
foo-0.1/a-dir/include-this-subdir/a-subdir/
foo-0.1/a-dir/include-this-subdir/a-subdir/a-file
foo-0.1/include-this-dir/
foo-0.1/include-this-dir/a-file
foo-0.1/include-this-dir/a-subdir/
foo-0.1/include-this-dir/a-subdir/a-file
foo-0.1/include-this-file
foo-0.1/.include-this-hidden-dir/
foo-0.1/.include-this-hidden-dir/a-file
foo-0.1/.include-this-hidden-dir/a-subdir/
foo-0.1/.include-this-hidden-dir/a-subdir/a-file
foo-0.1/.include-this-hidden-file
END
)
run_mk_origtargz() {
local dir="$1"
local exp_stderr="$2"
local exp_stdout="$3"
local stderrF="${SHUNIT_TMPDIR}/stderr"
shift
shift
shift
output="$( cd $TMPDIR/$dir >/dev/null; LC_ALL=C $MK_ORIGTARGZ "$@" 2> $stderrF )"
stderr="$(cat $stderrF)"
retval=$?
assertEquals "standard output of mk-origtargz $*\n" "$exp_stdout" "$output"
assertEquals "error output of mk-origtargz $*\n" "$exp_stderr" "$stderr"
assertEquals "return valueof mk-origtargz $*\n" "0" "$retval"
}
assertType () {
mime="$1"
file="$2"
actual="$(file --brief --mime-type "$file" | sed -e 's,/x-,/,')"
assertEquals "filetype for $(basename "$file")" "$mime" "$actual"
}
testSymlink() {
makeTarBall gz
makeDebianDir
run_mk_origtargz foo "" \
"Successfully symlinked ../foo-0.1.tar.gz to ../foo_0.1.orig.tar.gz." \
../foo-0.1.tar.gz
assertTrue "original tarball does not exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/foo_0.1.orig.tar.gz ]"
assertEquals "final symlink" foo-0.1.tar.gz "$(readlink $TMPDIR/foo_0.1.orig.tar.gz)"
}
testSymlinkWithConvertedSig() {
makeTarBall gz sig
makeDebianDir
run_mk_origtargz foo "" \
"Successfully symlinked ../foo-0.1.tar.gz to ../foo_0.1.orig.tar.gz." \
--signature 1 --signature-file=../foo-0.1.tar.gz.sig \
../foo-0.1.tar.gz
assertTrue "original tarball does not exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/foo_0.1.orig.tar.gz ]"
assertEquals "final symlink" foo-0.1.tar.gz "$(readlink $TMPDIR/foo_0.1.orig.tar.gz)"
assertTrue "signature isn't valid" "$GPG --homedir '$GPGHOME' --verify $TMPDIR/foo_0.1.orig.tar.gz.asc"
}
testSymlinkWithArmoredSig() {
# MR for https://lists.debian.org/debian-devel/2019/04/msg00459.html
makeTarBall gz asc
# an armored signature, but with the wrong extension.
mv $TMPDIR/foo-0.1.tar.gz.asc $TMPDIR/foo-0.1.tar.gz.sig
makeDebianDir
run_mk_origtargz foo "" \
"Successfully symlinked ../foo-0.1.tar.gz to ../foo_0.1.orig.tar.gz." \
--signature 1 --signature-file=../foo-0.1.tar.gz.sig \
../foo-0.1.tar.gz
assertTrue "original tarball does not exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/foo_0.1.orig.tar.gz ]"
assertEquals "final symlink" foo-0.1.tar.gz "$(readlink $TMPDIR/foo_0.1.orig.tar.gz)"
assertTrue "signature isn't valid" "$GPG --homedir '$GPGHOME' --verify $TMPDIR/foo_0.1.orig.tar.gz.asc"
}
testCopy() {
makeTarBall gz
makeDebianDir
run_mk_origtargz foo "" \
"Successfully copied ../foo-0.1.tar.gz to ../foo_0.1.orig.tar.gz." \
--copy ../foo-0.1.tar.gz
assertTrue "original tarball does not exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertFalse "result is a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/foo_0.1.orig.tar.gz ]"
}
testRename() {
makeTarBall gz
makeDebianDir
run_mk_origtargz foo "" \
"Successfully renamed ../foo-0.1.tar.gz to ../foo_0.1.orig.tar.gz." \
--rename ../foo-0.1.tar.gz
assertFalse "original tarball does exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertFalse "result is a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/foo_0.1.orig.tar.gz ]"
}
testSymlinkExplicit() {
makeTarBall gz
run_mk_origtargz "" "" \
"Successfully symlinked foo-0.1.tar.gz to foo_0.1.orig.tar.gz." \
--package foo --version 0.1 foo-0.1.tar.gz
assertTrue "original tarball does not exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/foo_0.1.orig.tar.gz ]"
assertEquals "final symlink" foo-0.1.tar.gz "$(readlink $TMPDIR/foo_0.1.orig.tar.gz)"
}
testCopyExplicit() {
makeTarBall gz
run_mk_origtargz "" "" \
"Successfully copied foo-0.1.tar.gz to foo_0.1.orig.tar.gz." \
--package foo --version 0.1 --copy foo-0.1.tar.gz
assertTrue "original tarball does not exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertFalse "result is a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/foo_0.1.orig.tar.gz ]"
}
testRenameExplicit() {
makeTarBall gz
run_mk_origtargz "" "" \
"Successfully renamed foo-0.1.tar.gz to foo_0.1.orig.tar.gz." \
--package foo --version 0.1 --rename foo-0.1.tar.gz
assertFalse "original tarball does exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertFalse "result is a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/foo_0.1.orig.tar.gz ]"
}
testSymlinkExplicitSubdir() {
makeTarBall gz
mkdir -p $TMPDIR/destdir
run_mk_origtargz "" "" \
"Successfully symlinked foo-0.1.tar.gz to destdir/foo_0.1.orig.tar.gz." \
--package foo --version 0.1 -C destdir foo-0.1.tar.gz
assertTrue "original tarball does not exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/destdir/foo_0.1.orig.tar.gz ]"
assertTrue "result is not a symlink" "[ -L $TMPDIR/destdir/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/destdir/foo_0.1.orig.tar.gz ]"
assertEquals "final symlink" ../foo-0.1.tar.gz "$(readlink $TMPDIR/destdir/foo_0.1.orig.tar.gz)"
}
testRepackGZ2GZ() {
makeTarBall gz
run_mk_origtargz "" "" \
"Successfully copied foo-0.1.tar.gz to foo_0.1.orig.tar.gz." \
--package foo --version 0.1 --copy foo-0.1.tar.gz --repack --compression gzip
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertType application/gzip $TMPDIR/foo_0.1.orig.tar.gz
}
testForceRepackGZ2XZ() {
makeTarBall gz
makeDebianDir
run_mk_origtargz foo "" \
"Successfully repacked ../foo-0.1.tar.gz as ../foo_0.1.orig.tar.gz." \
--force-repack ../foo-0.1.tar.gz --compression gzip
assertTrue "original tarball does not exist" "[ -e $TMPDIR/foo-0.1.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not a file" "[ -f $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result is not readable" "[ -r $TMPDIR/foo_0.1.orig.tar.gz ]"
}
testRepackGZ2XZ() {
makeTarBall gz
run_mk_origtargz "" ""\
"Successfully repacked foo-0.1.tar.gz as foo_0.1.orig.tar.xz." \
--package foo --version 0.1 --copy foo-0.1.tar.gz --repack
assertFalse "wrong result does exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
}
testRepackXZ2GZ() {
makeTarBall xz
run_mk_origtargz "" "" \
"Successfully repacked foo-0.1.tar.xz as foo_0.1.orig.tar.gz." \
--package foo --version 0.1 --copy foo-0.1.tar.xz --repack --compression gzip
assertFalse "wrong result does exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertType application/gzip $TMPDIR/foo_0.1.orig.tar.gz
}
testRepackZST2XZRepackOpt() {
makeTarBall zst
run_mk_origtargz "" ""\
"Successfully repacked foo-0.1.tar.zst as foo_0.1.orig.tar.xz." \
--package foo --version 0.1 --copy foo-0.1.tar.zst --repack
assertFalse "wrong result does exist" "[ -e $TMPDIR/foo_0.1.orig.tar.zst ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
}
testRepackZST2XZNoRepackOpt() {
makeTarBall zst
run_mk_origtargz "" ""\
"Successfully repacked foo-0.1.tar.zst as foo_0.1.orig.tar.xz." \
--package foo --version 0.1 --copy foo-0.1.tar.zst
assertFalse "wrong result does exist" "[ -e $TMPDIR/foo_0.1.orig.tar.zst ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
}
testRepackZST2ZSTFail() {
makeTarBall zst
run_mk_origtargz "" "mk-origtargz error: Bad value for compression: Unknown compression scheme zst"\
"" \
--package foo --version 0.1 --copy foo-0.1.tar.zst --compression zst
assertFalse "wrong result does exist" "[ -e $TMPDIR/foo_0.1.orig.tar.zst ]"
assertFalse "result does exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
}
testRepackZip2GZ() {
makeZipFile
run_mk_origtargz "" "" \
"Successfully repacked foo-0.1.zip as foo_0.1.orig.tar.gz." \
--package foo --version 0.1 --copy foo-0.1.zip --compression gzip
assertTrue "original zip file does not exist" "[ -e $TMPDIR/foo-0.1.zip ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertType application/gzip $TMPDIR/foo_0.1.orig.tar.gz
}
testRepackJar2GZ() {
if ! command -v jar >/dev/null
then
# skip to avoid dependency on java-jdk
return
fi
makeJarFile
run_mk_origtargz "" "" \
"Successfully repacked foo-0.1.jar as foo_0.1.orig.tar.gz." \
--package foo --version 0.1 --copy foo-0.1.jar --compression gzip
assertTrue "original zip file does not exist" "[ -e $TMPDIR/foo-0.1.jar ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertType application/gzip $TMPDIR/foo_0.1.orig.tar.gz
}
testRepackZip2GZRename() {
makeZipFile
run_mk_origtargz "" "" \
"Successfully repacked foo-0.1.zip as foo_0.1.orig.tar.gz, and removed the original file." \
--package foo --version 0.1 --rename foo-0.1.zip --compression gzip
assertFalse "original zip file does exist" "[ -e $TMPDIR/foo-0.1.zip ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertType application/gzip $TMPDIR/foo_0.1.orig.tar.gz
}
testRepackZip2XZ() {
makeZipFile
run_mk_origtargz "" "" \
"Successfully repacked foo-0.1.zip as foo_0.1.orig.tar.xz." \
--package foo --version 0.1 foo-0.1.zip
assertTrue "original zip file does not exist" "[ -e $TMPDIR/foo-0.1.zip ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
}
testRepackXpi2XZ() {
makeZipFile
mv $TMPDIR/foo-0.1.zip $TMPDIR/foo-0.1.xpi
run_mk_origtargz "" "" \
"Successfully repacked foo-0.1.xpi as foo_0.1.orig.tar.xz." \
--package foo --version 0.1 foo-0.1.xpi
assertTrue "original xpi file does not exist" "[ -e $TMPDIR/foo-0.1.xpi ]"
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
}
testRepackTAR2XZ() {
makeSimpleTar
run_mk_origtargz "" "" \
"Successfully repacked foo-0.1.tar as foo_0.1.orig.tar.xz." \
--package foo --version 0.1 --copy foo-0.1.tar --repack
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
}
testOldFormat() {
makeTarBall xz
makeDebianOldDir
makeDebianCopyright
run_mk_origtargz foo "mk-origtargz warn: Missing debian/source/format, switch compression to gzip
$expected_stderr_after_removal" \
"Successfully repacked ../foo-0.1.tar.xz as ../foo_0.1.orig.tar.gz, deleting 19 files from it." \
../foo-0.1.tar.xz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertType application/gzip $TMPDIR/foo_0.1.orig.tar.gz
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.gz | sort)"
}
testExclude() {
makeTarBall gz
makeDebianDir
makeDebianCopyright
run_mk_origtargz foo "$expected_stderr_after_removal" \
"Successfully repacked ../foo-0.1.tar.gz as ../foo_0.1.orig.tar.xz, deleting 19 files from it." \
../foo-0.1.tar.gz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.xz | sort)"
}
testGoVendorIncludeIgnore () {
makeGolangLikeVendorFiles
makeTarBall gz
makeDebianDir
makeDebianCopyright
# adjust existing test cases slightly
cat <<'END' >> $TMPDIR/foo/debian/copyright
vendor
Files-Included:
vendor/includeme
END
expected_files=$(LC_ALL=C sort <<END
$expected_files_after_removal
foo-0.1/vendor/
foo-0.1/vendor/a-subdir/
foo-0.1/vendor/includeme/
foo-0.1/vendor/includeme/important.go
END
)
run_mk_origtargz foo "$expected_stderr_after_removal" \
"Successfully repacked ../foo-0.1.tar.gz as ../foo_0.1.orig.tar.xz, deleting 21 files from it." \
../foo-0.1.tar.gz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
assertEquals "file contents" "$expected_files" "$(tar taf $TMPDIR/foo_0.1.orig.tar.xz | sort)"
}
testExcludeXZ() {
makeTarBall xz
makeDebianDir
makeDebianCopyright
run_mk_origtargz foo "$expected_stderr_after_removal" \
"Successfully repacked ../foo-0.1.tar.xz as ../foo_0.1.orig.tar.xz, deleting 19 files from it." \
../foo-0.1.tar.xz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.xz | sort)"
}
testExcludeZip() {
makeZipFile
makeDebianDir
makeDebianCopyright
run_mk_origtargz foo "$expected_stderr_after_removal" \
"Successfully repacked ../foo-0.1.zip as ../foo_0.1.orig.tar.xz, deleting 19 files from it." \
../foo-0.1.zip
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.xz | sort)"
}
testSuffix() {
makeTarBall gz
makeDebianDir
makeDebianCopyright
run_mk_origtargz foo "$expected_stderr_after_removal" \
"Successfully repacked ../foo-0.1.tar.gz as ../foo_0.1+dfsg1.orig.tar.xz, deleting 19 files from it." \
../foo-0.1.tar.gz --repack-suffix +dfsg1
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1+dfsg1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1+dfsg1.orig.tar.xz
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1+dfsg1.orig.tar.xz | sort)"
}
testSuffixXZ() {
makeTarBall xz
makeDebianDir
makeDebianCopyright
run_mk_origtargz foo "$expected_stderr_after_removal" \
"Successfully repacked ../foo-0.1.tar.xz as ../foo_0.1+dfsg1.orig.tar.xz, deleting 19 files from it." \
../foo-0.1.tar.xz --repack-suffix +dfsg1
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1+dfsg1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1+dfsg1.orig.tar.xz
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1+dfsg1.orig.tar.xz | sort)"
}
testSuffixZip() {
makeZipFile
makeDebianDir
makeDebianCopyright
run_mk_origtargz foo "$expected_stderr_after_removal" \
"Successfully repacked ../foo-0.1.zip as ../foo_0.1+dfsg1.orig.tar.xz, deleting 19 files from it." \
../foo-0.1.zip --repack-suffix +dfsg1
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1+dfsg1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1+dfsg1.orig.tar.xz
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1+dfsg1.orig.tar.xz | sort)"
}
testSuffixNoExclusions() {
makeTarBall gz
makeDebianDir
run_mk_origtargz foo "" \
"Successfully renamed ../foo-0.1.tar.gz to ../foo_0.1.orig.tar.gz." \
../foo-0.1.tar.gz --rename --repack-suffix +dfsg1
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
}
testSameNameSymlink() {
makeTarBall gz
mv $TMPDIR/foo-0.1.tar.gz $TMPDIR/foo_0.1.orig.tar.gz
makeDebianDir
run_mk_origtargz foo "" \
"Leaving ../foo_0.1.orig.tar.gz where it is." \
--symlink ../foo_0.1.orig.tar.gz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertFalse "result is a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
}
testSameNameCopy() {
makeTarBall gz
mv $TMPDIR/foo-0.1.tar.gz $TMPDIR/foo_0.1.orig.tar.gz
makeDebianDir
run_mk_origtargz foo "" \
"Leaving ../foo_0.1.orig.tar.gz where it is." \
--copy ../foo_0.1.orig.tar.gz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertFalse "result is a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
}
testSameNameRename() {
makeTarBall gz
mv $TMPDIR/foo-0.1.tar.gz $TMPDIR/foo_0.1.orig.tar.gz
makeDebianDir
run_mk_origtargz foo "" \
"Leaving ../foo_0.1.orig.tar.gz where it is." \
--rename ../foo_0.1.orig.tar.gz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertFalse "result is a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
}
testSameNameExclude() {
makeTarBall gz
mv $TMPDIR/foo-0.1.tar.gz $TMPDIR/foo_0.1.orig.tar.gz
makeDebianDir
makeDebianCopyright
run_mk_origtargz foo "$expected_stderr_after_removal" \
"Leaving ../foo_0.1.orig.tar.gz where it is, deleting 19 files from it." \
../foo_0.1.orig.tar.gz --compression=gzip
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
assertFalse "result is a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.gz ]"
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.gz | sort)"
}
testSameNameExcludeSymlink() {
makeTarBall xz
ln -s foo-0.1.tar.xz $TMPDIR/foo_0.1.orig.tar.xz
makeDebianDir
makeDebianCopyright
run_mk_origtargz foo "$expected_stderr_after_removal" \
"Leaving ../foo_0.1.orig.tar.xz where it is, deleting 19 files from it." \
../foo_0.1.orig.tar.xz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertTrue "result is not a symlink" "[ -L $TMPDIR/foo_0.1.orig.tar.xz ]"
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.xz | sort)"
}
testCopyrightFormatWarning() {
makeTarBall gz
makeDebianDir
makeWrongDebianCopyright
run_mk_origtargz foo \
"mk-origtargz warn: The file debian/copyright mentions Files-Excluded, but its format is not recognized. Specify Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ in order to remove files from the tarball with mk-origtargz." \
"Successfully symlinked ../foo-0.1.tar.gz to ../foo_0.1.orig.tar.gz." \
../foo-0.1.tar.gz
}
testBrokenTarWarning() {
makeBrokenTarBall
makeDebianDir
if dpkg --compare-versions $(dpkg-query -W -f='${Version}' libdpkg-perl) lt 1.19.0~; then
local SUBPROCESS_ERROR="gave error exit status 2"
else
local SUBPROCESS_ERROR="subprocess returned exit status 2"
fi
run_mk_origtargz foo \
"tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
$PROGNAME: error: tar --list --auto-compress --file ../foo_0.1.orig.tar.xz $SUBPROCESS_ERROR" \
"" \
../foo-0.1.tar.gz --repack
}
testUnmatchedExclusion() {
makeTarBall gz
makeDebianDir
makeUnmatchedExcludeCopyright
run_mk_origtargz foo "mk-origtargz warn: No files matched excluded pattern as the last matching glob: nomatch" \
"Successfully repacked ../foo-0.1.tar.gz as ../foo_0.1.orig.tar.xz, deleting 19 files from it." \
../foo-0.1.tar.gz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.xz | sort)"
}
testDuplicatePattern() {
makeTarBall gz
makeDebianDir
makeDuplicatePatternCopyright
run_mk_origtargz foo "mk-origtargz warn: No files matched excluded pattern as the last matching glob: exclude-dir1" \
"Successfully repacked ../foo-0.1.tar.gz as ../foo_0.1.orig.tar.xz, deleting 19 files from it." \
../foo-0.1.tar.gz
assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.xz ]"
assertType application/xz $TMPDIR/foo_0.1.orig.tar.xz
assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.xz | sort)"
}
. shunit2
|