From e6faf9e26bcb172026a4984ecadbaa8b6789bcb7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 4 Feb 2013 12:39:09 +0000 Subject: [PATCH] tests: "wc -l" portability for *BSDs On FreeBSD 9.0, "wc -l" emits leading whitespace, so filter it through tr -d '[:space:]' to eliminate it. --- t/t0000-simple-http.sh | 18 +++++++++--------- t/t0001-unix-http.sh | 16 ++++++++-------- t/t0003-reopen-logs.sh | 4 ++-- t/t0004-heartbeat-timeout.sh | 2 +- t/t0024-pipelined-sendfile-response.sh | 4 ++-- t/t0030-fast-pipe-response.sh | 2 +- t/t0034-pipelined-pipe-response.sh | 4 ++-- t/t0035-kgio-pipe-response.sh | 2 +- t/t0040-keepalive_requests-setting.sh | 8 ++++---- t/t0044-autopush.sh | 4 ++-- t/t0045-client_max_header_size.sh | 4 ++-- t/t0100-rack-input-hammer-chunked.sh | 4 ++-- t/t0100-rack-input-hammer-content-length.sh | 4 ++-- t/t0106-rack-input-keepalive.sh | 8 ++++---- t/t0402-async-keepalive.sh | 22 +++++++++++----------- t/t0600-rack-fiber_pool.sh | 2 +- t/t0700-app-deferred.sh | 4 ++-- t/t9000-rack-app-pool.sh | 2 +- t/t9100-thread-timeout.sh | 2 +- t/t9101-thread-timeout-threshold.sh | 2 +- t/test-lib.sh | 5 +++++ 21 files changed, 64 insertions(+), 59 deletions(-) diff --git a/t/t0000-simple-http.sh b/t/t0000-simple-http.sh index 57a7d59..c9481bd 100755 --- a/t/t0000-simple-http.sh +++ b/t/t0000-simple-http.sh @@ -60,19 +60,19 @@ t_begin "pipelining partial requests" && { dbgcat tmp t_begin "two HTTP/1.1 responses" && { - test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l) + test 2 -eq $(grep '^HTTP/1.1' $tmp | count_lines) } t_begin "two HTTP/1.1 200 OK responses" && { - test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l) + test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | count_lines) } t_begin 'one "Connection: keep-alive" response' && { - test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l) + test 1 -eq $(grep '^Connection: keep-alive' $tmp | count_lines) } t_begin 'one "Connection: close" response' && { - test 1 -eq $(grep '^Connection: close' $tmp | wc -l) + test 1 -eq $(grep '^Connection: close' $tmp | count_lines) } t_begin 'check subshell success' && { @@ -98,19 +98,19 @@ dbgcat tmp dbgcat r_err t_begin "got 2 HTTP/1.1 responses from pipelining" && { - test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l) + test 2 -eq $(grep '^HTTP/1.1' $tmp | count_lines) } t_begin "got 2 HTTP/1.1 200 OK responses" && { - test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l) + test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | count_lines) } t_begin "one keepalive connection" && { - test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l) + test 1 -eq $(grep '^Connection: keep-alive' $tmp | count_lines) } t_begin "second request closes connection" && { - test 1 -eq $(grep '^Connection: close' $tmp | wc -l) + test 1 -eq $(grep '^Connection: close' $tmp | count_lines) } t_begin "subshell exited correctly" && { @@ -134,7 +134,7 @@ dbgcat tmp dbgcat r_err t_begin "env.inspect should've put everything on one line" && { - test 1 -eq $(wc -l < $tmp) + test 1 -eq $(count_lines < $tmp) } t_begin "no headers in output" && { diff --git a/t/t0001-unix-http.sh b/t/t0001-unix-http.sh index 32d54c7..f6acd38 100755 --- a/t/t0001-unix-http.sh +++ b/t/t0001-unix-http.sh @@ -51,19 +51,19 @@ t_begin "pipelining partial requests" && { dbgcat tmp t_begin "two HTTP/1.1 responses" && { - test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l) + test 2 -eq $(grep '^HTTP/1.1' $tmp | count_lines) } t_begin "two HTTP/1.1 200 OK responses" && { - test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l) + test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | count_lines) } t_begin 'one "Connection: keep-alive" response' && { - test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l) + test 1 -eq $(grep '^Connection: keep-alive' $tmp | count_lines) } t_begin 'one "Connection: close" response' && { - test 1 -eq $(grep '^Connection: close' $tmp | wc -l) + test 1 -eq $(grep '^Connection: close' $tmp | count_lines) } t_begin 'check subshell success' && { @@ -89,19 +89,19 @@ dbgcat tmp dbgcat r_err t_begin "two HTTP/1.1 responses" && { - test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l) + test 2 -eq $(grep '^HTTP/1.1' $tmp | count_lines) } t_begin "two HTTP/1.1 200 OK responses" && { - test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l) + test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | count_lines) } t_begin 'one "Connection: keep-alive" response' && { - test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l) + test 1 -eq $(grep '^Connection: keep-alive' $tmp | count_lines) } t_begin 'one "Connection: close" response' && { - test 1 -eq $(grep '^Connection: close' $tmp | wc -l) + test 1 -eq $(grep '^Connection: close' $tmp | count_lines) } t_begin 'check subshell success' && { diff --git a/t/t0003-reopen-logs.sh b/t/t0003-reopen-logs.sh index cecd926..a01a422 100755 --- a/t/t0003-reopen-logs.sh +++ b/t/t0003-reopen-logs.sh @@ -67,11 +67,11 @@ t_begin "ensure no errors from curl" && { } t_begin "curl got $nr_client responses" && { - test "$(wc -l < $curl_out)" -eq $nr_client + test "$(count_lines < $curl_out)" -eq $nr_client } t_begin "all responses were identical" && { - nr=$(sort < $curl_out | uniq | wc -l) + nr=$(sort < $curl_out | uniq | count_lines) test "$nr" -eq 1 } diff --git a/t/t0004-heartbeat-timeout.sh b/t/t0004-heartbeat-timeout.sh index b96584d..c08edeb 100755 --- a/t/t0004-heartbeat-timeout.sh +++ b/t/t0004-heartbeat-timeout.sh @@ -34,7 +34,7 @@ t_begin "block the worker process to force it to die" && { t_begin "ensure worker was killed" && { test -e $ok - test 1 -eq $(grep timeout $r_err | grep killing | wc -l) + test 1 -eq $(grep timeout $r_err | grep killing | count_lines) } t_begin "ensure timeout took at least 3 seconds" && { diff --git a/t/t0024-pipelined-sendfile-response.sh b/t/t0024-pipelined-sendfile-response.sh index d98be5f..cfd8979 100755 --- a/t/t0024-pipelined-sendfile-response.sh +++ b/t/t0024-pipelined-sendfile-response.sh @@ -63,7 +63,7 @@ t_begin "staggered pipeline of 3 HTTP requests" && { wait echo ok >> $ok ) | socat - TCP:$listen > $dd_fifo - test 2 -eq $(grep '^ok$' $ok |wc -l) + test 2 -eq $(grep '^ok$' $ok |count_lines) } t_begin "pipeline 3 HTTP requests" && { @@ -78,7 +78,7 @@ t_begin "pipeline 3 HTTP requests" && { wait echo ok >> $ok ) | socat - TCP:$listen > $fifo - test 2 -eq $(grep '^ok$' $ok |wc -l) + test 2 -eq $(grep '^ok$' $ok |count_lines) } t_begin "shutdown server" && { diff --git a/t/t0030-fast-pipe-response.sh b/t/t0030-fast-pipe-response.sh index aab4357..e91392a 100755 --- a/t/t0030-fast-pipe-response.sh +++ b/t/t0030-fast-pipe-response.sh @@ -35,7 +35,7 @@ t_begin "send three keep-alive requests" && { } t_begin "ensure responses were all keep-alive" && { - test 3 -eq $(grep '< Connection: keep-alive' < $err | wc -l) + test 3 -eq $(grep '< Connection: keep-alive' < $err | count_lines) } t_begin "HTTP/1.0 test" && { diff --git a/t/t0034-pipelined-pipe-response.sh b/t/t0034-pipelined-pipe-response.sh index 2d28f86..59df69f 100755 --- a/t/t0034-pipelined-pipe-response.sh +++ b/t/t0034-pipelined-pipe-response.sh @@ -62,7 +62,7 @@ t_begin "staggered pipeline of 3 HTTP requests" && { wait echo ok >> $ok ) | socat - TCP:$listen > $dd_fifo - test 2 -eq $(grep '^ok$' $ok |wc -l) + test 2 -eq $(grep '^ok$' $ok |count_lines) } t_begin "pipeline 3 HTTP requests" && { @@ -77,7 +77,7 @@ t_begin "pipeline 3 HTTP requests" && { wait echo ok >> $ok ) | socat - TCP:$listen > $fifo - test 2 -eq $(grep '^ok$' $ok |wc -l) + test 2 -eq $(grep '^ok$' $ok |count_lines) } t_begin "shutdown server" && { diff --git a/t/t0035-kgio-pipe-response.sh b/t/t0035-kgio-pipe-response.sh index 552270f..b0c8112 100755 --- a/t/t0035-kgio-pipe-response.sh +++ b/t/t0035-kgio-pipe-response.sh @@ -35,7 +35,7 @@ t_begin "send three keep-alive requests" && { } t_begin "ensure responses were all keep-alive" && { - test 3 -eq $(grep '< Connection: keep-alive' < $err | wc -l) + test 3 -eq $(grep '< Connection: keep-alive' < $err | count_lines) } t_begin "HTTP/1.0 test" && { diff --git a/t/t0040-keepalive_requests-setting.sh b/t/t0040-keepalive_requests-setting.sh index 103b217..0a3570e 100755 --- a/t/t0040-keepalive_requests-setting.sh +++ b/t/t0040-keepalive_requests-setting.sh @@ -13,8 +13,8 @@ t_begin "setup and start" && { t_begin "curl requests hit default keepalive_requests limit" && { curl -sSfv http://$listen/[0-101] > $curl_out 2> $curl_err - test 1 -eq $(grep 'Connection: close' $curl_err |wc -l) - test 101 -eq $(grep 'Connection: keep-alive' $curl_err |wc -l) + test 1 -eq $(grep 'Connection: close' $curl_err |count_lines) + test 101 -eq $(grep 'Connection: keep-alive' $curl_err |count_lines) } t_begin "reload with smaller keepalive_requests limit" && { @@ -32,8 +32,8 @@ EOF t_begin "curl requests hit smaller keepalive_requests limit" && { rm -f $curl_out $curl_err curl -sSfv http://$listen/[1-13] > $curl_out 2> $curl_err - test 2 -eq $(grep 'Connection: close' $curl_err |wc -l) - test 11 -eq $(grep 'Connection: keep-alive' $curl_err |wc -l) + test 2 -eq $(grep 'Connection: close' $curl_err |count_lines) + test 11 -eq $(grep 'Connection: keep-alive' $curl_err |count_lines) } t_begin "killing succeeds" && { diff --git a/t/t0044-autopush.sh b/t/t0044-autopush.sh index 9faa61a..103f9fc 100644 --- a/t/t0044-autopush.sh +++ b/t/t0044-autopush.sh @@ -37,7 +37,7 @@ start_strace () { check_TCP_CORK () { nr=0 - while test 2 -gt $(grep TCP_CORK $strace_out | wc -l) + while test 2 -gt $(grep TCP_CORK $strace_out | count_lines) do nr=$(( $nr + 1 )) if test $nr -gt 30 @@ -48,7 +48,7 @@ check_TCP_CORK () { sleep 1 done - test 2 -eq $(grep TCP_CORK $strace_out | wc -l) + test 2 -eq $(grep TCP_CORK $strace_out | count_lines) fgrep 'SOL_TCP, TCP_CORK, [0],' $strace_out fgrep 'SOL_TCP, TCP_CORK, [1],' $strace_out } diff --git a/t/t0045-client_max_header_size.sh b/t/t0045-client_max_header_size.sh index 17cbc29..cd8f1fe 100755 --- a/t/t0045-client_max_header_size.sh +++ b/t/t0045-client_max_header_size.sh @@ -54,7 +54,7 @@ t_begin "smallest HTTP/0.9 request works right" && { ) | socat - TCP:$listen > $fifo wait test xok = x"$(cat $ok)" - test 1 -eq $(wc -l < $tmp) + test 1 -eq $(count_lines < $tmp) grep HTTP_VERSION $tmp && die "unexpected HTTP_VERSION in HTTP/0.9 request" } @@ -75,7 +75,7 @@ EOF t_begin "HTTP/1.1 request succeeds" && { curl -sSf http://$listen/ > $tmp - test 1 -eq $(wc -l < $tmp) + test 1 -eq $(count_lines < $tmp) dbgcat tmp } diff --git a/t/t0100-rack-input-hammer-chunked.sh b/t/t0100-rack-input-hammer-chunked.sh index efc3a9c..25ed718 100755 --- a/t/t0100-rack-input-hammer-chunked.sh +++ b/t/t0100-rack-input-hammer-chunked.sh @@ -32,11 +32,11 @@ t_begin "send $nr_client concurrent requests" && { t_begin "kill server" && kill $rainbows_pid t_begin "got $nr_client responses" && { - test $nr_client -eq $(wc -l < $curl_out) + test $nr_client -eq $(count_lines < $curl_out) } t_begin "all responses identical" && { - test 1 -eq $(sort < $curl_out | uniq | wc -l) + test 1 -eq $(sort < $curl_out | uniq | count_lines) } t_begin "sha1 matches on-disk sha1" && { diff --git a/t/t0100-rack-input-hammer-content-length.sh b/t/t0100-rack-input-hammer-content-length.sh index cbbe0be..6d90e6d 100755 --- a/t/t0100-rack-input-hammer-content-length.sh +++ b/t/t0100-rack-input-hammer-content-length.sh @@ -32,11 +32,11 @@ t_begin "send $nr_client concurrent requests" && { t_begin "kill server" && kill $rainbows_pid t_begin "got $nr_client responses" && { - test $nr_client -eq $(wc -l < $curl_out) + test $nr_client -eq $(count_lines < $curl_out) } t_begin "all responses identical" && { - test 1 -eq $(sort < $curl_out | uniq | wc -l) + test 1 -eq $(sort < $curl_out | uniq | count_lines) } t_begin "sha1 matches on-disk sha1" && { diff --git a/t/t0106-rack-input-keepalive.sh b/t/t0106-rack-input-keepalive.sh index 4bc65a1..3862e16 100755 --- a/t/t0106-rack-input-keepalive.sh +++ b/t/t0106-rack-input-keepalive.sh @@ -34,7 +34,7 @@ t_begin "send big pipelined chunked requests" && { t_begin "check responses" && { dbgcat tmp - test 4 -eq $(grep $random_blob_sha1 $tmp | wc -l) + test 4 -eq $(grep $random_blob_sha1 $tmp | count_lines) } t_begin "send big pipelined identity requests" && { @@ -58,7 +58,7 @@ t_begin "send big pipelined identity requests" && { t_begin "check responses" && { dbgcat tmp - test 3 -eq $(grep $random_blob_sha1 $tmp | wc -l) + test 3 -eq $(grep $random_blob_sha1 $tmp | count_lines) } t_begin "send pipelined identity requests" && { @@ -83,7 +83,7 @@ t_begin "send pipelined identity requests" && { t_begin "check responses" && { dbgcat tmp - test 3 -eq $(grep $body_sha1 $tmp | wc -l) + test 3 -eq $(grep $body_sha1 $tmp | count_lines) } t_begin "send pipelined chunked requests" && { @@ -111,7 +111,7 @@ t_begin "send pipelined chunked requests" && { t_begin "check responses" && { dbgcat tmp - test 3 -eq $(grep $body_sha1 $tmp | wc -l) + test 3 -eq $(grep $body_sha1 $tmp | count_lines) } t_begin "kill server" && kill $rainbows_pid diff --git a/t/t0402-async-keepalive.sh b/t/t0402-async-keepalive.sh index b5976da..c507100 100644 --- a/t/t0402-async-keepalive.sh +++ b/t/t0402-async-keepalive.sh @@ -39,9 +39,9 @@ t_begin "async.callback supports pipelining" && { t1=$(unix_time) elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed $model.$0 ($t_current)" - test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | wc -l)" - test 3 -eq "$(grep '^Hello ' $tmp | wc -l)" - test 3 -eq "$(grep 'World ' $tmp | wc -l)" + test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | count_lines)" + test 3 -eq "$(grep '^Hello ' $tmp | count_lines)" + test 3 -eq "$(grep 'World ' $tmp | count_lines)" } t_begin "async.callback supports delayed pipelining" && { @@ -59,9 +59,9 @@ t_begin "async.callback supports delayed pipelining" && { t1=$(unix_time) elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed $model.$0 ($t_current)" - test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | wc -l)" - test 3 -eq "$(grep '^Hello ' $tmp | wc -l)" - test 3 -eq "$(grep 'World ' $tmp | wc -l)" + test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | count_lines)" + test 3 -eq "$(grep '^Hello ' $tmp | count_lines)" + test 3 -eq "$(grep 'World ' $tmp | count_lines)" } t_begin "async.callback supports pipelining with delay $DELAY" && { @@ -82,9 +82,9 @@ t_begin "async.callback supports pipelining with delay $DELAY" && { min=$(( $DELAY * 3 )) t_info "elapsed=$elapsed $model.$0 ($t_current) min=$min" test $elapsed -ge $min - test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | wc -l)" - test 3 -eq "$(grep '^Hello ' $tmp | wc -l)" - test 3 -eq "$(grep 'World ' $tmp | wc -l)" + test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | count_lines)" + test 3 -eq "$(grep '^Hello ' $tmp | count_lines)" + test 3 -eq "$(grep 'World ' $tmp | count_lines)" } t_begin "async.callback supports keepalive" && { @@ -94,7 +94,7 @@ t_begin "async.callback supports keepalive" && { elapsed=$(( $t1 - $t0 )) t_info "elapsed=$elapsed $model.$0 ($t_current)" cmp $expect $tmp - test 2 -eq "$(fgrep 'Re-using existing connection!' $curl_err |wc -l)" + test 2 -eq "$(fgrep 'Re-using existing connection!' $curl_err |count_lines)" rm -f $curl_err } @@ -108,7 +108,7 @@ t_begin "async.callback supports keepalive with delay $DELAY" && { t_info "elapsed=$elapsed $model.$0 ($t_current) min=$min" test $elapsed -ge $min cmp $expect $tmp - test 2 -eq "$(fgrep 'Re-using existing connection!' $curl_err |wc -l)" + test 2 -eq "$(fgrep 'Re-using existing connection!' $curl_err |count_lines)" rm -f $curl_err } diff --git a/t/t0600-rack-fiber_pool.sh b/t/t0600-rack-fiber_pool.sh index 01f28b5..538eda4 100755 --- a/t/t0600-rack-fiber_pool.sh +++ b/t/t0600-rack-fiber_pool.sh @@ -43,7 +43,7 @@ t_begin "no errors from curl" && { t_begin "no errors in stderr" && check_stderr t_begin "ensure we hit 3 separate fibers" && { - test x3 = x"$(sort < $curl_out | uniq | wc -l)" + test x3 = x"$(sort < $curl_out | uniq | count_lines)" } t_done diff --git a/t/t0700-app-deferred.sh b/t/t0700-app-deferred.sh index 8d4b4e2..90614b2 100755 --- a/t/t0700-app-deferred.sh +++ b/t/t0700-app-deferred.sh @@ -25,8 +25,8 @@ t_begin "synchronous requests run in the same thread" && { curl --no-buffer -sSf http://$listen/ >> $sync_out 2>> $sync_err & wait test ! -s $sync_err - test 3 -eq "$(wc -l < $sync_out)" - test 1 -eq "$(uniq < $sync_out | wc -l)" + test 3 -eq "$(count_lines < $sync_out)" + test 1 -eq "$(uniq < $sync_out | count_lines)" } t_begin "deferred requests run in a different thread" && { diff --git a/t/t9000-rack-app-pool.sh b/t/t9000-rack-app-pool.sh index 5170b67..ea6657c 100755 --- a/t/t9000-rack-app-pool.sh +++ b/t/t9000-rack-app-pool.sh @@ -34,7 +34,7 @@ t_begin "kill server" && { } t_begin "$APP_POOL_SIZE instances of app were used" && { - test $APP_POOL_SIZE -eq $(sort < $curl_out | uniq | wc -l) + test $APP_POOL_SIZE -eq $(sort < $curl_out | uniq | count_lines) } t_begin "no errors in curl stderr" && { diff --git a/t/t9100-thread-timeout.sh b/t/t9100-thread-timeout.sh index bf0c252..d26e314 100755 --- a/t/t9100-thread-timeout.sh +++ b/t/t9100-thread-timeout.sh @@ -37,7 +37,7 @@ t_begin "short requests do not timeout while making a long one" && { test x"HI" = x"$(curl -sSf http://$listen/)" wait test -f $ok - test 20 -eq $(grep '^HI$' $ok | wc -l) + test 20 -eq $(grep '^HI$' $ok | count_lines) test x = x"$(grep -v '^HI$' $ok)" grep 408 $curl_err } diff --git a/t/t9101-thread-timeout-threshold.sh b/t/t9101-thread-timeout-threshold.sh index 07ac3b2..c1f5afe 100755 --- a/t/t9101-thread-timeout-threshold.sh +++ b/t/t9101-thread-timeout-threshold.sh @@ -23,7 +23,7 @@ t_begin "8 sleepy requests do not time out" && { 2>> $curl_err >> $curl_out & done wait - test 8 -eq "$(wc -l < $curl_out)" + test 8 -eq "$(count_lines < $curl_out)" test xHI = x"$(sort < $curl_out | uniq)" } diff --git a/t/test-lib.sh b/t/test-lib.sh index 26709bc..3471d69 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -43,6 +43,11 @@ unix_time () { $RUBY -e 'puts Time.now.to_i' } +# "wc -l" outputs leading whitespace on *BSDs, filter it out for portability +count_lines () { + wc -l | tr -d '[:space:]' +} + # "wc -c" outputs leading whitespace on *BSDs, filter it out for portability count_bytes () { wc -c | tr -d '[:space:]' -- 2.11.4.GIT