#!/bin/bash

set -e

function printStatus {
  if [ $? -eq 0 ]; then
    echo -e "\nSWEET SUITE SUCCESS"
  else
    echo -e "\nSUITE FAILURE"
  fi
}

trap printStatus EXIT

bin/i18n-checkup

echo -e "\n Cleaning build artifacts..."

# Clean up old plugin binaries used in test

rm -f fixtures/plugins/*.exe
rm -f plugin_examples/*.exe

export LC_ALL="en_US.UTF-8"

if [ ! $(which ginkgo) ];then
  echo -e "\n Installing ginkgo..."
  go get github.com/onsi/ginkgo/ginkgo
fi

echo -e "\n Formatting packages..."
go fmt ./...

echo -e "\n Vetting packages for potential issues..."
go tool vet cf/.
for file in $(find {cf,plugin,testhelpers,utils} \( -name "*.go" -not -iname "*test.go" \))
do
  go tool vet -all -shadow=true $file
done

CF_HOME=$(pwd)/fixtures ginkgo -r -randomizeAllSpecs -randomizeSuites $@

echo -e "\n Running build script to confirm everything compiles..."
bin/build
