File: test_uscan

package info (click to toggle)
devscripts 2.15.3%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 4,680 kB
  • ctags: 793
  • sloc: perl: 16,581; sh: 7,295; python: 950; makefile: 224; ansic: 28
file content (327 lines) | stat: -rwxr-xr-x 9,678 bytes parent folder | download | duplicates (3)
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
#!/bin/sh

# Copyright (C) 2013, Rafael Laboissiere <rafael@laboissiere.net>
#
# 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.

if test "$1" = --installed; then
    COMMAND="uscan --no-conf --compression=xz"
    shift
else
    top_srcdir=$(readlink -f "${0%/*}/..")
    if ! [ -x $top_srcdir/scripts/uscan -a -x $top_srcdir/scripts/mk-origtargz ]
    then
        echo "Please run make in scripts/"
	exit 1
    fi
    PATH="$top_srcdir/scripts:$PATH"
    PERLLIB="$top_srcdir"
    export PERLLIB
    COMMAND="uscan --no-conf --compression=xz"
fi

cleanup(){
    kill -9 $(cat $TMPDIR/repo/pid)
    rm -rf $TMPDIR
}

trap cleanup 1 2 3 13 15

containsName(){
  echo "$1" | fgrep -q "$2"
  echo $?
}

. "${0%/*}/shunit2-helper-functions.sh"

# The following tests do the following: (1) create a minimal Debian package
# directory, containing minimal files debian/{changelog,watch,copyright},
# (2) create a minimal repository, containing a tarball (built on the fly),
# (3) start an HTTP server that works offline, using the SimpleHTTPServer
# module of Python, and (4) run uscan inside that minimal universe.


# The following function tests the --repack feature
helperTestRepack() {
    from_ext="$1"
    to_comp="$2"
    file_output="$3"

    PKG=foo
    PORT=8000
    TMPDIR=$(mktemp -d)

    mkdir -p $TMPDIR/$PKG/debian

    cat <<END > $TMPDIR/$PKG/debian/watch
version=3
http://localhost:$PORT/$PKG-(\d).$from_ext
END

    cat <<END > $TMPDIR/$PKG/debian/changelog
$PKG (0-1) unstable; urgency=low

  * Initial release

 -- Joe Developer <jd@debian.org>  Mon, 02 Nov 2013 22:21:31 -0100
END

    mkdir -p $TMPDIR/repo/foo
    touch $TMPDIR/repo/foo/content

    ( cd $TMPDIR/repo ;
      tar cfa $PKG-1.$from_ext * ;
      python -m SimpleHTTPServer $PORT &
      echo $! > pid )

    OUTPUT=$( (cd $TMPDIR/$PKG ; $COMMAND --dehs --repack --compression=$to_comp) 2>&1 )

    TARBALL=${PKG}_1.orig.tar.$to_comp
    if [ "$from_ext" != "tar.$to_comp" ]
    then
	assertFalse 'unrepacked tarball still present' "[ -f $TMPDIR/${PKG}_1.orig.$from_ext ]"
    fi
    assertTrue 'pristine tarball is not created' "[ -f $TMPDIR/$TARBALL ]"
    assertNotNull "pristine tarball is not $to_comp-compressed" \
                  "$( file -L $TMPDIR/$TARBALL | grep "$file_output" )"
    CONTENTS="$(tar atf $TMPDIR/$TARBALL)"
    assertTrue 'file contents missing'	\
                $(containsName "$CONTENTS" content)
    assertTrue "malfored target in dehs output: $OUTPUT" \
               $(containsName "$OUTPUT" "<target>$TARBALL</target>")

    cleanup

}

testRepackGZ_XZ() { helperTestRepack "tar.gz" "xz" "XZ compressed data" ; }
testRepackGZ_BZ2() { helperTestRepack "tar.gz" "bz2" "bzip2 compressed data" ; }
testRepackBZ2_GZ() { helperTestRepack "tar.bz2" "gz" "gzip compressed data" ; }
testRepackGZ_GZ() { helperTestRepack "tar.gz" "gz" "gzip compressed data" ; }
testRepackXZ_XZ() { helperTestRepack "tar.xz" "xz" "XZ compressed data" ; }
testRepackTGZ_XZ() { helperTestRepack "tgz" "xz" "XZ compressed data" ; }

# The following function tests the --repack feature, with a zip file
testRepackZip_XZ() {
    to_comp=xz
    file_output="XZ compressed data"

    PKG=foo
    PORT=8000
    TMPDIR=$(mktemp -d)

    mkdir -p $TMPDIR/$PKG/debian

    cat <<END > $TMPDIR/$PKG/debian/watch
version=3
http://localhost:$PORT/$PKG-(\d).zip
END

    cat <<END > $TMPDIR/$PKG/debian/changelog
$PKG (0-1) unstable; urgency=low

  * Initial release

 -- Joe Developer <jd@debian.org>  Mon, 02 Nov 2013 22:21:31 -0100
END

    mkdir -p $TMPDIR/repo/foo
    touch $TMPDIR/repo/foo/content

    ( cd $TMPDIR/repo ;
      zip -q -r $PKG-1.zip * ;
      python -m SimpleHTTPServer $PORT &
      echo $! > pid )

    OUTPUT=$( (cd $TMPDIR/$PKG ; $COMMAND --dehs --repack --compression=$to_comp) )

    TARBALL=${PKG}_1.orig.tar.$to_comp
    assertTrue 'unrepacked zipfile present' "[ -f $TMPDIR/${PKG}-1.zip ]"
    assertTrue 'pristine tarball is not created' "[ -f $TMPDIR/$TARBALL ]"
    assertNotNull "pristine tarball is not $to_comp-compressed" \
                  "$( file -L $TMPDIR/$TARBALL | grep "$file_output" )"
    CONTENTS="$(tar atf $TMPDIR/$TARBALL)"
    assertTrue 'file contents missing'	\
                $(containsName "$CONTENTS" content)
    assertTrue "malfored target in dehs output: $OUTPUT" \
               $(containsName "$OUTPUT" "<target>$TARBALL</target>")

    cleanup

}



# The following function tests the Files-Excluded feature of uscan, which
# allows the selective exclusion of files from the upstream tarball before
# repacking it.

helperCreateRepo () {
    mkdir -p $PKG/debian

    cat <<END > $PKG/debian/watch
version=3
${OPTS}http://localhost:$PORT/$PKG-(\d).tar.gz
END

    cat <<END > $PKG/debian/changelog
$PKG (0-1) unstable; urgency=low

  * Initial release

 -- Joe Developer <jd@debian.org>  Mon, 02 Nov 2013 22:21:31 -0100
END

    cat <<'END' > $PKG/debian/copyright
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Files-Excluded: exclude-this
 exclude-dir
 .*
 */js/jquery.js
 ;?echo?baz;?#
END

    mkdir -p repo
    touch repo/include-this
    touch repo/exclude-this
    touch repo/.hidden
    mkdir -p "repo/; echo baz; #/"
    mkdir -p repo/exclude-dir
    touch repo/exclude-dir/file
    mkdir -p repo/exclude-dir/subdir
    touch repo/exclude-dir/subdir/file2
    mkdir -p repo/docs/html/js/
    touch repo/docs/html/js/jquery.js

}

helperTestContent() {
    assertTrue 'file that must be present is excluded in the tarball'	\
                $(containsName "$CONTENTS" include-this)
    assertFalse 'file that must be excluded is present in the tarball'	\
                $(containsName "$CONTENTS" exclude-this)
    assertFalse "dir that must be excluded is present in the tarball"	\
                $(containsName "$CONTENTS" exclude-dir)
    assertFalse "subdir that must be excluded is present in the tarball"	\
                $(containsName "$CONTENTS" subdir)
    assertFalse "non-root-file that must be excluded is present in the tarball"	\
                $(containsName "$CONTENTS" jquery.js)
    assertFalse "hidden file that must be excluded is present in the zip file"	\
                $(containsName "$CONTENTS" .hidden)
    assertFalse "path with whitespace that must be excluded is present"	\
                $(containsName "$CONTENTS" "; echo baz; #/")
}

testFileExclusion() {

    PKG=foo
    PORT=8000
    TMPDIR=$(mktemp -d)

    (
      cd $TMPDIR
      OPTS="opts=repacksuffix=+dfsg1 "
      helperCreateRepo
      cd repo
      tar cfz $PKG-1.tar.gz * .hidden
      python -m SimpleHTTPServer $PORT &
      echo $! > pid )

    (cd $TMPDIR/$PKG ; $COMMAND)

    TARBALL=${PKG}_1+dfsg1.orig.tar.gz
    assertTrue 'downloaded tarfile not present' "[ -f $TMPDIR/${PKG}-1.tar.gz ]"
    assertTrue 'pristine tarball is not created' "[ -f $TMPDIR/$TARBALL ]"
    assertFalse 'pristine tarball is a symlink (nothing repacked?)' "[ -L $TMPDIR/$TARBALL ]"
    assertNotNull 'pristine tarball is not gzip-compressed' \
                  "$( file $TMPDIR/$TARBALL | grep 'gzip compressed data' )"
    CONTENTS="$(tar atf $TMPDIR/$TARBALL)"

    helperTestContent

    cleanup

}

# the same, but run from a separate directory
testFileExclusionSeparateDir() {

    PKG=foo
    PORT=8000
    TMPDIR=$(mktemp -d)

    (
      cd $TMPDIR
      OPTS="opts=repacksuffix=+dfsg1 "
      helperCreateRepo
      cd repo
      tar cfz $PKG-1.tar.gz * .hidden
      python -m SimpleHTTPServer $PORT &
      echo $! > pid )

    mkdir $TMPDIR/otherdir
    (
    	cd $TMPDIR/otherdir; $COMMAND --package $PKG --force-download --upstream-version 1 --watchfile ../$PKG/debian/watch --copyright-file ../$PKG/debian/copyright
   )

    TARBALL=${PKG}_1+dfsg1.orig.tar.gz
    assertTrue 'downloaded tarfile not present' "[ -f $TMPDIR/${PKG}-1.tar.gz ]"
    assertTrue 'pristine tarball is not created' "[ -f $TMPDIR/$TARBALL ]"
    assertFalse 'pristine tarball is a symlink (nothing repacked?)' "[ -L $TMPDIR/$TARBALL ]"
    assertNotNull 'pristine tarball is not gzip-compressed' \
                  "$( file $TMPDIR/$TARBALL | grep 'gzip compressed data' )"
    CONTENTS="$(tar atf $TMPDIR/$TARBALL)"

    helperTestContent

    cleanup

}

# The same, for a zip file that is being repacked

testFileExclusionZipToTar() {

    PKG=foo
    PORT=8000
    TMPDIR=$(mktemp -d)

    (
      cd $TMPDIR
      helperCreateRepo
      cat <<END > $PKG/debian/watch
version=3
opts=repacksuffix=+dfsg1 http://localhost:$PORT/$PKG-(\d).zip
END

      cd repo
      zip -q -r $PKG-1.zip * .hidden;
      python -m SimpleHTTPServer $PORT &
      echo $! > pid )

    (cd $TMPDIR/$PKG ; $COMMAND --repack)

    TARBALL=${PKG}_1+dfsg1.orig.tar.xz
    assertTrue 'unrepacked zipfile not present' "[ -f $TMPDIR/${PKG}-1.zip ]"
    assertTrue 'pristine tarball is not created' "[ -f $TMPDIR/$TARBALL ]"
    assertNotNull 'pristine tarball is not xz-compressed' \
                  "$( file $TMPDIR/$TARBALL | grep 'XZ compressed data' )"
    CONTENTS="$(tar atf $TMPDIR/$TARBALL)"
    helperTestContent

    cleanup

}

. shunit2