#!/bin/bash
#
# Regression test with python2 and python3.  Tests both style and functional.

# Stop on errors
set -e
set -o pipefail

# Check working directory
PROJECT_ROOT=`cd $(dirname $0)/.. && pwd -P`
cd ${PROJECT_ROOT}

# Print commands
set -x

# Run unit tests with python2
# Note that we're using a bash subshell to encapsulate the virtual environment
echo "Testing with python2"
(
  rm -rf env2.tmp
  virtualenv -p python2 env2.tmp &> /dev/null
  source env2.tmp/bin/activate &> /dev/null
  pip install . &> /dev/null
  ./bin/test-style
  ./bin/test-functional
  rm -rf env2.tmp
)

# Test with python3
# Note that we're using a bash subshell to encapsulate the virtual environment
echo "Testing with python3"
(
  python3 -m venv env3.tmp &> /dev/null
  source env3.tmp/bin/activate &> /dev/null
  pip install . &> /dev/null
  ./bin/test-style
  ./bin/test-functional
  rm -rf env3.tmp
)

# All done
set +x
echo "PASS"
