Add test harness backend flag "compact"
[xapian.git] / xapian-core / tests / harness / testrunner.cc
blob3721d4db16156affda2570a9c7087441601be963
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,2018 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_inmemory.h"
31 #include "backendmanager_multi.h"
32 #include "backendmanager_remoteprog.h"
33 #include "backendmanager_remotetcp.h"
34 #include "backendmanager_singlefile.h"
36 #include "stringutils.h"
37 #include <iostream>
39 using namespace std;
41 BackendManager * backendmanager;
43 TestRunner::~TestRunner() { }
45 bool
46 TestRunner::use_backend(const string & backend_name)
48 if (user_backend.empty())
49 return true;
50 if (backend_name == user_backend)
51 return true;
52 if (startswith(backend_name, user_backend + "_"))
53 return true;
54 return false;
57 void
58 TestRunner::set_properties_for_backend(const string & backend_name)
60 /// A description of the properties which a particular backend supports.
61 struct BackendProperties {
62 const char * name;
63 unsigned properties;
66 /// A list of the properties of each backend.
67 static const BackendProperties backend_properties[] = {
68 { "none", 0 },
69 { "inmemory", INMEMORY|
70 BACKEND|POSITIONAL|WRITABLE|METADATA|VALUESTATS },
71 { "glass", GLASS|
72 BACKEND|TRANSACTIONS|POSITIONAL|WRITABLE|SPELLING|METADATA|
73 SYNONYMS|VALUESTATS|GENERATED|COMPACT
74 #ifdef XAPIAN_HAS_REMOTE_BACKEND
75 |REPLICAS
76 #endif
78 { "multi_glass", MULTI|
79 BACKEND|POSITIONAL|WRITABLE|METADATA|
80 SYNONYMS|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 { NULL, 0 }
90 for (const BackendProperties * i = backend_properties; i->name; ++i) {
91 if (backend_name == i->name) {
92 properties = i->properties;
93 return;
96 throw Xapian::InvalidArgumentError("Unknown backend " + backend_name);
99 void
100 TestRunner::do_tests_for_backend_(BackendManager* manager)
102 const string& backend_name = manager->get_dbtype();
103 if (use_backend(backend_name)) {
104 set_properties_for_backend(backend_name);
105 cout << "Running tests with backend \"" << backend_name << "\"..."
106 << endl;
107 backendmanager = manager;
108 result_so_far = max(result_so_far, run());
109 backendmanager = NULL;
114 TestRunner::run_tests(int argc, char ** argv)
116 result_so_far = 0;
117 try {
118 test_driver::add_command_line_option("backend", 'b', &user_backend);
119 test_driver::parse_command_line(argc, argv);
120 srcdir = test_driver::get_srcdir();
121 string datadir = srcdir + "/testdata/";
123 do_tests_for_backend(BackendManager(string()));
125 #ifdef XAPIAN_HAS_INMEMORY_BACKEND
126 do_tests_for_backend(BackendManagerInMemory(datadir));
127 #endif
129 #ifdef XAPIAN_HAS_GLASS_BACKEND
131 BackendManagerGlass glass_man(datadir);
132 do_tests_for_backend(glass_man);
133 do_tests_for_backend(BackendManagerSingleFile(datadir, &glass_man));
134 do_tests_for_backend(BackendManagerMulti(datadir, &glass_man));
135 # ifdef XAPIAN_HAS_REMOTE_BACKEND
136 do_tests_for_backend(BackendManagerRemoteProg(&glass_man));
137 do_tests_for_backend(BackendManagerRemoteTcp(&glass_man));
138 # endif
140 #endif
141 } catch (const Xapian::Error &e) {
142 cerr << "\nTest harness failed with " << e.get_description() << endl;
143 return 1;
144 } catch (const std::string &e) {
145 cerr << "\nTest harness failed with \"" << e << "\"" << endl;
146 return 1;
147 } catch (const char * e) {
148 cout << e << endl;
149 return 1;
151 return result_so_far;