From e3ac4d7b370896c3b03baf188f059d229603e8de Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Fri, 15 May 2015 11:36:19 +0200 Subject: [PATCH 1/3] Lint bash script using ShellCheck Ref http://www.shellcheck.net/about.html --- autotest.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/autotest.sh b/autotest.sh index 8b8017eba8..b01bdda089 100755 --- a/autotest.sh +++ b/autotest.sh @@ -54,10 +54,10 @@ if ! [ -x "$PHPUNIT" ]; then fi PHPUNIT_VERSION=$("$PHP" "$PHPUNIT" --version | cut -d" " -f2) -PHPUNIT_MAJOR_VERSION=$(echo $PHPUNIT_VERSION | cut -d"." -f1) -PHPUNIT_MINOR_VERSION=$(echo $PHPUNIT_VERSION | cut -d"." -f2) +PHPUNIT_MAJOR_VERSION=$(echo "$PHPUNIT_VERSION" | cut -d"." -f1) +PHPUNIT_MINOR_VERSION=$(echo "$PHPUNIT_VERSION" | cut -d"." -f2) -if ! [ $PHPUNIT_MAJOR_VERSION -gt 3 -o \( $PHPUNIT_MAJOR_VERSION -eq 3 -a $PHPUNIT_MINOR_VERSION -ge 7 \) ]; then +if ! [ "$PHPUNIT_MAJOR_VERSION" -gt 3 -o \( "$PHPUNIT_MAJOR_VERSION" -eq 3 -a "$PHPUNIT_MINOR_VERSION" -ge 7 \) ]; then echo "phpunit version >= 3.7 required. Version found: $PHPUNIT_VERSION" >&2 exit 4 fi @@ -70,7 +70,7 @@ fi if [ "$1" ]; then FOUND=0 for DBCONFIG in $DBCONFIGS; do - if [ "$1" = $DBCONFIG ]; then + if [ "$1" = "$DBCONFIG" ]; then FOUND=1 break fi @@ -90,7 +90,7 @@ fi function cleanup_config { if [ ! -z "$DOCKER_CONTAINER_ID" ]; then echo "Kill the docker $DOCKER_CONTAINER_ID" - docker rm -f $DOCKER_CONTAINER_ID + docker rm -f "$DOCKER_CONTAINER_ID" fi cd "$BASEDIR" @@ -132,15 +132,15 @@ function execute_tests { # drop database if [ "$1" == "mysql" ] ; then - mysql -u $DATABASEUSER -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true + mysql -u "$DATABASEUSER" -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true fi if [ "$1" == "pgsql" ] ; then - dropdb -U $DATABASEUSER $DATABASENAME || true + dropdb -U "$DATABASEUSER" "$DATABASENAME" || true fi if [ "$1" == "oci" ] ; then echo "Fire up the oracle docker" - DOCKER_CONTAINER_ID=`docker run -d deepdiver/docker-oracle-xe-11g` - DATABASEHOST=`docker inspect $DOCKER_CONTAINER_ID | grep IPAddress | cut -d '"' -f 4` + DOCKER_CONTAINER_ID=$(docker run -d deepdiver/docker-oracle-xe-11g) + DATABASEHOST=$(docker inspect "$DOCKER_CONTAINER_ID" | grep IPAddress | cut -d '"' -f 4) echo "Waiting 60 seconds for Oracle initialization ... " sleep 60 @@ -151,7 +151,7 @@ function execute_tests { # trigger installation echo "Installing ...." - "$PHP" ./occ maintenance:install --database=$1 --database-name=$DATABASENAME --database-host=$DATABASEHOST --database-user=$DATABASEUSER --database-pass=owncloud --database-table-prefix=oc_ --admin-user=$ADMINLOGIN --admin-pass=admin --data-dir=$DATADIR + "$PHP" ./occ maintenance:install --database="$1" --database-name="$DATABASENAME" --database-host="$DATABASEHOST" --database-user="$DATABASEUSER" --database-pass=owncloud --database-table-prefix=oc_ --admin-user="$ADMINLOGIN" --admin-pass=admin --data-dir="$DATADIR" #test execution echo "Testing with $1 ..." @@ -176,7 +176,7 @@ if [ -z "$1" ] then # run all known database configs for DBCONFIG in $DBCONFIGS; do - execute_tests $DBCONFIG + execute_tests "$DBCONFIG" done else FILENAME="$2" From 8b0c223d6e55a7aeec03949bf01cbb89246960aa Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Fri, 15 May 2015 11:44:51 +0200 Subject: [PATCH 2/3] Add support for facade binary scripts Fixes https://github.com/owncloud/core/issues/16296 --- autotest.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/autotest.sh b/autotest.sh index b01bdda089..d34bd48b49 100755 --- a/autotest.sh +++ b/autotest.sh @@ -53,7 +53,14 @@ if ! [ -x "$PHPUNIT" ]; then exit 3 fi -PHPUNIT_VERSION=$("$PHP" "$PHPUNIT" --version | cut -d" " -f2) +# PHPUnit might also be installed via a facade binary script +if [[ "$PHPUNIT" =~ \.phar$ ]]; then + PHPUNIT="$PHP $PHPUNIT" +else + PHPUNIT="$PHPUNIT" +fi + +PHPUNIT_VERSION=$($PHPUNIT --version | cut -d" " -f2) PHPUNIT_MAJOR_VERSION=$(echo "$PHPUNIT_VERSION" | cut -d"." -f1) PHPUNIT_MINOR_VERSION=$(echo "$PHPUNIT_VERSION" | cut -d"." -f2) @@ -160,11 +167,11 @@ function execute_tests { mkdir "coverage-html-$1" "$PHP" -f enable_all.php | grep -i -C9999 error && echo "Error during setup" && exit 101 if [ -z "$NOCOVERAGE" ]; then - "$PHP" "$PHPUNIT" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" --coverage-clover "autotest-clover-$1.xml" --coverage-html "coverage-html-$1" "$2" "$3" + $PHPUNIT --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" --coverage-clover "autotest-clover-$1.xml" --coverage-html "coverage-html-$1" "$2" "$3" RESULT=$? else echo "No coverage" - "$PHP" "$PHPUNIT" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" "$2" "$3" + $PHPUNIT --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" "$2" "$3" RESULT=$? fi } From 89b0bc1915594256098461ad70ff75ea6f395a96 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Fri, 15 May 2015 13:16:16 +0200 Subject: [PATCH 3/3] Store in array to allow paths with whitespace --- autotest.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autotest.sh b/autotest.sh index d34bd48b49..3ce88c6497 100755 --- a/autotest.sh +++ b/autotest.sh @@ -55,9 +55,9 @@ fi # PHPUnit might also be installed via a facade binary script if [[ "$PHPUNIT" =~ \.phar$ ]]; then - PHPUNIT="$PHP $PHPUNIT" + PHPUNIT=( "$PHP" "$PHPUNIT" ) else - PHPUNIT="$PHPUNIT" + PHPUNIT=( "$PHPUNIT" ) fi PHPUNIT_VERSION=$($PHPUNIT --version | cut -d" " -f2) @@ -167,11 +167,11 @@ function execute_tests { mkdir "coverage-html-$1" "$PHP" -f enable_all.php | grep -i -C9999 error && echo "Error during setup" && exit 101 if [ -z "$NOCOVERAGE" ]; then - $PHPUNIT --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" --coverage-clover "autotest-clover-$1.xml" --coverage-html "coverage-html-$1" "$2" "$3" + "${PHPUNIT[@]}" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" --coverage-clover "autotest-clover-$1.xml" --coverage-html "coverage-html-$1" "$2" "$3" RESULT=$? else echo "No coverage" - $PHPUNIT --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" "$2" "$3" + "${PHPUNIT[@]}" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" "$2" "$3" RESULT=$? fi }