From 9a05b416373fda505dd851309a3b1e3b3bcdf800 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 30 May 2016 17:55:31 +1200 Subject: [PATCH] Use << instead of + with FAIL_TEST and SKIP_TEST The argument is carefully handled such that << works, and it avoids creating temporary string objects so is more efficient, and also more readable for cases like std::string("Literal") + char_ptr. --- xapian-core/tests/api_queryparser.cc | 4 ++-- xapian-core/tests/api_replicate.cc | 12 ++++++------ xapian-core/tests/api_snippets.cc | 2 +- xapian-core/tests/apitest.cc | 4 ++-- xapian-core/tests/harness/cputimer.cc | 4 ++-- xapian-core/tests/stemtest.cc | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/xapian-core/tests/api_queryparser.cc b/xapian-core/tests/api_queryparser.cc index 16a66e37f..cd4f481a3 100644 --- a/xapian-core/tests/api_queryparser.cc +++ b/xapian-core/tests/api_queryparser.cc @@ -746,7 +746,7 @@ DEFINE_TESTCASE(queryparser1, !backend) { flags = queryparser.FLAG_DEFAULT|queryparser.FLAG_CJK_NGRAM; continue; } - FAIL_TEST(string("Unknown flag code: ") + p->expect); + FAIL_TEST("Unknown flag code: " << p->expect); } string expect, parsed; if (p->expect) @@ -817,7 +817,7 @@ DEFINE_TESTCASE(qp_default_op1, !backend) { flags = queryparser.FLAG_DEFAULT|queryparser.FLAG_CJK_NGRAM; continue; } - FAIL_TEST(string("Unknown flag code: ") + p->expect); + FAIL_TEST("Unknown flag code: " << p->expect); } string expect, parsed; if (p->expect) diff --git a/xapian-core/tests/api_replicate.cc b/xapian-core/tests/api_replicate.cc index b2d15fae8..8c311630b 100644 --- a/xapian-core/tests/api_replicate.cc +++ b/xapian-core/tests/api_replicate.cc @@ -64,7 +64,7 @@ static void mktmpdir(const string & path) { static off_t get_file_size(const string & path) { off_t size = file_size(path); if (errno) { - FAIL_TEST("Can't stat '" + path + "'"); + FAIL_TEST("Can't stat '" << path << "'"); } return size; } @@ -105,12 +105,12 @@ truncated_copy(const string & srcpath, const string & destpath, off_t tocopy) { FD fdin(open(srcpath.c_str(), O_RDONLY | O_BINARY)); if (fdin == -1) { - FAIL_TEST("Open failed (when opening '" + srcpath + "')"); + FAIL_TEST("Open failed (when opening '" << srcpath << "')"); } FD fdout(open(destpath.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666)); if (fdout == -1) { - FAIL_TEST("Open failed (when creating '" + destpath + "')"); + FAIL_TEST("Open failed (when creating '" << destpath << "')"); } const int BUFSIZE = 1024; @@ -145,7 +145,7 @@ get_changeset(const string & changesetpath, FD fd(open(changesetpath.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666)); if (fd == -1) { FAIL_TEST("Open failed (when creating a new changeset file at '" - + changesetpath + "')"); + << changesetpath << "')"); } Xapian::ReplicationInfo info1; master.write_changesets_to_fd(fd, @@ -167,7 +167,7 @@ apply_changeset(const string & changesetpath, FD fd(open(changesetpath.c_str(), O_RDONLY | O_BINARY)); if (fd == -1) { FAIL_TEST("Open failed (when reading changeset file at '" - + changesetpath + "')"); + << changesetpath << "')"); } int count = 1; @@ -877,7 +877,7 @@ DEFINE_TESTCASE(replicate7, replicas) { if (!entry) { if (errno == 0) break; - FAIL_TEST(string("readdir failed: ") + strerror(errno)); + FAIL_TEST("readdir failed: " << strerror(errno)); } // Skip '.' and '..'. diff --git a/xapian-core/tests/api_snippets.cc b/xapian-core/tests/api_snippets.cc index 239de1d0a..714deb8b1 100644 --- a/xapian-core/tests/api_snippets.cc +++ b/xapian-core/tests/api_snippets.cc @@ -141,7 +141,7 @@ make_tg_db(Xapian::WritableDatabase &db, const string & source) ifstream input; input.open(file.c_str()); if (!input.is_open()) { - FAIL_TEST("Couldn't open input: " + file); + FAIL_TEST("Couldn't open input: " << file); } Xapian::TermGenerator tg; diff --git a/xapian-core/tests/apitest.cc b/xapian-core/tests/apitest.cc index 08e75981d..463f9ca44 100644 --- a/xapian-core/tests/apitest.cc +++ b/xapian-core/tests/apitest.cc @@ -124,7 +124,7 @@ void skip_test_unless_backend(const std::string & backend_prefix) { if (!startswith(get_dbtype(), backend_prefix)) { - SKIP_TEST("Test only supported for " + backend_prefix + " backend"); + SKIP_TEST("Test only supported for " << backend_prefix << " backend"); } } @@ -132,7 +132,7 @@ void skip_test_for_backend(const std::string & backend_prefix) { if (startswith(get_dbtype(), backend_prefix)) { - SKIP_TEST("Test not supported for " + backend_prefix + " backend"); + SKIP_TEST("Test not supported for " << backend_prefix << " backend"); } } diff --git a/xapian-core/tests/harness/cputimer.cc b/xapian-core/tests/harness/cputimer.cc index 1296d4724..68a19328d 100644 --- a/xapian-core/tests/harness/cputimer.cc +++ b/xapian-core/tests/harness/cputimer.cc @@ -58,7 +58,7 @@ CPUTimer::get_current_cputime() const #ifdef HAVE_GETRUSAGE struct rusage r; if (getrusage(RUSAGE_SELF, &r) == -1) { - FAIL_TEST(string("Couldn't measure CPU for self: ") + strerror(errno)); + FAIL_TEST("Couldn't measure CPU for self: " << strerror(errno)); } t = r.ru_utime.tv_sec + r.ru_stime.tv_sec; @@ -66,7 +66,7 @@ CPUTimer::get_current_cputime() const #elif defined HAVE_TIMES struct tms b; if (times(&b) == (clock_t)-1) { - FAIL_TEST(string("Couldn't measure CPU: ") + strerror(errno)); + FAIL_TEST("Couldn't measure CPU: " << strerror(errno)); } t = (double)(b.tms_utime + b.tms_stime); # ifdef HAVE_SYSCONF diff --git a/xapian-core/tests/stemtest.cc b/xapian-core/tests/stemtest.cc index 47f52ee52..1a4c857a9 100644 --- a/xapian-core/tests/stemtest.cc +++ b/xapian-core/tests/stemtest.cc @@ -119,13 +119,13 @@ test_stemdict() ifstream voc((dir + language + "/voc.txt").c_str()); if (!voc.is_open()) { - SKIP_TEST(language + "/voc.txt not found"); + SKIP_TEST(language << "/voc.txt not found"); } ifstream st((dir + language + "/output.txt").c_str()); if (!st.is_open()) { voc.close(); - FAIL_TEST(language + "/output.txt not found"); + FAIL_TEST(language << "/output.txt not found"); } tout << "Testing " << language << " with Snowball dictionary..." << endl; @@ -152,7 +152,7 @@ test_stemdict() st.open((dir + language + "/output2.txt").c_str()); if (!st.is_open()) { voc.close(); - FAIL_TEST(language + "/output2.txt not found"); + FAIL_TEST(language << "/output2.txt not found"); } tout << "Testing " << language << " with supplemental dictionary..." << endl; -- 2.11.4.GIT