From 8a6117a22a7d01eeb5adc63d3152acf435cd3176 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 24 Jan 2013 23:33:54 +0000 Subject: tests: "wc -c" portability for *BSDs On FreeBSD 9.0, "wc -c" emits leading whitespace, so filter it through tr -d '[:space:]' to eliminate it. --- t/byte-range-common.sh | 2 +- t/t0003-reopen-logs.sh | 8 ++++---- t/t0005-large-file-response.sh | 2 +- t/t0027-nil-copy_stream.sh | 2 +- t/t0106-rack-input-keepalive.sh | 4 ++-- t/t9001-sendfile-to-path.sh | 2 +- t/test-lib.sh | 5 +++++ 7 files changed, 15 insertions(+), 10 deletions(-) (limited to 't') diff --git a/t/byte-range-common.sh b/t/byte-range-common.sh index ba05864..2c12a8b 100644 --- a/t/byte-range-common.sh +++ b/t/byte-range-common.sh @@ -1,5 +1,5 @@ t_begin "byte-range setup vars" && { - random_blob_size=$(wc -c < random_blob) + random_blob_size=$(count_bytes < random_blob) rb_1=$(( $random_blob_size - 1 )) range_head=-r-365 range_tail=-r155- diff --git a/t/t0003-reopen-logs.sh b/t/t0003-reopen-logs.sh index 8e2cdc5..cecd926 100755 --- a/t/t0003-reopen-logs.sh +++ b/t/t0003-reopen-logs.sh @@ -86,11 +86,11 @@ t_begin "rotated stderr is clean" && { } t_begin "server is now writing logs to new stderr" && { - before_rot=$(wc -c < $r_rot) - before_err=$(wc -c < $r_err) + before_rot=$(count_bytes < $r_rot) + before_err=$(count_bytes < $r_err) curl -sSfv http://$listen/ - after_rot=$(wc -c < $r_rot) - after_err=$(wc -c < $r_err) + after_rot=$(count_bytes < $r_rot) + after_err=$(count_bytes < $r_err) test $after_rot -eq $before_rot test $after_err -gt $before_err } diff --git a/t/t0005-large-file-response.sh b/t/t0005-large-file-response.sh index c21209d..1326192 100755 --- a/t/t0005-large-file-response.sh +++ b/t/t0005-large-file-response.sh @@ -21,7 +21,7 @@ t_begin "setup and startup" && { t_begin "read random blob sha1 and size" && { random_blob_sha1=$(rsha1 < random_blob) - random_blob_size=$(wc -c < random_blob) + random_blob_size=$(count_bytes < random_blob) } t_begin "read current RSS" && { diff --git a/t/t0027-nil-copy_stream.sh b/t/t0027-nil-copy_stream.sh index 9b68160..ac282ce 100644 --- a/t/t0027-nil-copy_stream.sh +++ b/t/t0027-nil-copy_stream.sh @@ -19,7 +19,7 @@ EOF t_begin "read random blob sha1 and size" && { random_blob_sha1=$(rsha1 < random_blob) - random_blob_size=$(wc -c < random_blob) + random_blob_size=$(count_bytes < random_blob) } t_begin "send a series HTTP/1.1 requests sequentially" && { diff --git a/t/t0106-rack-input-keepalive.sh b/t/t0106-rack-input-keepalive.sh index e408701..4bc65a1 100755 --- a/t/t0106-rack-input-keepalive.sh +++ b/t/t0106-rack-input-keepalive.sh @@ -8,9 +8,9 @@ t_begin "setup and startup" && { rtmpfiles req rainbows -D sha1.ru -c $unicorn_config body=hello - body_size=$(printf $body | wc -c) + body_size=$(printf $body | count_bytes) body_sha1=$(printf $body | rsha1) - random_blob_size=$(wc -c < random_blob) + random_blob_size=$(count_bytes < random_blob) random_blob_sha1=$(rsha1 < random_blob) rainbows_wait_start } diff --git a/t/t9001-sendfile-to-path.sh b/t/t9001-sendfile-to-path.sh index 5a9fdcd..4e4012c 100755 --- a/t/t9001-sendfile-to-path.sh +++ b/t/t9001-sendfile-to-path.sh @@ -40,7 +40,7 @@ t_begin "X-Sendfile does not show up in headers" && { } t_begin "Content-Length is set correctly in headers" && { - expect=$(wc -c < random_blob) + expect=$(count_bytes < random_blob) grep "^< Content-Length: $expect" $curl_err } diff --git a/t/test-lib.sh b/t/test-lib.sh index 8921da6..26709bc 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 -c" outputs leading whitespace on *BSDs, filter it out for portability +count_bytes () { + wc -c | tr -d '[:space:]' +} + skip_models () { for i in "$@" do -- cgit v1.2.3-24-ge0c7