Last active
August 29, 2015 14:07
-
-
Save Majkl578/eafc31a469076a3e886b to your computer and use it in GitHub Desktop.
Tests runner for all Nette Components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Tests runner for all Nette Components | |
# Author: Majkl578 | |
if [ "$1" == "--help" ] || [ "$1" == "-h" ] ; then | |
echo "Usage: $0 [HHVM_BINARY=hhvm] [DIR=random]" | |
exit 1 | |
fi | |
COMPONENTS=(application caching database finder forms latte neon reflection routing security tokenizer tracy bootstrap component-model di http mail php-generator robot-loader safe-stream utils) | |
BINARY=$1 | |
DIR=$2 | |
DATABASE_CONFIG='[mysql] | |
\ndsn = "mysql:host=127.0.0.1;dbname=nette_db_tests" | |
\nuser = root | |
\npassword = pwd | |
\n | |
\n[postgresql] | |
\ndsn = "pgsql:host=127.0.0.1;dbname=nette_db_tests" | |
\nuser = postgres | |
\npassword = pwd | |
\n | |
\n[sqlite] | |
\ndsn = "sqlite::memory:" | |
' | |
if [ -z "$DIR" ] || [ "$DIR" == "random" ] || [ ! -d "$DIR" ] || [ ! -w "$DIR" ]; then | |
DIR=`mktemp -d` | |
fi | |
if [ -z "$BINARY" ]; then | |
HHVM=hhvm | |
fi | |
if [ ! -x `command -v $BINARY` ]; then | |
echo "Invalid binary executable." | |
exit 1 | |
fi | |
BINARY_TYPE=`$BINARY --version 2>&1 | grep -E '(HipHop VM|PHP)'` || true | |
if [ -z "$BINARY_TYPE" ]; then | |
echo "Binary must be either PHP or HHVM." | |
exit 1 | |
fi | |
if [ -x git ]; then | |
echo "git not found in \$PATH" | |
exit 1 | |
fi | |
echo "Directory: $DIR" | |
echo | |
echo "Using $BINARY_TYPE, version:" | |
$BINARY --version | |
echo | |
COMPOSER_PATH=$DIR/composer | |
echo "Downloading composer..." | |
wget http://getcomposer.org/composer.phar -O $COMPOSER_PATH &> /dev/null | |
$BINARY $COMPOSER_PATH --version --no-ansi | |
echo | |
echo | |
STAT_TOTAL=0 | |
STAT_SKIPPED=0 | |
STAT_FAILED=0 | |
STAT_FAILURE_RATIO=0 | |
declare -A STATUS_COMPONENTS | |
exec 3>&1 | |
for COMPONENT in "${COMPONENTS[@]}"; do | |
COMPONENT_PATH=$DIR/$COMPONENT | |
mkdir $COMPONENT_PATH | |
cd $COMPONENT_PATH | |
echo "Testing $COMPONENT" | |
echo "Cloning..." | |
git clone https://github.com/nette/$COMPONENT --depth 1 --quiet $COMPONENT_PATH | |
echo "Installing dependencies..." | |
$BINARY $COMPOSER_PATH update -n --quiet | |
if [ "$COMPONENT" == "database" ]; then | |
echo "Setting databases.ini config file..." | |
echo -e $DATABASE_CONFIG > $COMPONENT_PATH/tests/Database/databases.ini | |
fi | |
echo "Testing..." | |
RESULT=$(vendor/bin/tester -p $BINARY -j 8 -s tests/ | tee /dev/fd/3 | grep -oE '(OK|FAILURES!).*') | |
COMPONENT_TOTAL=`echo $RESULT | grep -oE '([0-9]+) tests' | grep -oE '[0-9]+'` | |
COMPONENT_SKIPPED=`echo $RESULT | grep -oE '([0-9]+) skipped' | grep -oE '[0-9]+' || true` | |
COMPONENT_FAILED=`echo $RESULT | grep -oE '([0-9]+) failure' | grep -oE '[0-9]+' || true` | |
STAT_TOTAL=$(($STAT_TOTAL+$COMPONENT_TOTAL)) | |
if [ ! -z "$COMPONENT_SKIPPED" ]; then | |
STAT_SKIPPED=$(($STAT_SKIPPED+$COMPONENT_SKIPPED)) | |
fi | |
if [ ! -z "$COMPONENT_FAILED" ]; then | |
STAT_FAILED=$(($STAT_FAILED+$COMPONENT_FAILED)) | |
fi | |
if [ $STAT_TOTAL -gt 0 ] && [ $STAT_FAILED -gt 0 ]; then | |
STAT_FAILURE_RATIO=$(($STAT_FAILED*100/$STAT_TOTAL)) | |
fi | |
echo "Done testing $COMPONENT" | |
echo | |
echo "Current status: $STAT_TOTAL tests, $STAT_SKIPPED skipped, $STAT_FAILED failed (failure ratio $STAT_FAILURE_RATIO%)" | |
echo | |
echo | |
if [ -z $COMPONENT_FAILED ]; then | |
STATUS_COMPONENTS[$COMPONENT]="PASSED" | |
else | |
STATUS_COMPONENTS[$COMPONENT]="FAILED ${COMPONENT_FAILED}x" | |
fi | |
cd $DIR | |
done | |
echo | |
echo "Testing all components done!" | |
echo | |
echo "Final status: $STAT_TOTAL tests, $STAT_SKIPPED skipped, $STAT_FAILED failed (failure ratio $STAT_FAILURE_RATIO%)" | |
echo | |
echo "Status per component:" | |
for COMPONENT in "${COMPONENTS[@]}"; do | |
echo "$COMPONENT: ${STATUS_COMPONENTS[$COMPONENT]}" | |
done | |
echo | |
echo | |
echo "Directory $DIR not removed, you may either investigate the output or consider removing it yourself." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adjust $DATABASE_CONFIG, then: | |
$ test-all.sh hhvm | tee all-tests.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment