From b52238388778947f9395eeacc46fbd531b44fd01 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 8 Nov 2017 14:35:29 +1300 Subject: [PATCH] Make TEST_EQUAL() arguments side-effect free TEST_EQUAL() is a macro which evaluates its arguments a second time if the test fails, to report their values. This isn't ideal and really ought to be addressed, but for now fix uses where the argument has side-effect (e.g. *i++) such that the reported value should match the tested value. --- xapian-core/tests/api_anydb.cc | 6 ++++-- xapian-core/tests/api_geospatial.cc | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/xapian-core/tests/api_anydb.cc b/xapian-core/tests/api_anydb.cc index 2baf53a8d..0be2d87fe 100644 --- a/xapian-core/tests/api_anydb.cc +++ b/xapian-core/tests/api_anydb.cc @@ -1008,9 +1008,10 @@ DEFINE_TESTCASE(reversebool1, backend) { Xapian::MSetIterator i = mymset1.begin(); Xapian::MSetIterator j = mymset3.end(); for ( ; i != mymset1.end(); ++i) { + --j; // if this fails, then setting match_sort_forward=false didn't // reverse the results. - TEST_EQUAL(*i, *--j); + TEST_EQUAL(*i, *j); } } @@ -1057,7 +1058,8 @@ DEFINE_TESTCASE(reversebool2, backend) { for (j = mymset3.begin(); j != mymset3.end(); ++j) { // if this fails, then setting match_sort_forward=false didn't // reverse the results. - TEST_EQUAL(*--i, *j); + --i; + TEST_EQUAL(*i, *j); } } diff --git a/xapian-core/tests/api_geospatial.cc b/xapian-core/tests/api_geospatial.cc index 828482814..af908a885 100644 --- a/xapian-core/tests/api_geospatial.cc +++ b/xapian-core/tests/api_geospatial.cc @@ -313,11 +313,13 @@ DEFINE_TESTCASE(latlongcoords1, !backend) { i1 = g1.begin(); TEST(i1 != g1.end()); TEST_EQUAL((*i1).serialise(), c1.serialise()); - TEST_EQUAL((*(i1++)).serialise(), c1.serialise()); + TEST_EQUAL((*i1).serialise(), c1.serialise()); + ++i1; TEST(i1 != g1.end()); TEST_EQUAL((*i1).serialise(), c2.serialise()); i1 = g1.begin(); - TEST_EQUAL((*(++i1)).serialise(), c2.serialise()); + ++i1; + TEST_EQUAL((*i1).serialise(), c2.serialise()); TEST(i1 != g1.end()); ++i1; TEST(i1 == g1.end()); -- 2.11.4.GIT