forked from customink/central_logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·91 lines (78 loc) · 2.2 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# This script uses rvm and gemsets to test the gem against all versions of ruby
# (RUBY_VERSIONS) and all rails versions in the test/rails directories
# (RAILS_VERSIONS).
# If these aren't unset, bundler always uses them to find itself and the
# root project gemfile
unset BUNDLE_BIN_PATH
unset BUNDLE_GEMFILE
RAILS_VERSIONS='2 3'
RUBY_VERSIONS='1.8.7 1.9.2'
PROJECT_GEMSET='central_logger'
RAILS_DIR=rails
RAILS_RAKE_TASK_MODIFIER=':functionals'
RAKE_UNIT_TASK_MODIFIER=':units'
CLEAN=0
VALID_OPT='--clean'
function usage() {
echo 'Usage: ' $0 "[${VALID_OPT}]"
echo 'Options:' $VALID_OPT 'Delete and recreate all gemsets before running tests'
exit 1
}
ARG=$1
if [ $# -gt 1 ] || [ ${ARG:-$VALID_OPT} != $VALID_OPT ]; then
usage
elif [ -n "$1" ]; then
CLEAN=1
fi
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]]; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
exit 1
fi
# deletes and recreates a gemset
function clean_gemset() {
RUBY=$1; GEMSET=$2
# easier than checking and emptying/creating
rvm --force gemset delete ${RUBY}@${GEMSET}
rvm gemset create $GEMSET
}
# runs rake test, optionally cleaning the gemset
function rake_test() {
RUBY=$1; GEMSET=$2; SUBTASK=$3
echo
echo "-----------Running tests for '${RUBY}@${GEMSET}'------------"
rvm $RUBY
if [ $CLEAN -eq 1 ]; then
clean_gemset $RUBY $GEMSET
rvm gemset use $GEMSET
bundle install
else
rvm gemset use $GEMSET
fi
# 'rvm $RUBY_VER rake' doesn't work with bundle install
rake test${SUBTASK}
if [ $? -ne 0 ]; then exit 1; fi
}
# Loop through all perms of rubies and rails
cd test
for RBV in $RUBY_VERSIONS; do
rake_test $RBV $PROJECT_GEMSET $RAKE_UNIT_TASK_MODIFIER
NEXT_DIR=$RAILS_DIR
for RV in $RAILS_VERSIONS; do
if [ "$NEXT_DIR" == "$RAILS_DIR" ]; then
NEXT_DIR=${NEXT_DIR}/${RV}
else
NEXT_DIR=../${RV}
fi
cd $NEXT_DIR
rake_test $RBV ${PROJECT_GEMSET}_${RV} $RAILS_RAKE_TASK_MODIFIER
done
cd ../..
done