#!/bin/sh
set -e

TESTDIR="$(readlink -f "$(dirname "$0")")"
. "$TESTDIR/framework"

# regression test for #1126140
setupenvironment
configarchitecture 'amd64'

# dpkg helpers never create an empty Source field, so build the .deb by hand
mkdir -p empty-source/DEBIAN
cat > empty-source/DEBIAN/control <<EOF
Package: empty-source
Version: 1.0
Section: base
Priority: optional
Architecture: amd64
Source:
Maintainer: Joe Sixpack <joe@example.org>
Description: an autogenerated dummy empty-source=1.0/local
 If you find such a package installed on your system,
 something went horribly wrong! They are autogenerated
 and used only for testcases and serve no other purpose…
EOF
testsuccess --nomsg dpkg-deb --build empty-source empty-source.deb

for solver in 3.0 internal; do
	msgtest "Test that no solver crashes on an empty Source field" "$solver"
	testsuccess --nomsg aptget install ./empty-source.deb --solver "$solver" -s
done

testsuccess aptget install ./empty-source.deb -y
testdpkgstatus 'ii' 1 empty-source
