#!/bin/bash
#
# This file is part of  pbuilder -- personal Debian package builder
#
# Copyright © 2015 Mattia Rizzolo <mattia@mapreri.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 2 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.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, see <http://www.gnu.org/licenses/>.
#   On Debian systems, the full text of the GNU General Public
#   License version 2 can be found in the file
#   `/usr/share/common-licenses/GPL-2'.


# testsuite to test pbuilder-satisfydepends-funcs.

TD="$(dirname "$0")"
if [ -n "$PBUILDER_CHECKOUT" ]; then
    . "$TD/testlib.sh"
    . "$PBUILDER_CHECKOUT/pbuilder-buildpackage-funcs"
else
    . "$TD/testlib.sh"
    . "$PBUILDER_TEST_PKGLIBDIR/pbuilder-buildpackage-funcs"
fi

DEBIAN_CONTROL=""

cleanup() {
    if [ -n "$DEBIAN_CONTROL" ]; then
        rm -f "$DEBIAN_CONTROL"
    fi
}

test_getdscfilesNormal () {
    cat "$TESTDATA_DIR/dsc1" > "$DEBIAN_CONTROL"
    get822files dsc "$DEBIAN_CONTROL"
}

test_getdscfilesWithoutNL () {
    cat "$TESTDATA_DIR/dsc2_withoutNL" > "$DEBIAN_CONTROL"
    get822files dsc "$DEBIAN_CONTROL"
}

test_getchangesfilesNormal () {
    cat "$TESTDATA_DIR/changes1" > "$DEBIAN_CONTROL"
    get822files changes "$DEBIAN_CONTROL"
}

trap cleanup sigpipe sighup exit

# FIXME move to build dir also because we have to hardoce /tmp/ on the result below
DEBIAN_CONTROL="$(mktemp)"

expect_output "$DEBIAN_CONTROL /tmp/haskell-concrete-typerep_0.1.0.2.orig.tar.gz /tmp/haskell-concrete-typerep_0.1.0.2-2.debian.tar.gz" test_getdscfilesNormal
expect_output "$DEBIAN_CONTROL /tmp/golang-xmpp-dev_0.0~git20140304.orig.tar.gz /tmp/golang-xmpp-dev_0.0~git20140304-1.debian.tar.xz" test_getdscfilesWithoutNL
expect_output "$DEBIAN_CONTROL /tmp/pbuilder_0.225.2~bpo8+1.dsc /tmp/pbuilder_0.225.2~bpo8+1.tar.xz /tmp/pbuilder_0.225.2~bpo8+1_all.deb" test_getchangesfilesNormal

testlib_summary
