#!/bin/sh

set -e

# Test that when several licenses are detected (ex: the "MIT License" and
# "BSD License" classifiers of a dual licensed package), the user is
# asked to choose, instead of silently keeping the last detection.

ME=$(basename $0)
WORK=$(mktemp -d)
trap 'rm -rf "${WORK}"' EXIT
TESTDIR=$(cd "$(dirname "$0")" && pwd)
. "${TESTDIR}/fixtures.sh"

cd "${WORK}"

fixture_repo ${WORK}/repo no
FIX_CLASSIFIERS='"License :: OSI Approved :: MIT License", "License :: OSI Approved :: BSD License"' fixture_json ${WORK}/pkgos-test-pkg.json
fixture_sdist ${WORK}
mock_git ${WORK} ${WORK}/repo
debpypi_env ${WORK}

# Answer 1 to the team question, then 4 (Expat) in the license menu:
# 1 Apache-2.0, 2 BSD-2-clause, 3 BSD-3-clause, 4 Expat, ...
"${SCRIPT}" pkgos-test-pkg >${WORK}/out.log 2>&1 <<EOF
1
4
EOF

check () {
	if ! grep -q "$2" "$1" ; then
		echo "${ME}: $1 doesn't contain: $2"
		exit 1
	fi
}

check ${WORK}/out.log 'Multiple or unclear licenses detected (BSD-2-clause Expat)'
check ${WORK}/itp.txt 'License         : Expat'

exit 0
