#!/usr/bin/env bash

#
# Create a Heroku app with the following buildpack:
# https://github.com/ddollar/buildpack-test
#
# Push this Python buildpack to that Heroku app to
# run the tests.
#

testDetectWithReqs() {
  detect "simple-requirements"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectWithEmptyReqs() {
  detect "empty-requirements"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectDjango16() {
  detect "django-1.6-skeleton"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectDjango15() {
  detect "django-1.5-skeleton"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectDjango14() {
  detect "django-1.4-skeleton"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectDjango13() {
  detect "django-1.3-skeleton"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectNotDjangoWithSettings() {
  detect "not-django"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectWithSetupPy() {
  detect "distutils"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectWithSetupRequires() {
  detect "no-requirements"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectNotPython() {
  detect "not-python"
  assertNotCaptured "Python"
  assertEquals "1" "${RETURN}"
}

testDetectSimpleRuntimePypy2() {
  detect "simple-runtime-pypy2"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectSimpleRuntimePython2() {
  detect "simple-runtime-python2"
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

testDetectSimpleRuntimePython3() {
  detect "simple-runtime"  # should probably be renamed simple-runtime-python3
  assertCapturedEquals "Python"
  assertCapturedSuccess
}

## utils ########################################

pushd $(dirname 0) >/dev/null
BASE=$(pwd)
popd >/dev/null

source ${BASE}/vendor/test-utils

detect() {
  capture ${BASE}/bin/detect ${BASE}/test/$1
}

compile() {
  capture ${BASE}/bin/compile ${BASE}/test/$1
}

source ${BASE}/vendor/shunit2

