summaryrefslogtreecommitdiff
path: root/tests/test.sh
blob: df0e9498c2e46ec0960aaeda5afdbade26bf5e16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
#
# It is intended to run the command "make test" from the root directory of the library
#
#  @author valmat <ufabiz@gmail.com>
#


THIS=`basename $0`
    
function print_help() {
    echo "Use: $THIS [options...]"
    echo "Options:"
    echo "  -p <php>     Specify PHP executable to run (default: /usr/bin/php)."
    echo "  -e <file>    Name of test extension (default: extfortest.so)."
    echo "  -n           Do not compile the test extension."
    echo "  -w <file>    Write a list of all failed tests to <file>."
    echo "  -a <file>    Same as -w but append rather then truncating <file>."
    echo "  -d foo=bar   Pass -d option to the php binary (Define INI entry foo"
    echo "               with value 'bar')."
    echo "  -g <opt>     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 "  -r           Removes all auxiliary files. (*.log, *.diff etc)."
    echo "  -t <files>   Test file(s). Specify individual file(s) to test"
    echo "  -s <file>    Write output to <file>."
    echo "  -x           Sets 'SKIP_SLOW_TESTS' environmental variable."
    echo "  -o           Cancels sets 'SKIP_ONLINE_TESTS' (default set)."
    echo "  -q           Quiet, no user interaction (same as environment NO_INTERACTION)."
    echo "  -v           Verbose mode."
    echo "  -h           This Help."
    echo
    exit;
}

PHP_BIN="/usr/bin/php"
# options list
SCR_OPT=""
COMPILE_EXT=1
# SKIP_ONLINE_TESTS == true
OFFLINE=1
EXT_NAME="extfortest.so"
# The file list of the tests that will be launched
TEST_FILES=""

while getopts ":p:e:nw:a:d:g:mrt:s:xoqvh" 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"
            ;;
        r)
            # Removes all auxiliary files. (*.log, *.diff etc).
            
            # if quiet, only delete
            if [ $(echo $SCR_OPT | grep -o "\-q") ]; then
                find ./php/phpt -type f \( \
                                           -name '*.diff' -or -name '*.exp' -or -name '*.log' -or -name '*.out' \
                                           -or -name '*.php' -or -name '*.sh' -or -name '*.mem' -or \
                                           -name '*.phpt-diff' -or -name '*.phpt-exp' -or -name '*.phpt-log' -or -name '*.phpt-out' \
                                           -or -name '*.phpt-php' -or -name '*.phpt-sh' -or -name '*.phpt-mem' \
                                        \) -delete
            
            # else delete and print
            else
                echo -e "\x1b[1;31;47mRemove auxiliary files...\x1b[0;0m"
                for AUXF in `find ./php/phpt -type f \( \
                                           -name '*.diff' -or -name '*.exp' -or -name '*.log' -or -name '*.out' \
                                           -or -name '*.php' -or -name '*.sh' -or -name '*.mem' -or \
                                           -name '*.phpt-diff' -or -name '*.phpt-exp' -or -name '*.phpt-log' -or -name '*.phpt-out' \
                                           -or -name '*.phpt-php' -or -name '*.phpt-sh' -or -name '*.phpt-mem' \
                                        \)`;
                    do
                    echo -e "\x1b[1;31;47mdel \x1b[0;30;47m$(dirname $AUXF)/\x1b[1;31;47m$(basename $AUXF)\x1b[0;30;47m ...\x1b[0;0m"
                    rm $AUXF
                done
            fi
            exit;
            ;;
        t)
            TEST_FILES="${TEST_FILES}${OPTARG} "
            ;;
        x)
            SCR_OPT="$SCR_OPT -x"
            ;;
        o)
            # SKIP_ONLINE_TESTS == false
            OFFLINE=0
            ;;
        q)
            SCR_OPT="$SCR_OPT -q"
            ;;
        v)
            SCR_OPT="$SCR_OPT -v"
            ;;
        h)
            print_help
            ;;
        *)
            echo "wrong option -$OPTARG";
            echo "";
            print_help
            ;;
    esac
done

# The file list of the tests that will be launched
if [ ! "$TEST_FILES" ]; then
    TEST_FILES=`find ./php/phpt -type f -name "*.phpt"`
fi

# default offline mode
if [ 1 = $OFFLINE ]; then
    SCR_OPT="$SCR_OPT --offline"
fi

# A list of all additional options
SCR_OPT="$SCR_OPT -d extension_dir=$PWD/ext_dir -d extension=$EXT_NAME"


# Create a local copy of the directory with the extension for run without installation
./prepare.sh $EXT_NAME

# Absolute path to library
LIBRARY_PATH="$(cd $PWD/.. && echo $PWD)"

if [ 1 = $COMPILE_EXT ]; then
    
    # Create a local copy of header files
    PHPCPP_H="$LIBRARY_PATH/tests/include/lib/phpcpp.h"
    PHPCPP_INC="$LIBRARY_PATH/tests/include/lib/phpcpp"
    mkdir -p "$LIBRARY_PATH/tests/include/lib"
    # local copy of /usr/include/phpcpp.h:
    if [ ! -L $PHPCPP_H ];
    then
        ln -s "$LIBRARY_PATH/phpcpp.h" $PHPCPP_H
    fi
    # local copy of /usr/include/phpcpp:
    if [ -a $PHPCPP_INC ];
    then
        rm -rf $PHPCPP_INC
    fi
    ln -s "$LIBRARY_PATH/include" $PHPCPP_INC
    
    echo "Compile the test extension"
    cd cpp
    make clean && make
    cd ..
fi

LD_LIBRARY_PATH="${LIBRARY_PATH}:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH


# run tests
$PHP_BIN run-tests.php $SCR_OPT -p "$PHP_BIN" $TEST_FILES