From 9cd8554749a9f120b010c93933d09d2dd27b1280 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 4 Feb 2013 12:39:09 +0000 Subject: 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-http-basic.sh | 2 +- t/t0004-heartbeat-timeout.sh | 2 +- t/t0100-rack-input-tests.sh | 14 +++++++------- t/t9000-preread-input.sh | 4 ++-- t/test-lib.sh | 5 +++++ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/t/t0000-http-basic.sh b/t/t0000-http-basic.sh index 01ead95..8ab58ac 100755 --- a/t/t0000-http-basic.sh +++ b/t/t0000-http-basic.sh @@ -26,7 +26,7 @@ t_begin "HTTP/0.9 request should not return headers" && { } 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/t0004-heartbeat-timeout.sh b/t/t0004-heartbeat-timeout.sh index 3e373e9..2965283 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/t0100-rack-input-tests.sh b/t/t0100-rack-input-tests.sh index 873f15c..ee7a437 100755 --- a/t/t0100-rack-input-tests.sh +++ b/t/t0100-rack-input-tests.sh @@ -24,7 +24,7 @@ t_begin "corked identity request" && { wait echo ok > $ok ) | ( sleep 1 && socat - TCP4:$listen > $fifo ) - test 1 -eq $(grep $blob_sha1 $tmp |wc -l) + test 1 -eq $(grep $blob_sha1 $tmp |count_lines) test x"$(cat $ok)" = xok } @@ -36,7 +36,7 @@ t_begin "corked chunked request" && { wait echo ok > $ok ) | ( sleep 1 && socat - TCP4:$listen > $fifo ) - test 1 -eq $(grep $blob_sha1 $tmp |wc -l) + test 1 -eq $(grep $blob_sha1 $tmp |count_lines) test x"$(cat $ok)" = xok } @@ -50,7 +50,7 @@ t_begin "corked identity request (input#size first)" && { wait echo ok > $ok ) | ( sleep 1 && socat - TCP4:$listen > $fifo ) - test 1 -eq $(grep $blob_sha1 $tmp |wc -l) + test 1 -eq $(grep $blob_sha1 $tmp |count_lines) test x"$(cat $ok)" = xok } @@ -64,7 +64,7 @@ t_begin "corked identity request (input#rewind first)" && { wait echo ok > $ok ) | ( sleep 1 && socat - TCP4:$listen > $fifo ) - test 1 -eq $(grep $blob_sha1 $tmp |wc -l) + test 1 -eq $(grep $blob_sha1 $tmp |count_lines) test x"$(cat $ok)" = xok } @@ -81,8 +81,8 @@ t_begin "corked chunked request (input#size first)" && { wait echo ok > $ok ) | ( sleep 1 && socat - TCP4:$listen > $fifo ) - test 1 -eq $(grep $blob_sha1 $tmp |wc -l) - test 1 -eq $(grep $blob_sha1 $tmp |wc -l) + test 1 -eq $(grep $blob_sha1 $tmp |count_lines) + test 1 -eq $(grep $blob_sha1 $tmp |count_lines) test x"$(cat $ok)" = xok } @@ -99,7 +99,7 @@ t_begin "corked chunked request (input#rewind first)" && { wait echo ok > $ok ) | ( sleep 1 && socat - TCP4:$listen > $fifo ) - test 1 -eq $(grep $blob_sha1 $tmp |wc -l) + test 1 -eq $(grep $blob_sha1 $tmp |count_lines) test x"$(cat $ok)" = xok } diff --git a/t/t9000-preread-input.sh b/t/t9000-preread-input.sh index b9da05e..d6c73ab 100755 --- a/t/t9000-preread-input.sh +++ b/t/t9000-preread-input.sh @@ -26,7 +26,7 @@ t_begin "sha1 matches" && { } t_begin "app only dispatched twice" && { - test 2 -eq "$(grep 'app dispatch:' < $r_err | wc -l )" + test 2 -eq "$(grep 'app dispatch:' < $r_err | count_lines )" } t_begin "aborted chunked request" && { @@ -38,7 +38,7 @@ t_begin "aborted chunked request" && { } t_begin "app only dispatched twice" && { - test 2 -eq "$(grep 'app dispatch:' < $r_err | wc -l )" + test 2 -eq "$(grep 'app dispatch:' < $r_err | count_lines )" } t_begin "killing succeeds" && { diff --git a/t/test-lib.sh b/t/test-lib.sh index 2b93576..28d6a88 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -37,6 +37,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:]' -- cgit v1.2.3-24-ge0c7