summaryrefslogtreecommitdiffstats
path: root/test/test_uscan_svn
blob: fdc3c2d2edad6d867b67c119591a012d61d23bb3 (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
#!/bin/bash

# Copyright (C) 2018, Xavier <yadd@debian.org>
#               2019-2020, Andrius Merkys <merkys@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
#set -x

DEB_HOST_OS="$(dpkg-architecture -qDEB_HOST_ARCH_OS)"
if [ "$DEB_HOST_OS" = "kfreebsd" ]; then
    # kbsd has a non-working semaphore, that is needed here.
    echo "This test is not supported on $(dpkg-architecture -qDEB_HOST_ARCH), skipping"
    exit 0
fi
DEB_HOST_ARCH="$(dpkg-architecture -qDEB_HOST_ARCH)"
if [ "$DEB_HOST_ARCH" = "i386" ]; then
    echo "To \"help\" Ubuntu that has a fondamentally broken i386 (so that we can't depend on svn), this test is simply skipped on i386."
    exit 0
fi

TESTTYPE=Svn
. ./lib_test_uscan

COMMAND="chronic_sh uscan --no-conf --compression=xz --dehs"

# prevent the local from messing with this test
export HOME=""
export XDG_CONFIG_HOME=""

# comment out for debug
#COMMAND="$COMMAND --verbose"
#COMMAND="$COMMAND --debug"

cleanup(){
    rm -rf "$TEMP_PKG_DIR"
}

spawnSvnRepo(){
    mkdir -p "$TEMP_PKG_DIR/repo"
    (cd "$TEMP_PKG_DIR/repo" || exit 1
    chronic_sh svnadmin create .)
    mkdir -p "$TEMP_PKG_DIR/working-copy"
    (cd "$TEMP_PKG_DIR/working-copy" || exit 1
    chronic_sh svn checkout "file:///$TEMP_PKG_DIR/repo" .
    chronic_sh mkdir trunk tags
    touch trunk/changelog trunk/file.c
    chronic_sh svn add trunk tags
    chronic_sh svn commit -m 'Init'
    export TZ=UTC
    for version in 1.0 2.0; do
        echo "# Version $version" >> trunk/file.c
        cat >> trunk/changelog <<END
Version $version

END
        chronic_sh faketime -f '2000-01-01 12:34:56' svn commit -m "Releasing $version"
        chronic_sh faketime -f '2000-01-01 12:34:56' svn copy ^/trunk "^/tags/v$version" -m "Version $version"
    done)
}

trap cleanup EXIT

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

# shellcheck source=shunit2-helper-functions.sh
. "${0%/*}/shunit2-helper-functions.sh"

PKG=foo

makeDebianDir() {
    WATCHARGS=$1
    TEMP_PKG_DIR=$(mktemp -d --tmpdir="$SHUNIT_TMPDIR" uscan_svn.XXXXXX)
    if [ -z "$TEMP_PKG_DIR" ]; then
        echo "Failed to create temporary directory" >&2
        exit 1
    fi
    mkdir -p "$TEMP_PKG_DIR/$PKG/debian/source"
    spawnSvnRepo

    cat <<END > "$TEMP_PKG_DIR/$PKG/debian/watch"
version=4
opts="mode=svn,$WATCHARGS" \
file:///$TEMP_PKG_DIR/repo/tags v([\\d\\.]+)\/ debian
END

    cat <<END > "$TEMP_PKG_DIR/$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
    echo '3.0 (quilt)' > "$TEMP_PKG_DIR/$PKG/debian/source/format"
}

makeDebianDirHead() {
    WATCHARGS=$1
    makeDebianDir "$WATCHARGS"
    cat <<END > "$TEMP_PKG_DIR/$PKG/debian/watch"
version=4
opts="mode=svn,$WATCHARGS" \
file:///$TEMP_PKG_DIR/repo/trunk HEAD
END
}

helperLaunch() {
    WATCHARGS=$1
    ARG="${2:-}"
    if test "$ARG" = "HEAD"; then
        makeDebianDirHead "$WATCHARGS"
    else
        makeDebianDir "$WATCHARGS"
    fi
    ( cd "$TEMP_PKG_DIR/$PKG" || exit 1 ; $COMMAND --watchfile=debian/watch )
    assertEquals "uscan: exit_code!=0 but exit_code=0" "0" "$?"
}

helperLaunchFail() {
    WATCHARGS=$1
    ARG="${2:-}"
    if test "$ARG" = "HEAD"; then
        makeDebianDirHead "$WATCHARGS"
    else
        makeDebianDir "$WATCHARGS"
    fi
    # discard output as it's expected to fail
    ( cd "$TEMP_PKG_DIR/$PKG" || exit 1 ; $COMMAND --watchfile=debian/watch > /dev/null)
    assertEquals "uscan: exit_code!=2 but exit_code=2" "2" "$?"
}

testSvn() {
    helperLaunch "pgpmode=none"
    TARBALL="${PKG}_2.0.orig.tar.xz"
    CHECKSUM=$(sha1sum "$TEMP_PKG_DIR/${PKG}-2.0.tar.xz" | awk '{print $1}')
    assertTrue 'downloaded tarfile not present' "[ -f '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' ]"
    assertTrue 'pristine tarball is not created' "[ -f '$TEMP_PKG_DIR/$TARBALL' ]"
    assertTrue 'pristine tarball is a symlink' "[ -L '$TEMP_PKG_DIR/$TARBALL' ]"
    if [ "$CHECKSUM" != 'bd4a60786013848e402bcf20db211fd465afeda5' ]; then
        set -x
        echo "Copying the faulty tarball to the artefact directory, if available..."
        if [ -n "${AUTOPKGTEST_ARTIFACTS:-}" ] && [ -d "$AUTOPKGTEST_ARTIFACTS" ]; then
            cp -v "$TEMP_PKG_DIR/${PKG}-2.0.tar.xz" "$AUTOPKGTEST_ARTIFACTS"/
        fi
        set +x
    fi
    assertTrue 'checksums do not match' "[ '${CHECKSUM}' = 'bd4a60786013848e402bcf20db211fd465afeda5' ]"
    cleanup
}

testSvnPgpmodeDefault() {
    helperLaunch "pgpmode=default"
    TARBALL="${PKG}_2.0.orig.tar.xz"
    assertTrue 'downloaded tarfile not present' "[ -f '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' ]"
    assertTrue 'pristine tarball is not created' "[ -f '$TEMP_PKG_DIR/$TARBALL' ]"
    assertTrue 'pristine tarball is a symlink' "[ -L '$TEMP_PKG_DIR/$TARBALL' ]"
    cleanup
}

testSvnPgpmodeNext() {
    helperLaunchFail "pgpmode=next"
    cleanup
}

testSvnHead() {
    helperLaunch "pgpmode=none" HEAD
    ORIG="$TEMP_PKG_DIR/foo_0.0~svn4.orig.tar.xz"
    UPSTREAM="$TEMP_PKG_DIR/foo-0.0~svn4.tar.xz"
    assertTrue 'downloaded tarfile not present' "[ -f '$UPSTREAM' ]"
    assertTrue 'pristine tarball is not created' "[ -f '$ORIG' ]"
    assertTrue 'pristine tarball is a symlink' "[ -L '$ORIG' ]"
    cleanup
}

testSvnHeadMangle() {
    helperLaunch "pgpmode=none,uversionmangle=s/^[^~]+/1.23.45/" HEAD
    ORIG="$TEMP_PKG_DIR/foo_1.23.45~svn4.orig.tar.xz"
    UPSTREAM="$TEMP_PKG_DIR/foo-1.23.45~svn4.tar.xz"
    assertTrue 'downloaded tarfile not present' "[ -f '$UPSTREAM' ]"
    assertTrue 'pristine tarball is not created' "[ -f '$ORIG' ]"
    assertTrue 'pristine tarball is a symlink' "[ -L '$ORIG' ]"
    cleanup
}

# shellcheck disable=SC1091
. shunit2