Add runtests-wrapper.sh
[privoxy.git] / tests / cts / runtests-wrapper.sh
1 #!/bin/sh
2 ################################################################################
3 #
4 # runtests-wrapper.sh
5 #
6 # Wrapper around curl's runtests.pl that sets a couple of options
7 # so Privoxy is being used.
8 #
9 # Copyright (c) 2013-2021 Fabian Keil <fk@fabiankeil.de>
10 #
11 # Permission to use, copy, modify, and distribute this software for any
12 # purpose with or without fee is hereby granted, provided that the above
13 # copyright notice and this permission notice appear in all copies.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 ################################################################################
23
24 curl_setup_is_sane() {
25     local curl_source_directory="${1}"
26     local curl_binary="${curl_source_directory}/src/curl"
27     local runtests_pl="${curl_source_directory}/tests/runtests.pl"
28
29     if [ ! -d "${curl_source_directory}" ]; then
30         echo "Missing curl source directory at ${curl_source_directory}"
31         return 1
32     fi
33     if [ ! -f "${curl_binary}" ]; then
34         echo "Missing curl binary at ${curl_binary}. Did you compile curl?"
35         return 1
36     fi
37     if [ ! -f "${runtests_pl}" ]; then
38         echo "Did not find runtests.pl at ${runtests_pl}"
39         return 1
40     fi
41
42     return 0
43 }
44
45 runtests_wrapper() {
46     local extra_args \
47         a_flag proxy_args exclude_file_args testdir_args \
48         privoxy_lib privoxy_ip privoxy_source_directory curl_source_directory \
49         keyword directory_name test_dir
50
51     directory_name="$(dirname "$0")"
52     test_dir="$(realpath "${directory_name}")"
53     privoxy_source_directory="$(realpath "${test_dir}"/../..)"
54     privoxy_lib="${privoxy_source_directory}/tests/cts/privoxy-runtests.pm"
55     curl_source_directory="$(realpath "${privoxy_source_directory}"/../curl)"
56
57     curl_setup_is_sane "${curl_source_directory}" || exit 1
58
59     # Defaults that can be changed through arguments
60     privoxy_ip=127.0.0.1
61     privoxy_port=9119
62     a_flag="-a"
63     proxy_args="-P http://${privoxy_ip}:${privoxy_port}/ -o HOSTIP=${privoxy_ip}"
64     exclude_file_args="-E ${privoxy_source_directory}/tests/cts/curl-test-manifest-for-privoxy"
65     testdir_args="-o TESTDIR=${privoxy_source_directory}/tests/cts/data"
66     keyword=HTTP
67
68     while [ -n "$1" ];
69     do
70         case "$1" in
71             "-A")
72                 a_flag=""
73                 shift
74                 ;;
75             "-E")
76                 exclude_file_args=""
77                 shift
78                 ;;
79             "-k")
80                 shift
81                 keyword="$1"
82                 shift
83                 ;;
84             "-i")
85                 shift
86                 privoxy_ip="$1"
87                 shift
88                 proxy_args="-P http://${privoxy_ip}:${privoxy_port}/ -o HOSTIP=${privoxy_ip}"
89                 ;;
90             "-T")
91                 echo "Not setting TESTDIR"
92                 testdir_args=""
93                 shift
94                 ;;
95             "-t")
96                 shift
97                 echo "Overwriting default TESTDIR with $1"
98                 testdir_args="-o TESTDIR=$1"
99                 shift
100                 ;;
101             "-p")
102                 shift
103                 privoxy_port="$1"
104                 shift
105                 proxy_args="-P http://${privoxy_ip}:${privoxy_port}/ -o HOSTIP=${privoxy_ip}"
106                 ;;
107             "-P")
108                 # "Obviously" -P means not setting -P
109                 echo "Not setting '$proxy_args'"
110                 proxy_args=""
111                 shift
112                 ;;
113             *)
114                 break;;
115         esac
116     done
117
118     extra_args="$*"
119     
120     cd "${curl_source_directory}/tests" || exit 1
121     ./runtests.pl -L "${privoxy_lib}" $proxy_args $exclude_file_args $testdir_args $a_flag -n $keyword !skip $extra_args
122 }
123
124 main() {
125     runtests_wrapper "$@"
126 }
127
128 main "$@"