diff --git a/.travis.yml b/.travis.yml index cbf3ff239..da3381bdc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ compiler: script: s/travis-build before_install: - sudo apt-get update -qq - - sudo apt-get install -qq libtolua-dev liblua5.1-dev libncurses5-dev libsqlite3-dev libxml2-dev + - sudo apt-get install -qq zlib1g-dev libtolua-dev liblua5.1-dev libncurses5-dev libsqlite3-dev libxml2-dev valgrind os: - linux - osx diff --git a/s/runtests b/s/runtests index ef7fc71df..17df4e165 100755 --- a/s/runtests +++ b/s/runtests @@ -1,4 +1,7 @@ #!/bin/bash + +set -e + ROOT=$(pwd) while [ ! -d $ROOT/.git ]; do ROOT=$(dirname $ROOT) @@ -21,4 +24,5 @@ cd $ROOT $ROOT/$BIN_DIR/eressea/eressea -v0 scripts/run-tests.lua $ROOT/$BIN_DIR/eressea/eressea -v0 scripts/run-tests-e2.lua $ROOT/$BIN_DIR/eressea/eressea -v0 scripts/run-tests-e3.lua + cd $OLDWPD diff --git a/s/travis-build b/s/travis-build index b34b90d02..4724d04b0 100755 --- a/s/travis-build +++ b/s/travis-build @@ -1,18 +1,63 @@ #!/bin/sh +set -e +ROOT=`pwd` +MACHINE=`uname -m` +[ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc" +[ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc" +[ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" +BUILD="$ROOT/build-$MACHINE-$CC-Debug" + inifile() { +cd $ROOT if [ ! -e eressea.ini ]; then cp conf/eressea.ini . -build/iniparser/inifile eressea.ini add lua:paths lunit:scripts +$BUILD/iniparser/inifile eressea.ini add lua:paths lunit:scripts fi } -[ -d build ] || mkdir build -cd build && cmake .. \ - -DCMAKE_MODULE_PATH=$PWD/../cmake/Modules \ - -DCMAKE_BUILD_TYPE=Debug .. && \ -make && cd .. && inifile && -build/eressea/test_eressea && -build/eressea/eressea -v0 scripts/run-tests.lua -build/eressea/eressea -v0 scripts/run-tests-e2.lua -build/eressea/eressea -v0 scripts/run-tests-e3.lua +build() { +cd $BUILD +cmake -DCMAKE_MODULE_PATH=$ROOT/cmake/Modules -DCMAKE_BUILD_TYPE=Debug .. +make +} + +test_valgrind_report () { +cd tests +ln -sf ../scripts/config.lua +valgrind --suppressions=ubuntu-12_04.supp --error-exitcode=1 $BUILD/eressea/eressea -v0 -t184 ../scripts/reports.lua +} + +test_unittests() { +$BUILD/eressea/test_eressea +} + +cleanup() { +cd $ROOT/tests +rm -rf reports score eressea.log* config.lua +} + +test_server() { +cd $ROOT +inifile +$BUILD/eressea/eressea -v0 scripts/run-tests.lua +$BUILD/eressea/eressea -v0 scripts/run-tests-e2.lua +$BUILD/eressea/eressea -v0 scripts/run-tests-e3.lua +} +# information +echo "* base directory: $ROOT" +echo "* build directory: $BUILD" +echo "* lsb_release:" +lsb_release -a +echo "* zlib1g-dev package:" +dpkg -l zlib1g-dev +echo + +# build the code +[ -d $BUILD ] || mkdir $BUILD +build +test_unittests +test_server +test_valgrind_report + +cleanup diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index 9f08b0f54..4a2b3e59e 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -19,4 +19,4 @@ require 'lunit' rules = require('eressea.' .. config.rules) result = lunit.main() -return result.errors +return result.errors + result.failed diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index 2f823daa7..47bcca60b 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -20,4 +20,4 @@ require 'lunit' eressea.settings.set("rules.alliances", "0") rules = require('eressea.' .. config.rules) result = lunit.main() -return result.errors +return result.errors + result.failed diff --git a/scripts/run-tests.lua b/scripts/run-tests.lua index d13a1425b..d1306ddcd 100644 --- a/scripts/run-tests.lua +++ b/scripts/run-tests.lua @@ -14,4 +14,4 @@ require 'eressea.path' require 'tests' require 'lunit' result = lunit.main() -return result.errors +return result.errors + result.failed diff --git a/scripts/tests/pool.lua b/scripts/tests/pool.lua index 2ac9c87f2..b89d180fa 100644 --- a/scripts/tests/pool.lua +++ b/scripts/tests/pool.lua @@ -8,6 +8,7 @@ function setup() eressea.settings.set("rules.economy.food", "0") eressea.settings.set("nmr.removenewbie", "0") eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("GiveRestriction", "0") eressea.settings.set("rules.magic.playerschools", "") conf = [[{ "races": { diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index 3ee3cf056..2befe6733 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -204,7 +204,8 @@ static void test_build_building_no_materials(CuTest *tc) { btype = bt_find("castle"); assert(btype); set_level(u, SK_BUILDING, 1); - CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, 0)); + u->orders = create_order(K_MAKE, u->faction->locale, 0); + CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, u->orders)); CuAssertPtrEquals(tc, 0, u->region->buildings); CuAssertPtrEquals(tc, 0, u->building); test_cleanup(); @@ -222,7 +223,8 @@ static void test_build_building_with_golem(CuTest *tc) { assert(btype->construction); set_level(bf.u, SK_BUILDING, 1); - CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 1, 0)); + u->orders = create_order(K_MAKE, u->faction->locale, 0); + CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 1, u->orders)); CuAssertPtrNotNull(tc, u->region->buildings); CuAssertIntEquals(tc, 1, u->region->buildings->size); CuAssertIntEquals(tc, 0, u->number); @@ -245,7 +247,8 @@ static void test_build_building_success(CuTest *tc) { i_change(&bf.u->items, rtype->itype, 1); set_level(u, SK_BUILDING, 1); - CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, 0)); + u->orders = create_order(K_MAKE, u->faction->locale, 0); + CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, u->orders)); CuAssertPtrNotNull(tc, u->region->buildings); CuAssertPtrEquals(tc, u->region->buildings, u->building); CuAssertIntEquals(tc, 1, u->building->size); diff --git a/src/kernel/order.c b/src/kernel/order.c index b72b8e6bd..20cce5853 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -65,6 +65,9 @@ static void release_data(order_data * data) void replace_order(order ** dlist, order * orig, const order * src) { + assert(src); + assert(orig); + assert(dlist); while (*dlist != NULL) { order *dst = *dlist; if (dst->data == orig->data) { diff --git a/src/kernel/order.test.c b/src/kernel/order.test.c index 414dd87e7..6900da420 100644 --- a/src/kernel/order.test.c +++ b/src/kernel/order.test.c @@ -143,6 +143,21 @@ static void test_skip_token(CuTest *tc) { CuAssertStrEquals(tc, 0, getstrtoken()); } +static void test_replace_order(CuTest *tc) { + order *orders = 0, *orig, *repl; + struct locale * lang = get_or_create_locale("en"); + + orig = create_order(K_MAKE, lang, 0); + repl = create_order(K_ALLY, lang, 0); + replace_order(&orders, orig, repl); + CuAssertPtrEquals(tc, 0, orders); + orders = orig; + replace_order(&orders, orig, repl); + CuAssertPtrNotNull(tc, orders); + CuAssertPtrEquals(tc, 0, orders->next); + CuAssertIntEquals(tc, getkeyword(repl), getkeyword(orders)); +} + CuSuite *get_order_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -152,6 +167,7 @@ CuSuite *get_order_suite(void) SUITE_ADD_TEST(suite, test_parse_make_temp); SUITE_ADD_TEST(suite, test_parse_maketemp); SUITE_ADD_TEST(suite, test_init_order); + SUITE_ADD_TEST(suite, test_replace_order); SUITE_ADD_TEST(suite, test_skip_token); SUITE_ADD_TEST(suite, test_getstrtoken); return suite; diff --git a/tests/data/184.dat b/tests/data/184.dat new file mode 100644 index 000000000..74d72258a Binary files /dev/null and b/tests/data/184.dat differ diff --git a/tests/eressea.ini b/tests/eressea.ini new file mode 100644 index 000000000..e84171d45 --- /dev/null +++ b/tests/eressea.ini @@ -0,0 +1,14 @@ +[eressea] +base = . +report = reports +verbose = 0 +lomem = 0 +debug = 0 +memcheck = 0 +locales = de,en + +[lua] +install = .. +paths = lunit:scripts +maxnmrs = 20 +rules = e2 diff --git a/tests/orders.184 b/tests/orders.184 new file mode 100644 index 000000000..e69de29bb diff --git a/tests/ubuntu-12_04.supp b/tests/ubuntu-12_04.supp new file mode 100644 index 000000000..29862fa2b --- /dev/null +++ b/tests/ubuntu-12_04.supp @@ -0,0 +1,16 @@ +{ + zlib1g-dev-1:1.2.3.4.dfsg + Memcheck:Cond + fun:inflateReset2 + fun:inflateInit2_ + obj:/usr/lib/x86_64-linux-gnu/libxml2.so.2.8.0 + fun:__libxml2_xzread + obj:/usr/lib/x86_64-linux-gnu/libxml2.so.2.8.0 + fun:xmlParserInputBufferGrow + fun:xmlParserInputGrow + obj:/usr/lib/x86_64-linux-gnu/libxml2.so.2.8.0 + fun:xmlParseDocument + obj:/usr/lib/x86_64-linux-gnu/libxml2.so.2.8.0 + fun:read_xml + fun:init_data +}