Blob
- Date:
- Message:
- rework the regression suite The tests are still there, the suite is equivalent to the old one, but this one is better structured. The biggest annoyance I had with the old one was that it wasn't straightforward to test only a specific set of tests. It's still impossible, but it's way easier to do it now. This extract all the tests to their own functions. It's overall better in all possible regards.
- Actions:
- History | Blame | Raw File
1 failed=3 gg="./gg"4 gmid="./../gmid"5 current_test=7 run_test() {8 ggflags=9 port=1096510 config_common="11 ipv6 off12 port $port13 "14 hdr=15 body=16 dont_check=no18 current_test=$119 rm -f reg.conf21 if ! $1; then22 echo "$1 failed"23 failed="$failed $1"24 else25 echo "$1 passed"26 fi28 if [ "$dont_check" != 'no' ]; then29 return30 fi32 if ! check; then33 echo "gmid crashed?"34 failed="$failed $1"35 fi36 }38 # usage: gen_config <global config> <server config>39 # generates a configuration file reg.conf40 gen_config() {41 cat <<EOF > reg.conf42 $config_common43 $144 server "localhost" {45 cert "$PWD/cert.pem"46 key "$PWD/key.pem"47 root "$PWD/testdata"48 $249 }50 EOF51 if ! checkconf; then52 echo "failed to parse the config" >&253 return 154 fi55 }57 checkconf() {58 $gmid -n -c reg.conf >/dev/null59 }61 # usage: setup_simple_test <global config> <server config>62 # generates a configuration file with `gen_config', validates it and63 # launches the daemon64 setup_simple_test() {65 gen_config "$1" "$2"66 run67 }69 # usage: get <path>70 # return the body of the request on stdout71 get() {72 $gg -T30 -b $ggflags "gemini://localhost:10965/$1"73 }75 # usage: head <path>76 # return the meta response line on stdout77 head() {78 $gg -T30 -h $ggflags "gemini://localhost:10965/$1"79 }81 # usage: raw <path>82 # return both header and body83 raw() {84 $gg -T30 $ggflags "gemini://localhost:10965/$1"85 }87 # usage: fetch <path>88 # fetches the header and the body. They're returned in $hdr and89 # $body.90 fetch() {91 if ! hdr="$(head $1)" || ! body="$(get $1)"; then92 return 193 fi94 }96 # usage: fetch_hdr <path>97 # fetches the header into $hdr98 fetch_hdr() {99 hdr="$(head $1)"100 body=""101 }103 # usage: check_reply header body104 # checks that $hdr and $body are equal to the given strings105 check_reply() {106 if [ "$hdr" != "$1" ]; then107 echo "Header mismatch" >&2108 echo "wants : $1" >&2109 echo "got : $hdr" >&2110 return 1111 fi113 if [ "$body" != "$2" ]; then114 echo "Body mismatch" >&2115 echo "wants : $1" >&2116 echo "got : $body" >&2117 return 1118 fi119 }121 run() {122 if check; then123 kill -HUP "$(cat gmid.pid)"124 sleep 1125 return126 fi128 $gmid -P gmid.pid -c reg.conf130 # give gmid time to bind the port, otherwise we end up131 # executing gg when gmid isn't ready yet.132 sleep 1133 }135 check() {136 if [ ! -f gmid.pid ]; then137 return 1138 fi140 pid="$(cat gmid.pid || true)"141 if [ "$pid" == "" ]; then142 return 1143 fi145 # remember: we're running under ``set -e''146 if ps $pid >/dev/null; then147 return 0148 fi150 return 1151 }153 # usage: sha in out154 # writes the sha256 of `in' to `out'155 sha() {156 if which sha256 >/dev/null 2>&1; then157 sha256 < "$1" > "$2"158 return $?159 fi161 if which sha256sum >/dev/null 2>&1; then162 sha256sum "$1" | awk '{print $1}' > "$2"163 return $?164 fi166 echo "No sha binary found" >&2167 exit 1168 }170 count() {171 wc -l | xargs172 }174 quit() {175 pid="$(cat gmid.pid || true)"176 if [ "$pid" != "" ]; then177 kill $pid || true178 wait || true179 fi180 }182 onexit() {183 rm -f bigfile bigfile.sha184 quit185 }