#!/bin/sh
. ./Common

###############################################################################

qpkg_fail "direct conflict precludes resolution" prereq A <<EOF
Package: B
Version: 0
Architecture: test
Filename: B

Package: A
Version: 0
Architecture: test
Depends: B
Conflicts: B
Filename: A
EOF
expect <<EOF
can't resolve A
EOF

###############################################################################

qpkg_fail "indirect conflict precludes resolution" prereq A <<EOF
Package: C
Version: 0
Architecture: test
Filename: C

Package: B
Version: 0
Architecture: test
Depends: C
Filename: B

Package: A
Version: 0
Architecture: test
Depends: B
Conflicts: C
Filename: A
EOF
expect <<EOF
can't resolve A
EOF

###############################################################################

qpkg_fail "aggregation of conflicts" prereq A <<EOF
Package: C
Version: 0
Architecture: test
Filename: C

Package: B
Version: 0
Architecture: test
Depends: C
Conflicts: C
Filename: B

Package: A
Version: 0
Architecture: test
Depends: B
Filename: A
EOF
expect <<EOF
can't resolve A
EOF

###############################################################################

qpkg_fail "conflicts honor version (match)" prereq A <<EOF
Package: B
Version: 1
Architecture: test
Filename: B

Package: A
Version: 0
Architecture: test
Depends: B
Conflicts: B (= 1)
Filename: A
EOF
expect <<EOF
can't resolve A
EOF

###############################################################################

qpkg "conflicts honor version (mismatch)" prereq A <<EOF
Package: B
Version: 1
Architecture: test
Filename: B

Package: A
Version: 0
Architecture: test
Depends: B
Conflicts: B (= 0)
Filename: A
EOF
expect <<EOF
B
EOF

###############################################################################

qpkg "conflict trumps preference (1)" prereq foo <<EOF
Package: bar
Version: 0
Architecture: test
Filename: bar_0

Package: bar
Version: 1
Architecture: test
Filename: bar_1

Package: foo
Version: 0
Architecture: test
Depends: bar
Conflicts: bar (>= 1)
Filename: foo
EOF
expect <<EOF
bar_0
EOF

###############################################################################

qpkg "conflict trumps preference (2)" prereq foo <<EOF
Package: bar
Version: 1
Architecture: test
Filename: bar_1

Package: bar
Version: 0
Architecture: test
Filename: bar_0

Package: foo
Version: 0
Architecture: test
Depends: bar
Conflicts: bar (>= 1)
Filename: foo
EOF
expect <<EOF
bar_0
EOF

###############################################################################

qpkg_fail "prerequisite conflicts with dependant" prereq A <<EOF
Package: B
Version: 0
Architecture: test
Conflicts: A
Filename: B

Package: A
Version: 0
Architecture: test
Depends: B
Filename: A
EOF
expect <<EOF
can't resolve A
EOF

###############################################################################

qpkg_fail "prerequisite conflicts with considered package (1)" prereq A <<EOF
Package: B
Version: 0
Architecture: test
Conflicts: C
Filename: B

Package: C
Version: 0
Architecture: test
Filename: C

Package: A
Version: 0
Architecture: test
Depends: B, C
Filename: A
EOF
expect <<EOF
can't resolve A
EOF

###############################################################################

qpkg_fail "prerequisite conflicts with considered package (1)" prereq A <<EOF
Package: B
Version: 0
Architecture: test
Filename: B

Package: C
Version: 0
Architecture: test
Conflicts: B
Filename: C

Package: A
Version: 0
Architecture: test
Depends: B, C
Filename: A
EOF
expect <<EOF
can't resolve A
EOF
