1 /** @file testrunner.cc
2 * @brief Run multiple tests for different backends.
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
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"
42 BackendManager
* backendmanager
;
44 TestRunner::~TestRunner() { }
47 TestRunner::use_backend(const string
& backend_name
)
49 if (user_backend
.empty())
51 if (backend_name
== user_backend
)
53 if (startswith(backend_name
, user_backend
+ "_"))
59 TestRunner::set_properties_for_backend(const string
& backend_name
)
61 /// A description of the properties which a particular backend supports.
62 struct BackendProperties
{
67 /// A list of the properties of each backend.
68 static const BackendProperties backend_properties
[] = {
70 { "inmemory", INMEMORY
|
71 BACKEND
|POSITIONAL
|WRITABLE
|METADATA
|VALUESTATS
},
73 BACKEND
|TRANSACTIONS
|POSITIONAL
|WRITABLE
|SPELLING
|METADATA
|
74 SYNONYMS
|VALUESTATS
|GENERATED
75 #ifdef XAPIAN_HAS_REMOTE_BACKEND
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
},
88 BACKEND
|POSITIONAL
|VALUESTATS
},
92 for (const BackendProperties
* i
= backend_properties
; i
->name
; ++i
) {
93 if (backend_name
== i
->name
) {
94 properties
= i
->properties
;
98 throw Xapian::InvalidArgumentError("Unknown backend " + backend_name
);
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
<< "\"..."
110 backendmanager
= &manager
;
111 result_so_far
= max(result_so_far
, run());
112 backendmanager
= NULL
;
117 TestRunner::run_tests(int argc
, char ** argv
)
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());
129 do_tests_for_backend(BackendManager());
131 #ifdef XAPIAN_HAS_INMEMORY_BACKEND
132 do_tests_for_backend(BackendManagerInMemory());
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"));
144 } catch (const Xapian::Error
&e
) {
145 cerr
<< "\nTest harness failed with " << e
.get_description() << endl
;
147 } catch (const std::string
&e
) {
148 cerr
<< "\nTest harness failed with \"" << e
<< "\"" << endl
;
150 } catch (const char * e
) {
154 return result_so_far
;