forked from backlogs/redmine_backlogs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbl-test
executable file
·138 lines (110 loc) · 3.83 KB
/
rbl-test
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
set -e
function errmsg {
echo "$1"
exit 1
}
function print_usage {
cat <<EOF
Usage:
`basename $0` Run all tests and generate coverage report
`basename $0` -f <feature> Run tests for a single feature
`basename $0` -h Show this page
`basename $0` -p Publish test results to website
EOF
exit $1
}
while getopts "phf:" OPT; do
case $OPT in
h) print_usage 0;;
f) TEST_FEATURE="$OPTARG";;
p) PUBLISH="yes";;
[?]) print_usage 1;;
esac
done
command -v ruby >/dev/null 2>&1 || errmsg "no ruby available"
RUBYVER=`ruby --version | awk '{print $2}' | awk -F. '{print $1 "." $2}'`
GEMSET=`rvm-prompt g | sed -e 's/@//'`
export RAILS_ENV=cucumber
case "$GEMSET" in
redmine) ;;
chiliproject) ;;
*) echo 'No gemset active'; exit 1;;
esac
CONFIG="$( cd "$( dirname "$0" )" && pwd )"
CONFIG="$CONFIG/rbl-test.rc"
if [ ! -f $CONFIG ]; then
echo "$CONFIG does not exist"
exit 1
fi
source $CONFIG
cd ~/redmine/$GEMSET-$RUBYVER
mysqldump -u root -p$DBROOTPW $GEMSET > ../setup/blcuke-salvage.sql
mysqladmin --force -u root -p$DBROOTPW drop $GEMSET
mysqladmin -u root -p$DBROOTPW create $GEMSET
if [ -f ../setup/cucumber-$GEMSET.sql.gz ]; then
echo 'Pre-loading data'
zcat ../setup/cucumber-$GEMSET.sql.gz| mysql -u root -p$DBROOTPW $GEMSET
fi
echo migrations
bundle exec rake $TRACE generate_session_store
script -e -c "rake $TRACE db:migrate" -f ~/redmine/cuke-$GEMSET.log
#script -e -c "REDMINE_LANG=en rake $TRACE redmine:load_default_data" -f ~/redmine/defaults.log
script -e -c "rake $TRACE db:migrate:plugins" -f ~/redmine/cuke-$GEMSET.log
#rake redmine:backlogs:install batch=true corruptiontest=false labels=false RAILS_ENV=cucumber
rm -f log/cucumber.log
if [ -z "$TEST_FEATURE" ]; then
echo "Running all tests"
if [ "$RUBYVER" = "1.9" ]; then
script -e -c "cucumber features" -f ~/redmine/cuke-$GEMSET.log
else
script -e -c "rake $TRACE redmine:backlogs:rcov" -f ~/redmine/cuke-$GEMSET.log
fi
else
echo "Testing feature: $TEST_FEATURE"
script -e -c "cucumber $TEST_FEATURE" -f ~/redmine/cuke-$GEMSET.log
fi
sed '/^$/d' -i ~/redmine/cuke-$GEMSET.log
#mysqladmin --force -u root -p$DBROOTPW drop $GEMSET
#mysqladmin -u root -p$DBROOTPW create $GEMSET
#cat ../setup/blcuke-salvage.sql | mysql -u root -p$DBROOTPW $GEMSET
if [ -n "$PUBLISH" ]; then
cd ~/redmine/redmine_backlogs
BRANCH=`git branch --no-color | awk '/^\*/ { print $2}'`
COMMIT=`git log -1 --format=%h`
COVERAGE="$GEMSET-$BRANCH-$COMMIT"
rm -rf ~/redmine/www/coverage/$GEMSET-$BRANCH-*
ran=0
if [ -e ~/redmine/cuke-$GEMSET.log ]; then
ran=`grep scenarios ~/redmine/cuke-$GEMSET.log | wc -l`
fi
if [ "$ran" = "1" ]; then
mkdir "$HOME/redmine/www/coverage/$COVERAGE"
failed=`grep -E 'scenarios.*(skipped|failed)' ~/redmine/cuke-$GEMSET.log | wc -l`
if [ "$failed" = "1" ]; then
cd ~/redmine/www/coverage/$COVERAGE
echo '---' > index.markdown
echo 'title: Build failed' >> index.markdown
echo 'layout: default' >> index.markdown
echo '---' >> index.markdown
echo '# Build failed' >> index.markdown
echo '' >> index.markdown
ruby -e 'while gets; break if $_ =~ /^WARNING/; end; while gets; break if $_ =~ /^[+]-{10}/; puts " #{$_.strip} "; end' ~/redmine/cuke-$GEMSET.log >> index.markdown
else
cp -r ~/redmine/$GEMSET-$RUBYVER/coverage/* "$HOME/redmine/www/coverage/$COVERAGE"
fi
fi
cd ~/redmine/www/coverage
echo '---' > index.markdown
echo 'title: Code coverage' >> index.markdown
echo 'layout: default' >> index.markdown
echo '---' >> index.markdown
echo '# Code coverage' >> index.markdown
echo '' >> index.markdown
ls -lt | grep ^d | awk '{print "[" $8, $6, $7 "](" $9 ") "}' >> index.markdown
chmod a+rwX ~/redmine/www/coverage/*
git add .
git commit -am "coverage update: $COVERAGE"
git push
fi