#!/usr/bin/env sh

cd "$(dirname "$0")"
. "./.common.sh"
cd ../..

clear

if ! chkcmd 'git'; then
        echo ' error: "git" command not found.'
        exit 1
fi

versions='ORIG_HEAD master'

if test $# -gt 0; then
        versions="$@"
fi

test_dir="$(pwd)/sandbox/codevelox"
repo_dir="$test_dir/checkout"
test_php="$test_dir/speedtest.php"

git_branch=$(git branch | grep "\*" | cut -d ' ' -f 2)

ggit()
{
        git --work-tree "$repo_dir" "$@"
}

mkdir -p "$repo_dir"
mkdir -p "$test_dir"

cp -f 'support/Codevelox.php' "$test_dir/"
cp -f 'support/speedtest.php' "$test_dir/"

for v in $versions; do
        ggit checkout -f $v

        mkdir -p "$test_dir/$v"

        cp -rf "$repo_dir/source/"* "$test_dir/$v/"
done

ggit checkout $git_branch

cd "$test_dir"

echo "\n Versions to test: $versions\n"

for v in $versions; do
        echo " => Testing version $v";

        php speedtest.php "$v"
done
