unicorn_rails: fix requires for Ruby 1.9.2
[unicorn.git] / t / test-lib.sh
blob22497f3d46fab64ff57bbd6647257152c009b329
1 #!/bin/sh
2 # Copyright (c) 2009 Rainbows! hackers
3 # Copyright (c) 2010 Unicorn hackers
4 . ./my-tap-lib.sh
6 set +u
7 set -e
8 RUBY="${RUBY-ruby}"
9 RUBY_VERSION=${RUBY_VERSION-$($RUBY -e 'puts RUBY_VERSION')}
10 RUBY_ENGINE=${RUBY_ENGINE-$($RUBY -e 'puts((RUBY_ENGINE rescue "ruby"))')}
11 t_pfx=$PWD/trash/$T-$RUBY_ENGINE-$RUBY_VERSION
12 set -u
14 PATH=$PWD/bin:$PATH
15 export PATH
17 test -x $PWD/bin/unused_listen || die "must be run in 't' directory"
19 wait_for_pid () {
20 path="$1"
21 nr=30
22 while ! test -s "$path" && test $nr -gt 0
24 nr=$(($nr - 1))
25 sleep 1
26 done
29 # given a list of variable names, create temporary files and assign
30 # the pathnames to those variables
31 rtmpfiles () {
32 for id in "$@"
34 name=$id
35 _tmp=$t_pfx.$id
36 eval "$id=$_tmp"
38 case $name in
39 *fifo)
40 rm -f $_tmp
41 mkfifo $_tmp
42 T_RM_LIST="$T_RM_LIST $_tmp"
44 *socket)
45 rm -f $_tmp
46 T_RM_LIST="$T_RM_LIST $_tmp"
49 > $_tmp
50 T_OK_RM_LIST="$T_OK_RM_LIST $_tmp"
52 esac
53 done
56 dbgcat () {
57 id=$1
58 eval '_file=$'$id
59 echo "==> $id <=="
60 sed -e "s/^/$id:/" < $_file
63 check_stderr () {
64 set +u
65 _r_err=${1-${r_err}}
66 set -u
67 if grep -v $T $_r_err | grep -i Error
68 then
69 die "Errors found in $_r_err"
70 elif grep SIGKILL $_r_err
71 then
72 die "SIGKILL found in $_r_err"
76 # unicorn_setup
77 unicorn_setup () {
78 eval $(unused_listen)
79 rtmpfiles unicorn_config pid r_err r_out fifo tmp ok
80 cat > $unicorn_config <<EOF
81 listen "$listen"
82 pid "$pid"
83 stderr_path "$r_err"
84 stdout_path "$r_out"
85 EOF
88 unicorn_wait_start () {
89 # no need to play tricks with FIFOs since we got "ready_pipe" now
90 unicorn_pid=$(cat $pid)
93 rsha1 () {
94 _cmd="$(which sha1sum 2>/dev/null || :)"
95 test -n "$_cmd" || _cmd="$(which openssl 2>/dev/null || :) sha1"
96 test "$_cmd" != " sha1" || _cmd="$(which gsha1sum 2>/dev/null || :)"
98 # last resort, see comments in sha1sum.rb for reasoning
99 test -n "$_cmd" || _cmd=sha1sum.rb
100 expr "$($_cmd < random_blob)" : '\([a-f0-9]\{40\}\)'