summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-02-04 12:29:00 +0000
committerEric Wong <normalperson@yhbt.net>2013-02-04 12:31:05 +0000
commit2a2163594ea2b515e98fbe9f909bcf90e4c35fe8 (patch)
treecdfb5fd65bd1850dba45362a81350da6ee0ae7d0
parent85223902e8229bd460ce0b4ad126f42b1db42a46 (diff)
On FreeBSD 9.0, "wc -c" emits leading whitespace, so
filter it through tr -d '[:space:]' to eliminate it.

This is commit 8a6117a22a7d01eeb5adc63d3152acf435cd3176
in rainbows.git
-rwxr-xr-xt/t0006-reopen-logs.sh8
-rwxr-xr-xt/t0019-max_header_len.sh2
-rwxr-xr-xt/t0100-rack-input-tests.sh6
-rw-r--r--t/test-lib.sh7
4 files changed, 14 insertions, 9 deletions
diff --git a/t/t0006-reopen-logs.sh b/t/t0006-reopen-logs.sh
index 430959c..a6e7a17 100755
--- a/t/t0006-reopen-logs.sh
+++ b/t/t0006-reopen-logs.sh
@@ -62,11 +62,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)
         test xtrue = x$(curl -sSf http://$listen/ 2> $curl_err)
-        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/t0019-max_header_len.sh b/t/t0019-max_header_len.sh
index 5ce1c69..6a355b4 100755
--- a/t/t0019-max_header_len.sh
+++ b/t/t0019-max_header_len.sh
@@ -5,7 +5,7 @@ t_plan 5 "max_header_len setting (only intended for Rainbows!)"
 t_begin "setup and start" && {
         unicorn_setup
         req='GET / HTTP/1.0\r\n\r\n'
-        len=$(printf "$req" | wc -c)
+        len=$(printf "$req" | count_bytes)
         echo Unicorn::HttpParser.max_header_len = $len >> $unicorn_config
         unicorn -D -c $unicorn_config env.ru
         unicorn_wait_start
diff --git a/t/t0100-rack-input-tests.sh b/t/t0100-rack-input-tests.sh
index 13d4207..873f15c 100755
--- a/t/t0100-rack-input-tests.sh
+++ b/t/t0100-rack-input-tests.sh
@@ -8,9 +8,9 @@ t_begin "setup and startup" && {
         rtmpfiles curl_out curl_err
         unicorn_setup
         unicorn -E none -D rack-input-tests.ru -c $unicorn_config
-        blob_sha1=$(rsha1 < random_blob)
-        blob_size=$(wc -c < random_blob)
-        t_info "blob_sha1=$blob_sha1"
+        blob_sha1=$(rsha1 < random_blob)
+        blob_size=$(count_bytes < random_blob)
+        t_info "blob_sha1=$blob_sha1"
         unicorn_wait_start
 }
 
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 6d0fa22..2b93576 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 -c" outputs leading whitespace on *BSDs, filter it out for portability
+count_bytes () {
+        wc -c | tr -d '[:space:]'
+}
+
 # given a list of variable names, create temporary files and assign
 # the pathnames to those variables
 rtmpfiles () {
@@ -54,7 +59,7 @@ rtmpfiles () {
                         ;;
                 *socket)
                         _tmp="$(mktemp -t $id.$$.XXXXXXXX)"
-                        if test $(printf "$_tmp" |wc -c) -gt 108
+                        if test $(printf "$_tmp" |count_bytes) -gt 108
                         then
                                 echo >&2 "$_tmp too long, tests may fail"
                                 echo >&2 "Try to set TMPDIR to a shorter path"