script/test in faraday-0.9.0.rc5 vs script/test in faraday-0.9.0.rc6

- old
+ new

@@ -22,10 +22,11 @@ if [[ "$RUBYOPT" != *"bundler/setup"* ]]; then export RUBYOPT="-rbundler/setup $RUBYOPT" fi port=3999 +proxy_port=3998 scheme=http if [ "$SSL" = "yes" ]; then scheme=https if [ -z "$SSL_KEY" ] || [ -z "$SSL_FILE" ]; then @@ -45,26 +46,32 @@ done } start_server() { mkdir -p log - script/server -p $port >log/server.log 2>&1 & + script/server -p $port >log/test.log 2>&1 & echo $! } +start_proxy() { + mkdir -p log + script/proxy-server -p $proxy_port -u "faraday@test.local:there is cake" >log/proxy.log 2>&1 & + echo $! +} + server_started() { - lsof -i :$port >/dev/null + lsof -i :${1?} >/dev/null } timestamp() { date +%s } wait_for_server() { timeout=$(( `timestamp` + $1 )) while true; do - if server_started; then + if server_started "$2"; then break elif [ `timestamp` -gt "$timeout" ]; then echo "timed out after $1 seconds" >&2 return 1 fi @@ -107,38 +114,59 @@ fi fi # If there are any adapter tests, spin up the HTTP server if [ -n "$(filter_matching "adapters" "${test_files[@]}")" ]; then - if server_started; then + if server_started $port; then echo "aborted: another instance of server running on $port" >&2 exit 1 fi server_pid=$(start_server) - wait_for_server 15 || { - cat log/server.log + proxy_pid=$(start_proxy) + wait_for_server 30 $port || { + cat log/test.log + kill "$server_pid" + kill "$proxy_pid" exit 1 } + wait_for_server 5 $proxy_port cleanup() { if [ $? -ne 0 ] && [ -n "$TRAVIS" ]; then cat log/test.log fi kill "$server_pid" + kill "$proxy_pid" } trap cleanup INT EXIT export LIVE="${scheme}://localhost:${port}" + export LIVE_PROXY="http://faraday%40test.local:there%20is%20cake@localhost:${proxy_port}" fi +warnings="${TMPDIR:-/tmp}/faraday-warnings.$$" + run_test_files() { - ruby -e 'while f=ARGV.shift and f!="--"; load f; end' "${test_files[@]}" -- "$@" + # Save warnings on stderr to a separate file + RUBYOPT="$RUBYOPT -w" ruby -e 'while f=ARGV.shift and f!="--"; load f; end' "${test_files[@]}" -- "$@" \ + 2> >(tee >(grep 'warning:' >"$warnings") | grep -v 'warning:') } +check_warnings() { + # Display Ruby warnings from this project's source files. Abort if any were found. + num="$(grep -F "$PWD" "$warnings" | grep -v "${PWD}/bundle" | sort | uniq -c | sort -rn | tee /dev/stderr | wc -l)" + rm -f "$warnings" + if [ "$num" -gt 0 ]; then + echo "FAILED: this test suite doesn't tolerate Ruby syntax warnings!" >&2 + exit 1 + fi +} + if [ -n "$RBENV_VERSIONS" ]; then IFS=' ' versions=($RBENV_VERSIONS) for version in "${versions[@]}"; do echo "[${version}]" RBENV_VERSION="$version" run_test_files "$@" done else run_test_files "$@" fi +check_warnings