1 | #!/usr/bin/env bash |
---|
2 | ISCRIPT=$1 |
---|
3 | OPT=$2 |
---|
4 | |
---|
5 | [ -n "$ISCRIPT" ] || { echo Syntax: `basename "$0"` irssi-test-script; exit 1; } |
---|
6 | |
---|
7 | # Load variables from test |
---|
8 | eval `sed -e '1,/^###/!d;/^###/d' "$ISCRIPT"` |
---|
9 | |
---|
10 | #if [ "$OPT" == "checkvars" ]; then echo $TESTNEEDEDVARS; fi |
---|
11 | RET=0 |
---|
12 | |
---|
13 | # Check if we have the neccessary environment variables for this test |
---|
14 | for var in $TESTNEEDEDVARS; do |
---|
15 | if [ -z `eval echo \$\{$var\}` ]; then |
---|
16 | if [ "$OPT" != "checkvars" ]; then |
---|
17 | echo Need environment variable "$var" for this test. |
---|
18 | exit 66 |
---|
19 | else |
---|
20 | echo $var |
---|
21 | RET=66 |
---|
22 | fi |
---|
23 | fi |
---|
24 | done |
---|
25 | |
---|
26 | # if we got this far we're OK |
---|
27 | if [ "$OPT" == "checkvars" ]; then exit $RET; fi |
---|
28 | |
---|
29 | [ -n "$PORT" ] || { echo 'Need the bitlbee listening port as environment variable PORT'; exit 1; } |
---|
30 | |
---|
31 | # Setup the irssi dir |
---|
32 | ( |
---|
33 | rm -r dotirssi |
---|
34 | mkdir -p dotirssi/scripts dotirssi/logs |
---|
35 | cp "`dirname $0`"/trigger.pl dotirssi/scripts && |
---|
36 | echo 'script load trigger.pl' >dotirssi/startup |
---|
37 | ) &>/dev/null || { echo Failed to setup irssi testdir; exit 1; } |
---|
38 | |
---|
39 | # write irssi config |
---|
40 | |
---|
41 | echo ' |
---|
42 | |
---|
43 | aliases = { |
---|
44 | runtest = "'`sed -e "1,/^###/d;s/@LOGIN@/$TESTLOGIN/;s/@PASSWORD@/$TESTPASSWORD/" "$ISCRIPT" | tr '\n' ';'`'"; |
---|
45 | expectbee = "/trigger add -publics -channels &bitlbee -regexp"; |
---|
46 | expectjoin = "/trigger add -joins -masks *!$0@* $1-"; |
---|
47 | expectmsg = "/trigger add -privmsgs -masks *!$0@* $1-"; |
---|
48 | }; |
---|
49 | |
---|
50 | servers = ( { address = "localhost"; chatnet = "local"; port = "'$PORT'"; autoconnect="yes";}); |
---|
51 | |
---|
52 | settings = { |
---|
53 | settings_autosave = "no"; |
---|
54 | core = { real_name = "bitlbee-test"; user_name = "bitlbee-test"; nick = "bitlbeetest"; }; |
---|
55 | "fe-text" = { actlist_sort = "refnum"; }; |
---|
56 | }; |
---|
57 | |
---|
58 | chatnets = { local = { type = "IRC"; autosendcmd = "/runtest"; }; }; |
---|
59 | |
---|
60 | logs = { |
---|
61 | "dotirssi/logs/status.log" = { auto_open = "yes"; level = "ALL"; items = ( { type = "window"; name = "1"; } ); }; |
---|
62 | "dotirssi/logs/control.log" = { auto_open = "yes"; level = "ALL"; items = ( { type = "target"; name = "&bitlbee"; } ); }; |
---|
63 | ' >dotirssi/config |
---|
64 | |
---|
65 | for nick in $TESTLOGNICKS; do |
---|
66 | echo ' |
---|
67 | "dotirssi/logs/'$nick'.log" = { auto_open = "yes"; level = "ALL"; items = ( { type = "target"; name = "'$nick'"; } ); }; |
---|
68 | ' >>dotirssi/config |
---|
69 | done |
---|
70 | |
---|
71 | echo '};' >>dotirssi/config |
---|
72 | |
---|
73 | # Go! |
---|
74 | |
---|
75 | echo Running irssi... |
---|
76 | screen -D -m irssi --config=dotirssi/config --home=dotirssi/ & |
---|
77 | |
---|
78 | # output logs |
---|
79 | |
---|
80 | submitlogs() { |
---|
81 | perl -p -i -e "s/$TESTLOGIN/---TESTLOGIN---/;s/$TESTPASSWORD/---TESTPASSWORD---/" dotirssi/logs/*.log |
---|
82 | |
---|
83 | if [ "$OPT" == "tgz" ]; then |
---|
84 | tar czf "`dirname $0`"/"`basename "$ISCRIPT"`".logs.tgz dotirssi/logs/*.log |
---|
85 | elif [ "$OPT" == "ctest" ]; then |
---|
86 | echo CTEST_FULL_OUTPUT |
---|
87 | for log in dotirssi/logs/*.log; do |
---|
88 | echo -n '<DartMeasurement name="'$log'" type="text/string"><![CDATA[' |
---|
89 | cat "$log" |
---|
90 | echo "]]></DartMeasurement>" |
---|
91 | done |
---|
92 | else |
---|
93 | echo Test logs: dotirssi/logs/*.log |
---|
94 | fi |
---|
95 | } |
---|
96 | |
---|
97 | # timeout stuff |
---|
98 | |
---|
99 | t=$TESTDURATION |
---|
100 | intval=1 |
---|
101 | while (( t >= intval )); do |
---|
102 | sleep $intval |
---|
103 | kill -0 $! &>/dev/null || { echo screen/irssi terminated.; submitlogs; bash -c "cd dotirssi/logs && $TESTCHECKRESULT" >/dev/null; exit $?; } |
---|
104 | t=$(( t - $intval )) |
---|
105 | done |
---|
106 | echo Killing screen/irssi... |
---|
107 | kill $! |
---|
108 | submitlogs |
---|
109 | exit 22 |
---|