Debian Codegraph @

tests/runtests.sh

raw
1 #!/usr/bin/env bash
2
3 pushd $(dirname $0) > /dev/null; script_dir=$PWD; popd > /dev/null
4
5 pactester=$script_dir/../src/pactester
6 pacfile=$script_dir/proxy.pac
7 testdata=$script_dir/testdata
8 library_path=$script_dir/../src
9 export DYLD_LIBRARY_PATH=$library_path:$DYLD_LIBRARY_PATH
10 export LD_LIBRARY_PATH=$library_path:$LD_LIBRARY_PATH
11
12 lib=$library_path/libpacparser.so.1
13
14 os_arch=$(uname -s | sed /\ /s//_/)
15 if [ "$os_arch" = "Darwin" ]; then
16 lib=$library_path/libpacparser.1.dylib
17 fi
18
19 if test ! -f "$lib"; then
20 echo "Test failed. pacparser library not found."
21 exit 1
22 fi
23
24 while read line
25 do
26 comment="${line#*#}"
27 line="${line%%#*}"
28 line=${line%"${line##*[^[:space:]]}"}
29 test -z "$line" && continue
30 # If machine is not connected to the internet and a test requires internet
31 # just skip that test.
32 test ! -z $NO_INTERNET && \
33 test "${comment/INTERNET_REQUIRED/}" != "${comment}" && \
34 continue
35 params=${line%%|*}
36 expected_result=${line##*|}
37 result=$($pactester -p $pacfile $params)
38 if [ $? != 0 ]; then
39 echo "pactester execution failed."
40 echo "Command tried: $pactester -p $pacfile $params"
41 echo "Running with debug mode on..."
42 echo "DEBUG=1 $pactester -p $pacfile $params"
43 DEBUG=1 $pactester -p $pacfile $params
44 exit 1
45 fi
46 [ $DEBUG ] && echo "Test line: $line"
47 [ $DEBUG ] && echo "Params: $params"
48 if [ "$result" != "$expected_result" ]; then
49 echo "Test failed: got \"$result\", expected \"$expected_result\""
50 echo "Command tried: $pactester -p $pacfile $params"
51 echo "Running with debug mode on..."
52 echo "DEBUG=1 $pactester -p $pacfile $params"
53 DEBUG=1 $pactester -p $pacfile $params
54 exit 1;
55 fi
56 done < $testdata
57
58
59 # Logging tests: verify alert() / console.log() output lands on stderr with
60 # the expected prefixes, and that the proxy result on stdout is unaffected.
61 logging_pac=$script_dir/logging.pac
62 logging_stderr=$(mktemp)
63 logging_stdout=$($pactester -p $logging_pac -u http://example.com/ -h example.com 2>$logging_stderr)
64 if [ "$logging_stdout" != "DIRECT" ]; then
65 echo "Logging test failed: stdout was \"$logging_stdout\", expected \"DIRECT\""
66 cat $logging_stderr
67 rm -f $logging_stderr
68 exit 1
69 fi
70 expected_stderr=$'ALERT: checking example.com\nLOG: url: http://example.com/\nLOG: single arg'
71 actual_stderr=$(cat $logging_stderr)
72 rm -f $logging_stderr
73 if [ "$actual_stderr" != "$expected_stderr" ]; then
74 echo "Logging test failed: stderr mismatch"
75 echo "Expected:"
76 echo "$expected_stderr"
77 echo "Got:"
78 echo "$actual_stderr"
79 exit 1
80 fi
81
82 echo "All tests were successful."