Finish adding honey backend to test harness
[xapian.git] / xapian-core / tests / harness / testrunner.cc
blob8d1f528de8b68f739a8733515666d6b725423a4a
1 /** @file testrunner.cc
2 * @brief Run multiple tests for different backends.
3 */
4 /* Copyright 2008,2009 Lemur Consulting Ltd
5 * Copyright 2008,2009,2010,2011,2015,2017 Olly Betts
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 * USA
23 #include <config.h>
25 #include "testrunner.h"
27 #include "testsuite.h"
28 #include "backendmanager.h"
29 #include "backendmanager_glass.h"
30 #include "backendmanager_honey.h"
31 #include "backendmanager_inmemory.h"
32 #include "backendmanager_multi.h"
33 #include "backendmanager_remoteprog.h"
34 #include "backendmanager_remotetcp.h"
35 #include "backendmanager_singlefile.h"
37 #include "stringutils.h"
38 #include <iostream>
40 using namespace std;
42 BackendManager * backendmanager;
44 TestRunner::~TestRunner() { }
46 bool
47 TestRunner::use_backend(const string & backend_name)
49 if (user_backend.empty())
50 return true;
51 if (backend_name == user_backend)
52 return true;
53 if (startswith(backend_name, user_backend + "_"))
54 return true;
55 return false;
58 void
59 TestRunner::set_properties_for_backend(const string & backend_name)
61 /// A description of the properties which a particular backend supports.
62 struct BackendProperties {
63 const char * name;
64 unsigned properties;
67 /// A list of the properties of each backend.
68 static const BackendProperties backend_properties[] = {
69 { "none", 0 },
70 { "inmemory", INMEMORY|
71 BACKEND|POSITIONAL|WRITABLE|METADATA|VALUESTATS },
72 { "glass", GLASS|
73 BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|SPELLING|METADATA|
74 SYNONYMS|VALUESTATS|GENERATED
75 #ifdef XAPIAN_HAS_REMOTE_BACKEND
76 |REPLICAS
77 #endif
79 { "multi_glass", MULTI|
80 BACKEND|POSITIONAL|VALUESTATS },
81 { "remoteprog_glass", REMOTE|
82 BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS },
83 { "remotetcp_glass", REMOTE|
84 BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|METADATA|VALUESTATS },
85 { "singlefile_glass", SINGLEFILE|
86 BACKEND|POSITIONAL|VALUESTATS },
87 { "honey", HONEY|
88 BACKEND|POSITIONAL|VALUESTATS },
89 { NULL, 0 }
92 for (const BackendProperties * i = backend_properties; i->name; ++i) {
93 if (backend_name == i->name) {
94 properties = i->properties;
95 return;
98 throw Xapian::InvalidArgumentError("Unknown backend " + backend_name);
101 void
102 TestRunner::do_tests_for_backend(BackendManager&& manager)
104 const string& backend_name = manager.get_dbtype();
105 if (use_backend(backend_name)) {
106 manager.set_datadir(srcdir + "/testdata/");
107 set_properties_for_backend(backend_name);
108 cout << "Running tests with backend \"" << backend_name << "\"..."
109 << endl;
110 backendmanager = &manager;
111 result_so_far = max(result_so_far, run());
112 backendmanager = NULL;
117 TestRunner::run_tests(int argc, char ** argv)
119 result_so_far = 0;
120 try {
121 test_driver::add_command_line_option("backend", 'b', &user_backend);
122 test_driver::parse_command_line(argc, argv);
123 srcdir = test_driver::get_srcdir();
125 #ifdef XAPIAN_HAS_HONEY_BACKEND
126 do_tests_for_backend(BackendManagerHoney());
127 #endif
129 do_tests_for_backend(BackendManager());
131 #ifdef XAPIAN_HAS_INMEMORY_BACKEND
132 do_tests_for_backend(BackendManagerInMemory());
133 #endif
135 #ifdef XAPIAN_HAS_GLASS_BACKEND
136 do_tests_for_backend(BackendManagerGlass());
137 do_tests_for_backend(BackendManagerSingleFile("glass"));
138 do_tests_for_backend(BackendManagerMulti("glass"));
139 # ifdef XAPIAN_HAS_REMOTE_BACKEND
140 do_tests_for_backend(BackendManagerRemoteProg("glass"));
141 do_tests_for_backend(BackendManagerRemoteTcp("glass"));
142 # endif
143 #endif
144 } catch (const Xapian::Error &e) {
145 cerr << "\nTest harness failed with " << e.get_description() << endl;
146 return 1;
147 } catch (const std::string &e) {
148 cerr << "\nTest harness failed with \"" << e << "\"" << endl;
149 return 1;
150 } catch (const char * e) {
151 cout << e << endl;
152 return 1;
154 return result_so_far;