#!/bin/sh
set -e

TESTDIR=$(readlink -f $(dirname $0))
. $TESTDIR/framework
setupenvironment
configarchitecture 'amd64' 'i386'

insertinstalledpackage 'pkg-native' 'amd64' '1' 'Multi-Arch: foreign
Essential: yes'
insertinstalledpackage 'pkg-foreign' 'i386' '1' 'Multi-Arch: foreign
Essential: yes'
insertinstalledpackage 'pkg-none-native' 'amd64' '1' 'Essential: yes'
insertinstalledpackage 'pkg-none-foreign' 'i386' '1' 'Essential: yes'

insertpackage 'unstable' 'pkg-native' 'amd64,i386' '2' 'Multi-Arch: foreign
Essential: yes'
insertpackage 'unstable' 'pkg-foreign' 'amd64,i386' '2' 'Multi-Arch: foreign
Depends: pkg-depends-new
Essential: yes'
insertpackage 'unstable' 'pkg-none-native' 'amd64,i386' '2' 'Essential: yes'
insertpackage 'unstable' 'pkg-none-foreign' 'amd64,i386' '2' 'Essential: yes
Depends: pkg-depends-new'

insertpackage 'unstable' 'pkg-none-new' 'amd64,i386' '2' 'Essential: yes'
insertpackage 'unstable' 'pkg-depends-new' 'amd64,i386' '2' 'Essential: yes'

setupaptarchive

testequal 'Reading package lists...
Building dependency tree...
The following packages will be REMOVED:
  pkg-native*
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  pkg-native
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
Purg pkg-native [1]' aptget purge pkg-native -s

testequal 'Reading package lists...
Building dependency tree...
The following packages will be REMOVED:
  pkg-foreign:i386*
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  pkg-foreign:i386
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
Purg pkg-foreign:i386 [1]' aptget purge pkg-foreign:i386 -s

testequal 'Reading package lists...
Building dependency tree...
The following packages will be REMOVED:
  pkg-none-native*
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  pkg-none-native
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
Purg pkg-none-native [1]' aptget purge pkg-none-native -s

testequal 'Reading package lists...
Building dependency tree...
The following packages will be REMOVED:
  pkg-none-foreign:i386*
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  pkg-none-foreign:i386
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
Purg pkg-none-foreign:i386 [1]' aptget purge pkg-none-foreign:i386 -s

testequal 'Reading package lists...
Building dependency tree...
Calculating upgrade...
The following NEW packages will be installed:
  pkg-depends-new:i386 pkg-none-new
The following packages will be upgraded:
  pkg-foreign:i386 pkg-native pkg-none-foreign:i386 pkg-none-native
4 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Inst pkg-depends-new:i386 (2 unstable [i386])
Conf pkg-depends-new:i386 (2 unstable [i386])
Inst pkg-foreign:i386 [1] (2 unstable [i386])
Conf pkg-foreign:i386 (2 unstable [i386])
Inst pkg-native [1] (2 unstable [amd64])
Conf pkg-native (2 unstable [amd64])
Inst pkg-none-foreign:i386 [1] (2 unstable [i386])
Conf pkg-none-foreign:i386 (2 unstable [i386])
Inst pkg-none-native [1] (2 unstable [amd64])
Conf pkg-none-native (2 unstable [amd64])
Inst pkg-none-new (2 unstable [amd64])
Conf pkg-none-new (2 unstable [amd64])' aptget dist-upgrade -s