public
Description: PHP5 Unit Testing Framework
Homepage: http://www.snaptest.net
Clone URL: git://github.com/Jakobo/snaptest.git
snaptest / snaptest.sh
100755 115 lines (97 sloc) 2.894 kb
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
#!/bin/bash
 
# Portable version of resolve_symlink to work across multiple
# *nix flavors.
function resolve_symlink {
    SCRIPT=$1 NEWSCRIPT=''
    until [ "$SCRIPT" = "$NEWSCRIPT" ]; do
if [ "${SCRIPT:0:1}" = '.' ]; then SCRIPT=$PWD/$SCRIPT; fi
cd $(dirname $SCRIPT)
        if [ ! "${SCRIPT:0:1}" = '.' ]; then SCRIPT=$(basename $SCRIPT); fi
SCRIPT=${NEWSCRIPT:=$SCRIPT}
        NEWSCRIPT=$(ls -l $SCRIPT | awk '{ print $NF }')
    done
if [ ! "${SCRIPT:0:1}" = '/' ]; then SCRIPT=$PWD/$SCRIPT; fi
echo $(dirname $SCRIPT)
}
 
 
# change to shell script real location
FPATH=$(resolve_symlink $0);
 
# correct pwd to resolve any symlinks and spaces in the name
OPATH=`pwd`
# OPATH=`echo $OPATH | sed s/\ /\\\\\\\\\ /`
 
cd $FPATH
 
# load options
. getoptx.sh
 
cd "$OPATH"
 
# Auto Locate PHP
PHPX=`which php`
if [[ ! -x "$PHPX" ]] ; then
PHPX=""
    if [ -z $PHPX ] ; then
if [ -x "/usr/local/bin/php" ] ; then
PHPX="/usr/local/bin/php"
        fi
if [ -x "/usr/bin/php" ] ; then
PHPX="/usr/bin/php"
        fi
if [ -x "/opt/local/bin/php" ] ; then
PHPX="/opt/local/bin/php"
        fi
fi
fi
 
if [[ ! -z $PHPX ]] ; then
PHP=$PHPX
fi
 
# parse the options
CMD=""
while getoptex "out. php. match. help;" "$@"
do
if [ "$OPTOPT" = "php" ] ; then
if [ -x "$OPTARG" ] ; then
PHP=$OPTARG
        else
echo "The path of $OPTARG was not a valid php path."
            exit 0
        fi
fi
if [ "$OPTOPT" = "help" ] ; then
CMD="$CMD --help"
    else
if [ "$OPTOPT" != "php" ] ; then
CMD="$CMD --$OPTOPT=$OPTARG"
        fi
fi
done
shift $[OPTIND-1]
PTH=""
for arg in "$@"
do
PTH="$arg"
done
 
# if the path begins with ./ or ../, sub in $OPATH at the front
RELPTH=`echo "$PTH" | sed "s/^\.\{1,2\}\/.*/RELPTHMATCH/"`
if [ "$RELPTH" = "RELPTHMATCH" ] ; then
PTH="$OPATH/$PTH"
fi
 
PTH=`echo $PTH | sed "s/ /\\\\\\ /g"`;
 
# choke and die if we couldn't auto-find PHP and the user didn't supply
# a valid PHP executable path
if [ -z $PHP ] ; then
echo "PHP was not found in any common location. You will need to"
    echo "supply the --php=<path> switch."
    exit 0
fi
 
# is the PHP we are using CLI or CGI
CGI=`$PHP -v | grep cgi | wc -l | sed "s/[^0-9]//g"`
 
# run php on the snaptest.php file with the commands
if [ "$CGI" = "0" ] ; then
    # PTH=`echo $PTH | sed "s/ /__S_P_A_C_E__/g"`
    CMD="$PHP -q $FPATH/snaptest.php --php=$PHP --nice=$NICE $CMD $PTH"
else
    # if we are running in CGI mode, we need to mangle our . characters
    # otherwise PHP mangles them in the request
    PHPSAFE=`echo "$PHP" | sed "s/\./__D_O_T__/g"`
    CMDSAFE=`echo "$CMD" | sed "s/\./__D_O_T__/g"`
    PTHSAFE=`echo "$PTH" | sed "s/\./__D_O_T__/g"`
 
    CMD="$PHP -q $FPATH/snaptest.php --php=$PHPSAFE $CMDSAFE $PTHSAFE"
fi
 
$CMD