#!/bin/sh

set -e

# Test that when there is no license file, the PyPI metadata (license
# classifiers) is used to detect the license.

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 :: Apache Software License"' fixture_json ${WORK}/pkgos-test-pkg.json
fixture_sdist ${WORK}
mock_git ${WORK} ${WORK}/repo
debpypi_env ${WORK}

"${SCRIPT}" pkgos-test-pkg >${WORK}/out.log 2>&1 <<EOF
1
EOF

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

check ${WORK}/out.log 'Detected license: Apache-2.0 (from PyPI metadata)'
check ${WORK}/itp.txt 'License         : Apache-2.0'

exit 0
