#!/bin/sh

# To install:
# ln -sv $GOPATH/src/github.com/lmorg/murex/test/pre-push .git/hooks/

cd $GOPATH/src/github.com/lmorg/murex

trap ctrl_c INT

ctrl_c() {
    printf "\n\033[0;31m[PUSH CANCELLED]\033[0m\n"
    exit 1
}

echo "Starting count server...."
export MUREX_TEST_COUNT=http
go run github.com/lmorg/murex/test/count/server 2>/dev/null &
sleep 3

echo "Running golang unit tests...."
mkdir -p ./test/tmp
go test ./... -count 1 -race || exit 1
curl -s http://localhost:38000/t > ./test/murex-test-count.txt
echo "$(cat ./test/murex-test-count.txt) tests completed"

echo "Running murex behavioural tests...."
go build github.com/lmorg/murex || exit 1
./murex -c 'g: behavioural/*.mx -> foreach: f { source $f }; try {test: run *}' || exit 1

echo "Writing automated assets...."
git add ./test/murex-test-count.txt #./version.svg #./testcases.svg
git commit -m "Automated assets"

echo "Allowing git push to proceed...."
