From e8334afd7f2920b706a3d28250a3e2b6dbd49538 Mon Sep 17 00:00:00 2001 From: valmat Date: Tue, 18 Mar 2014 15:18:11 +0600 Subject: Unit tests. For description see https://github.com/CopernicaMarketingSoftware/PHP-CPP/pull/25#issuecomment-37882236 --- Makefile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 32fd0b0..2452294 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,17 @@ PHP_DIR = /usr/include/php5 +# +# PHP binary file +# +# The path to the executable PHP binary file. +# Need to run tests. +# You can see the command "whereis php" +# + +PHP_BIN = /usr/bin/php + + # # Installation directory # @@ -126,6 +137,10 @@ OBJECTS = $(SOURCES:%.cpp=%.o) # all: ${OBJECTS} ${RESULT} + @echo + @echo "Build complete." + @echo "Don't forget to run 'make test'." + @echo ${RESULT}: ${OBJECTS} ${LINKER} ${LINKER_FLAGS} -o $@ ${OBJECTS} @@ -141,4 +156,6 @@ install: ${CP} phpcpp.h ${INSTALL_HEADERS} ${CP} include/*.h ${INSTALL_HEADERS}/phpcpp ${CP} ${RESULT} ${INSTALL_LIB} +test: + cd tests && ./test.sh ${PHP_BIN} -- cgit v1.2.3 From e526e3baba901960d07bfc7759610711a6ab5ced Mon Sep 17 00:00:00 2001 From: valmat Date: Tue, 18 Mar 2014 21:54:34 +0600 Subject: Some improvements unit test --- Makefile | 5 +-- tests/prepare.sh | 5 +++ tests/test.sh | 107 ++++++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 100 insertions(+), 17 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 2452294..9ecb526 100644 --- a/Makefile +++ b/Makefile @@ -91,9 +91,6 @@ COMPILER_FLAGS = -Wall -c -I. -I${PHP_DIR} -I${PHP_DIR}/main -I${PHP_DIR}/ext # Just like the compiler, the linker can have flags too. The default flag # is probably the only one you need. # -# Are you compiling on OSX? You may have to append the option "-undefined dynamic_lookup" -# to the linker flags -# LINKER_FLAGS = -shared `php-config --ldflags` @@ -157,5 +154,5 @@ install: ${CP} include/*.h ${INSTALL_HEADERS}/phpcpp ${CP} ${RESULT} ${INSTALL_LIB} test: - cd tests && ./test.sh ${PHP_BIN} + cd tests && ./test.sh -p ${PHP_BIN} diff --git a/tests/prepare.sh b/tests/prepare.sh index e052c72..58fc646 100755 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -8,6 +8,11 @@ EXTDLOC=ext_dir SO=extfortest.so +if [ $1 ] +then + SO=$1 +fi + EXTDIR=$(php-config --extension-dir) #echo $EXTDIR diff --git a/tests/test.sh b/tests/test.sh index 136af45..f055b43 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,33 +1,114 @@ #!/bin/bash # -# do not run this script. It is intended to run the command "make test" from the root directory of the library +# It is intended to run the command "make test" from the root directory of the library # -if [ ! $1 ] -then - echo "Required the path to executable PHP binary file" - exit; -fi + +THIS=`basename $0` + +function print_help() { + echo "Use: $THIS [options...]" + echo "Options:" + echo " -p Specify PHP executable to run (default: /usr/bin/php)." + echo " -e Name of test extension (default: extfortest.so)." + echo " -n Do not compile the test extension." + echo " -w Write a list of all failed tests to ." + echo " -a Same as -w but append rather then truncating ." + echo " -d foo=bar Pass -d option to the php binary (Define INI entry foo" + echo " with value 'bar')." + echo " -g Comma separated list of groups to show during test run" + echo " (possible values: PASS, FAIL, XFAIL, SKIP, BORK, WARN, LEAK, REDIRECT)." + echo " -m Test for memory leaks with Valgrind." + echo " -s Write output to ." + echo " -x Sets 'SKIP_SLOW_TESTS' environmental variable." + echo " -o Cancels sets 'SKIP_ONLINE_TESTS' (default set)." + echo " -v Verbose mode." + echo " -h This Help." + echo + exit; +} + +PHP_BIN="/usr/bin/php" +SCR_OPT="" +COMPILE_EXT=1 +OFFLINE=1 EXT_NAME="extfortest.so" +while getopts ":p:e:nw:a:d:g:ms:xovh" opt ; +do + case $opt in + p) + PHP_BIN=$OPTARG; + ;; + e) + EXT_NAME=$OPTARG; + ;; + n) + COMPILE_EXT=0 + ;; + w) + SCR_OPT="$SCR_OPT -w $OPTARG" + ;; + a) + SCR_OPT="$SCR_OPT -a $OPTARG" + ;; + d) + SCR_OPT="$SCR_OPT -d $OPTARG" + ;; + g) + SCR_OPT="$SCR_OPT -g $OPTARG" + ;; + s) + SCR_OPT="$SCR_OPT -s $OPTARG" + ;; + m) + SCR_OPT="$SCR_OPT -m" + ;; + x) + SCR_OPT="$SCR_OPT -x" + ;; + o) + OFFLINE=0 + ;; + v) + SCR_OPT="$SCR_OPT -v" + ;; + h) + print_help + ;; + *) + echo "wrong option -$OPTARG"; + echo ""; + print_help + ;; + esac +done + +# default offline mode +if [ 1 = $OFFLINE ]; then + SCR_OPT="$SCR_OPT --offline" +fi + TEST_FILES=`find ./php/phpt -type f -name "*.phpt"` -PHP_BIN=$1 #RUN_SCR="$PHP_BIN -z ./cpp/$EXT_NAME" RUN_SCR="$PHP_BIN -d enable_dl=On -d extension_dir=./ext_dir -d extension=$EXT_NAME" # Create a local copy of the directory with the extension for run without installation -./prepare.sh +./prepare.sh $EXT_NAME -echo "Compile the test extension" -cd cpp -make clean && make -cd .. +if [ 1 = $COMPILE_EXT ]; then + echo "Compile the test extension" + cd cpp + make clean && make + cd .. +fi + # run tests -$PHP_BIN run-tests.php --offline -p "$RUN_SCR" $TEST_FILES +$PHP_BIN run-tests.php $SCR_OPT -p "$RUN_SCR" $TEST_FILES -- cgit v1.2.3 From ce1624b0be45aa12a95e22739185c70226d57b1b Mon Sep 17 00:00:00 2001 From: valmat Date: Tue, 18 Mar 2014 22:39:18 +0600 Subject: Accidentally deleted --- Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9ecb526..516ab06 100644 --- a/Makefile +++ b/Makefile @@ -91,6 +91,9 @@ COMPILER_FLAGS = -Wall -c -I. -I${PHP_DIR} -I${PHP_DIR}/main -I${PHP_DIR}/ext # Just like the compiler, the linker can have flags too. The default flag # is probably the only one you need. # +# Are you compiling on OSX? You may have to append the option "-undefined dynamic_lookup" +# to the linker flags +# LINKER_FLAGS = -shared `php-config --ldflags` -- cgit v1.2.3