Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

finishing up test harness

  • Loading branch information...
commit 2f8ad5badcfc715d1fb264a07cba0e7490f6a04f 1 parent 7ff673f
@micha authored
View
4 test/Makefile
@@ -1,6 +1,6 @@
test:
- ./runtests tests > tests.tmp 2>&1
+ ./runtests tests |tee tests.tmp |grep -E '^# \[(REQ|OUT)\] TEST [0-9]'
diff tests.out tests.tmp |tee tests.log
record:
- ./runtests tests > tests.out 2>&1
+ ./runtests tests |tee tests.out |grep -E '^# \[(REQ|OUT)\] TEST [0-9]'
View
35 test/lilhttpd
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+
+[ "$1" = "-I" ] && reflect="yes"
+
+while read a; do
+ a=$(echo "$a" |tr -d '\r')
+ if [ -n "$r" ]; then
+ r=$(printf "%s\\n%s" "$r" "$a")
+ else
+ r="$a"
+ f=$(echo "$a" |cut -d" " -f2 |sed -e 's@^/@@' -e 's/?.*//')
+ fi
+ [ "${a/#Content-Length: /}" = "$a" ] || n=${a/#Content-Length: /}
+ [ "$a" = "" ] && break
+done
+
+r=$(printf "%s\\n%s" "$r" "$(head -c ${n:-0})")
+
+if [ "$reflect" = "yes" ]; then
+ ct="text/plain"
+else
+ r=$(cat "$f")
+ ct=$(file -b --mime "$f")
+fi
+
+cat <<EOF
+HTTP/1.0 200 OK
+Cache-Control: private
+Content-Type: $ct
+Server: restytest1.0
+Connection: close
+Content-Length: $(echo "$r" |wc -c |awk '{print $1}')
+
+$r
+EOF
View
12 test/runtests
@@ -8,9 +8,9 @@ PORT=${3:-9090}
# run tests to check that the correct request is being made
( j=1
while true; do
- gnetcat -l -w 1 -p $PORT \
- -e 'while read -t 1 a; do echo "$a"; done' localhost || break
- grep '^# TEST [0-9][0-9]*' $TEST |head -$j |tail -1 && j=$((j+1))
+ gnetcat -l -w 1 -p $PORT -e './lilhttpd -I' localhost || break
+ grep '^# TEST [0-9][0-9]*' $TEST |head -$j |tail -1 |sed 's/^#/# [REQ]/'
+ j=$((j+1))
done )&
. $TEST
@@ -20,9 +20,9 @@ wait
# run tests again, this time checking actual output
( j=1
while true; do
- gnetcat -l -w 1 -p $PORT \
- -e "read a b c; cat .\$(echo \$b |sed 's/?.*//')" localhost || break
- grep '^# TEST [0-9][0-9]*' $TEST |head -$j |tail -1 && j=$((j+1))
+ gnetcat -l -w 1 -p $PORT -e ./lilhttpd localhost || break
+ grep '^# TEST [0-9][0-9]*' $TEST |head -$j |tail -1 |sed 's/^#/# [OUT]/'
+ j=$((j+1))
done )&
. $TEST
View
7 test/simple.html
@@ -1,10 +1,3 @@
-HTTP/1.0 200 OK
-Cache-Control: private
-Content-Type: text/html
-Server: restytest1.0
-Connection: Close
-Content-Length: 2340
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
View
1  test/simple.txt
@@ -0,0 +1 @@
+hi there
View
3  test/tests
@@ -30,3 +30,6 @@ POST /simple.html '{foo: "bar"}'
# TEST 11: POST with extra header and basic auth, data in message body
POST /simple.html -u "user:secret" -H "Accept: application/json" < simple.json
+
+# TEST 12: json pretty-print formatting
+GET /simple.json | ../pp 2>/dev/null
View
203 test/tests.out
@@ -1,55 +1,53 @@
-# TEST 1: basic GET request
-GET /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-
-# TEST 2: basic PUT request
-PUT /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-Content-Length: 20
-Content-Type: application/x-www-form-urlencoded
-
+# [REQ] TEST 1: basic GET request
+GET /simple.html HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: */*
+# [REQ] TEST 2: basic PUT request
+PUT /simple.html HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: */*
+Content-Length: 20
+Content-Type: application/x-www-form-urlencoded
here is some data
-# TEST 3: basic POST request
-POST /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-Content-Length: 20
-Content-Type: application/x-www-form-urlencoded
-
+@-
+# [REQ] TEST 3: basic POST request
+POST /simple.html HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: */*
+Content-Length: 20
+Content-Type: application/x-www-form-urlencoded
here is some data
-# TEST 4: basic DELETE request
-DELETE /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-
-# TEST 5: basic TRACE request
-TRACE /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-Content-Length: 20
-Content-Type: application/x-www-form-urlencoded
-
+@-
+# [REQ] TEST 4: basic DELETE request
+DELETE /simple.html HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: */*
+# [REQ] TEST 5: basic TRACE request
+TRACE /simple.html HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: */*
+Content-Length: 20
+Content-Type: application/x-www-form-urlencoded
here is some data
-# TEST 6: basic OPTIONS request
-OPTIONS /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-
-# TEST 7: Raw response
-GET /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-
-# TEST 8: Get headers too
+@-
+# [REQ] TEST 6: basic OPTIONS request
+HTTP/1.0 200 OK
+Cache-Control: private
+Content-Type: text/plain
+Server: restytest1.0
+Connection: close
+Content-Length: 168
+# [REQ] TEST 7: Raw response
+GET /simple.html HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: */*
+# [REQ] TEST 8: Get headers too
* <url> malformed
* About to connect() to 127.0.0.1 port 9090 (#0)
* Trying 127.0.0.1... connected
@@ -59,40 +57,45 @@ Accept: */*
> Host: 127.0.0.1:9090
> Accept: */*
>
+* HTTP 1.0, assume close after body
+< HTTP/1.0 200 OK
+< Cache-Control: private
+< Content-Type: text/plain
+< Server: restytest1.0
+< Connection: close
+< Content-Length: 164
+<
{ [data not shown]
-* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0
-GET /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-
-# TEST 9: POST with data sent in query string
-POST /simple.html?foo=bar HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-
-# TEST 10: POST with data sent in message body
-POST /simple.html HTTP/1.1
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: */*
-Content-Length: 15
-Content-Type: application/x-www-form-urlencoded
-
+GET /simple.html HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: */*
+# [REQ] TEST 9: POST with data sent in query string
+POST /simple.html?foo=bar HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: */*
+# [REQ] TEST 10: POST with data sent in message body
+POST /simple.html HTTP/1.1
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: */*
+Content-Length: 15
+Content-Type: application/x-www-form-urlencoded
{foo: "bar"}
-# TEST 11: POST with extra header and basic auth, data in message body
-POST /simple.html HTTP/1.1
-Authorization: Basic dXNlcjpzZWNyZXQ=
-User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
-Host: 127.0.0.1:9090
-Accept: application/json
-Content-Length: 66
-Content-Type: application/x-www-form-urlencoded
-
+@-
+# [REQ] TEST 11: POST with extra header and basic auth, data in message body
+POST /simple.html HTTP/1.1
+Authorization: Basic dXNlcjpzZWNyZXQ=
+User-Agent: curl/7.21.2 (x86_64-apple-darwin10.4.0) libcurl/7.21.2 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19
+Host: 127.0.0.1:9090
+Accept: application/json
+Content-Length: 66
+Content-Type: application/x-www-form-urlencoded
{"foo":[1,2,3],"bar":{"dog":"woof","cat":"meow","fish":"banana"}}
-# TEST 1: basic GET request
+# [REQ] TEST 12: json pretty-print formatting
+# [OUT] TEST 1: basic GET request
[1]fork me on github
Resty
@@ -123,7 +126,7 @@ Hello There.
References
http://github.com/micha/resty
-# TEST 2: basic PUT request
+# [OUT] TEST 2: basic PUT request
[1]fork me on github
Resty
@@ -154,7 +157,7 @@ Hello There.
References
http://github.com/micha/resty
-# TEST 3: basic POST request
+# [OUT] TEST 3: basic POST request
[1]fork me on github
Resty
@@ -185,7 +188,7 @@ Hello There.
References
http://github.com/micha/resty
-# TEST 4: basic DELETE request
+# [OUT] TEST 4: basic DELETE request
[1]fork me on github
Resty
@@ -216,7 +219,7 @@ Hello There.
References
http://github.com/micha/resty
-# TEST 5: basic TRACE request
+# [OUT] TEST 5: basic TRACE request
[1]fork me on github
Resty
@@ -247,14 +250,14 @@ Hello There.
References
http://github.com/micha/resty
-# TEST 6: basic OPTIONS request
+# [OUT] TEST 6: basic OPTIONS request
HTTP/1.0 200 OK
Cache-Control: private
-Content-Type: text/html
+Content-Type: text/html; charset=us-ascii
Server: restytest1.0
-Connection: Close
+Connection: close
Content-Length: 2340
-# TEST 7: Raw response
+# [OUT] TEST 7: Raw response
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
@@ -336,7 +339,7 @@ Content-Length: 2340
</div>
</body>
</html>
-# TEST 8: Get headers too
+# [OUT] TEST 8: Get headers too
* <url> malformed
* About to connect() to 127.0.0.1 port 9090 (#0)
* Trying 127.0.0.1... connected
@@ -349,9 +352,9 @@ Content-Length: 2340
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Cache-Control: private
-< Content-Type: text/html
+< Content-Type: text/html; charset=us-ascii
< Server: restytest1.0
-< Connection: Close
+< Connection: close
< Content-Length: 2340
<
{ [data not shown]
@@ -386,7 +389,7 @@ Hello There.
References
http://github.com/micha/resty
-# TEST 9: POST with data sent in query string
+# [OUT] TEST 9: POST with data sent in query string
[1]fork me on github
Resty
@@ -417,7 +420,7 @@ Hello There.
References
http://github.com/micha/resty
-# TEST 10: POST with data sent in message body
+# [OUT] TEST 10: POST with data sent in message body
[1]fork me on github
Resty
@@ -448,7 +451,7 @@ Hello There.
References
http://github.com/micha/resty
-# TEST 11: POST with extra header and basic auth, data in message body
+# [OUT] TEST 11: POST with extra header and basic auth, data in message body
[1]fork me on github
Resty
@@ -479,3 +482,17 @@ Hello There.
References
http://github.com/micha/resty
+# [OUT] TEST 12: json pretty-print formatting
+{
+ "bar" : {
+ "cat" : "meow",
+ "dog" : "woof",
+ "fish" : "banana"
+ },
+ "foo" : [
+ 1,
+ 2,
+ 3
+ ]
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.