From bf86b1d66a1d02ffd99bff9f3ba7090c2f49b283 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 7 Sep 2015 15:27:30 +0200 Subject: [PATCH 1/4] add missing .sh files to git (previously blocked by .gitignore) add an integration test for run-turn.lua --- .gitignore | 1 - process/compress.sh | 24 ++++++++++++++++++++++ process/functions.sh | 10 +++++++++ process/received-mail.sh | 1 + process/received.sh | 1 + process/run-turn.sh | 22 ++++++++++++++++++++ process/sendreports.sh | 33 ++++++++++++++++++++++++++++++ s/travis-build | 1 + tests/run-turn.sh | 44 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 136 insertions(+), 1 deletion(-) create mode 100755 process/compress.sh create mode 100644 process/functions.sh create mode 100644 process/received-mail.sh create mode 100644 process/received.sh create mode 100755 process/run-turn.sh create mode 100755 process/sendreports.sh create mode 100755 tests/run-turn.sh diff --git a/.gitignore b/.gitignore index 7173836cc..24a918963 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,6 @@ ipch/ *.opensdf *.pdb *.sdf -*.sh *.suo *.user diff --git a/process/compress.sh b/process/compress.sh new file mode 100755 index 000000000..f012e68c8 --- /dev/null +++ b/process/compress.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [ -z $ERESSEA ]; then + echo "You need to define the \$ERESSEA environment variable to run $0" + exit -2 +fi + +GAME=$ERESSEA/game-$1 +GAME_NAME=$(grep name $GAME/eressea.ini | sed 's/.*=\s*//') + +TURN=$2 +if [ -z $TURN ] +then + TURN=`cat $GAME/turn` +fi + +if [ ! -d $GAME/reports ]; then + echo "cannot find reprts directory in $GAME" + exit +fi + +cd $GAME/reports +compress.py $TURN "$GAME_NAME" +cd - diff --git a/process/functions.sh b/process/functions.sh new file mode 100644 index 000000000..859fd302a --- /dev/null +++ b/process/functions.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +PATH=$ERESSEA/bin:$PATH + +function abort() { + if [ $# -gt 0 ]; then + echo $@ + fi + exit -1 +} diff --git a/process/received-mail.sh b/process/received-mail.sh new file mode 100644 index 000000000..b6b4a0605 --- /dev/null +++ b/process/received-mail.sh @@ -0,0 +1 @@ +ls -1 orders.dir/turn* | sed -e 's/.*turn-\(.*\),gruenbaer.*/\1/' | sort -u diff --git a/process/received.sh b/process/received.sh new file mode 100644 index 000000000..817186000 --- /dev/null +++ b/process/received.sh @@ -0,0 +1 @@ +grep -hiw ERESSEA orders.dir/turn-* | cut -d\ -f2 | sort -u diff --git a/process/run-turn.sh b/process/run-turn.sh new file mode 100755 index 000000000..9cc4e4ffd --- /dev/null +++ b/process/run-turn.sh @@ -0,0 +1,22 @@ +GAME=$1 +TURN=$2 + +if [ ! -d $ERESSEA/game-$GAME ] ; then + echo "No such game: $GAME" + exit 1 +fi + +cd $ERESSEA/game-$GAME +if [ -z $TURN ]; then + TURN=$(cat turn) +fi + +echo "running turn $TURN, game $GAME" +if [ -d orders.dir.$TURN ]; then + echo "orders.dir.$TURN already exists" +else + mv orders.dir orders.dir.$TURN + mkdir -p orders.dir +fi +ls -1rt orders.dir.$TURN/turn-* | xargs cat > orders.$TURN +$ERESSEA/bin/eressea -t $TURN run-turn.lua diff --git a/process/sendreports.sh b/process/sendreports.sh new file mode 100755 index 000000000..fc24200b6 --- /dev/null +++ b/process/sendreports.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +## +## Prepare the report + +if [ -z $ERESSEA ]; then + echo "You have to define the \$ERESSEA environment variable to run $0" + exit -2 +fi +source $HOME/bin/functions.sh +source $ERESSEA/etc/eressea.conf + +if [ ! -z $1 ]; then + GAME=$ERESSEA/game-$1 +else + GAME=$ERESSEA +fi + +cd $GAME/reports || abort "could not chdir to reports directory" +for REPORT in *.sh +do + echo -n "Sending " + basename $REPORT .sh + bash $REPORT +done +cd - + +if [ -e $GAME/ages.sh ]; then + cd $GAME + ./ages.sh + cd - +fi + diff --git a/s/travis-build b/s/travis-build index a6c920340..414a70f80 100755 --- a/s/travis-build +++ b/s/travis-build @@ -19,3 +19,4 @@ inifile s/runtests cd tests ./write-reports.sh +./run-turn.sh diff --git a/tests/run-turn.sh b/tests/run-turn.sh new file mode 100755 index 000000000..9bfe19ba6 --- /dev/null +++ b/tests/run-turn.sh @@ -0,0 +1,44 @@ +NEWFILES="data/185.dat datum parteien parteien.full passwd score turn" +cleanup () { +rm -rf reports $NEWFILES +} + +setup() { +ln -sf ../scripts/config.lua +} + +quit() { +test -n "$2" && echo $2 +exit $1 +} + +ROOT=`pwd` +while [ ! -d $ROOT/.git ]; do + ROOT=`dirname $ROOT` +done + +set -e +cd $ROOT/tests +setup +cleanup +VALGRIND=`which valgrind` +SERVER=../Debug/eressea/eressea +if [ -n "$VALGRIND" ]; then +SUPP=../share/ubuntu-12_04.supp +SERVER="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER" +fi +echo "running $SERVER" +$SERVER -t 184 ../scripts/run-turn.lua +[ -d reports ] || quit 4 "no reports directory created" +CRFILE=185-zvto.cr +for file in $NEWFILES reports/$CRFILE ; do + [ -e $file ] || quit 5 "did not create $file" +done +grep -q PARTEI reports/$CRFILE || quit 1 "CR did not contain any factions" +grep -q REGION reports/$CRFILE || quit 2 "CR did not contain any regions" +grep -q SCHIFF reports/$CRFILE || quit 3 "CR did not contain any ships" +grep -q BURG reports/$CRFILE || quit 4 "CR did not contain any buildings" +grep -q EINHEIT reports/$CRFILE || quit 5 "CR did not contain any units" +grep -q GEGENSTAENDE reports/$CRFILE || quit 6 "CR did not contain any items" +echo "integration tests: PASS" +cleanup From 2e11994155f01c1e6886e44af8632c3cbd1adfa0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 7 Sep 2015 15:40:12 +0200 Subject: [PATCH 2/4] hard-code the expected number of entries in the CR for a tighter test. --- tests/run-turn.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/run-turn.sh b/tests/run-turn.sh index 9bfe19ba6..0cee4ce5b 100755 --- a/tests/run-turn.sh +++ b/tests/run-turn.sh @@ -9,9 +9,18 @@ ln -sf ../scripts/config.lua quit() { test -n "$2" && echo $2 +echo "integration tests: FAILED" exit $1 } +assert_grep_count() { +file=$1 +expr=$2 +expect=$3 +count=`grep -cE $expr $file` +[ $count -eq $expect ] || quit 1 "expected $expect counts of $expr in $file, got $count" +} + ROOT=`pwd` while [ ! -d $ROOT/.git ]; do ROOT=`dirname $ROOT` @@ -34,11 +43,11 @@ CRFILE=185-zvto.cr for file in $NEWFILES reports/$CRFILE ; do [ -e $file ] || quit 5 "did not create $file" done -grep -q PARTEI reports/$CRFILE || quit 1 "CR did not contain any factions" -grep -q REGION reports/$CRFILE || quit 2 "CR did not contain any regions" -grep -q SCHIFF reports/$CRFILE || quit 3 "CR did not contain any ships" -grep -q BURG reports/$CRFILE || quit 4 "CR did not contain any buildings" -grep -q EINHEIT reports/$CRFILE || quit 5 "CR did not contain any units" -grep -q GEGENSTAENDE reports/$CRFILE || quit 6 "CR did not contain any items" +assert_grep_count reports/$CRFILE '^REGION' 7 +assert_grep_count reports/$CRFILE '^PARTEI' 2 +assert_grep_count reports/$CRFILE '^SCHIFF' 1 +assert_grep_count reports/$CRFILE '^BURG' 1 +assert_grep_count reports/$CRFILE '^EINHEIT' 2 +assert_grep_count reports/$CRFILE '^GEGENSTAENDE' 2 echo "integration tests: PASS" cleanup From aa394feb8003ff4b2fec06fb41b857ad2085e787 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 7 Sep 2015 15:57:08 +0200 Subject: [PATCH 3/4] make test data humans, not vampunicorn (what happened there?) --- tests/data/184.dat | Bin 7773 -> 7612 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/tests/data/184.dat b/tests/data/184.dat index ffe368510a226707f8cc399f4618e898a433fd55..dad439d814be3a08ec7a277a68d2541c80cc08db 100644 GIT binary patch delta 738 zcmca>v&UL0hLM4Ri2(?hm{aponk+y}zQ%bS>lXW?bWpCT@nw@hr&ZZDrw~ ze3%8?g@= F765z4;qL$d delta 885 zcmdmEeb+`ZnvsEliGhKEk%>7qFQv%>$YkJaoY%oVQA&@SyDTxcpfoQtIlpM~LnhgY zSppNQbudIv@=v^}jV?M_jgfz{86$@3$t{cmlc!>e^D;SgiZd{P9MQYNVDd*sblc^4 z9bpO@8&``@4q!r8Av<{i6aVB5Oz3v%Oy*-o7n7YF!z?g47mN6Ap!gXq;!-REleJke z&8cMJpWKN>{5nwm3oPPhtaGLO5|cAZQZw^1@{95q7#Wa*c><^IW)Ze2Oa#iif+fJq(N*C9_h^i;s@}C2FSaClG!W(da*E^ From 84aa0beee5dcd365921140c1687fbaf05070903f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 7 Sep 2015 16:11:58 +0200 Subject: [PATCH 4/4] create a more complex integration test for a unit that sails with a ship (and sees more regions along the way). --- tests/data/184.dat | Bin 7612 -> 7632 bytes tests/orders.184 | 4 ++++ tests/run-turn.sh | 3 +++ 3 files changed, 7 insertions(+) diff --git a/tests/data/184.dat b/tests/data/184.dat index dad439d814be3a08ec7a277a68d2541c80cc08db..734e5a19fd610d5aee2e81843190b8076a84dbb3 100644 GIT binary patch delta 72 zcmdmEeZhKz50?z%>kImvPWkyI3Yq0eRSYai`H3a03=EFUsd*`reYxbNfbt9+?2bWB buAU*T4E(IDj;y))d8w8A6gKyA=?en@PEHlP delta 22 ecmca$y~lck4;LfD