2#include <libmesh/ignore_warnings.h>
3#include <cppunit/extensions/TestFactoryRegistry.h>
4#include <cppunit/ui/text/TestRunner.h>
5#include <cppunit/BriefTestProgressListener.h>
6#include <cppunit/TestPath.h>
7#include <cppunit/TestResult.h>
8#include <cppunit/TestListener.h>
9#include <cppunit/TestFailure.h>
10#include <cppunit/Exception.h>
11#include <libmesh/restore_warnings.h>
14#include <libmesh/libmesh.h>
15#include <libmesh/libmesh_abort.h>
45 virtual void addFailure(
const CppUnit::TestFailure & failure)
override;
51 << failure.failedTestName()
52 << (failure.isError() ?
" error" :
" failure");
54 const CppUnit::SourceLine source_line = failure.sourceLine();
55 if (source_line.isValid())
57 <<
":" << source_line.lineNumber();
59 libMesh::err <<
":\n" << failure.thrownException()->what() << std::endl;
65#ifdef LIBMESH_HAVE_CXX11_REGEX
93 virtual bool findTestPath (
const std::string & testName, CppUnit::TestPath & testPath)
const override {
return _shimmed_test.findTestPath(testName, testPath); }
95 virtual bool findTestPath (
const CppUnit::Test * test, CppUnit::TestPath & testPath)
const override {
return _shimmed_test.findTestPath(test, testPath); }
97 virtual CppUnit::Test *
findTest(
const std::string & testName)
const override {
return _shimmed_test.findTest(testName); }
113 const std::string & allow_r_str,
114 const std::regex & allow_r,
115 const std::string & deny_r_str,
116 const std::regex & deny_r,
117 CppUnit::TextUi::TestRunner & runner)
119 int n_tests_added = 0;
122 if (test->getName() ==
"All Tests" && allow_r_str ==
"All Tests" &&
126 runner.addTest(test);
130 if (test->getChildTestCount() == 0)
133 if ((allow_r_str ==
"All Tests" ||
134 std::regex_search(test->getName(), allow_r)) &&
135 !std::regex_search(test->getName(), deny_r))
141 runner.addTest(
new TestShim(*test));
146 for (
int i = 0; i < test->getChildTestCount(); i++)
149 deny_r_str, deny_r, runner);
151 return n_tests_added;
157int main(
int argc,
char ** argv)
201 std::string allow_regex_string =
"All Tests";
205 std::string deny_regex_string =
"^$";
210 std::unique_ptr<CppUnit::Test> owned_suite;
213 CppUnit::TextUi::TestRunner runner;
217 CppUnit::TestFactoryRegistry & registry = CppUnit::TestFactoryRegistry::getRegistry();
218 CppUnit::Test * suite = registry.makeTest();
220#ifdef LIBMESH_HAVE_CXX11_REGEX
222 const std::regex allow_regex(allow_regex_string);
223 const std::regex deny_regex(deny_regex_string);
226 libMesh::out <<
"Will run the following tests:" << std::endl;
227 const int n_tests_added =
229 allow_regex_string, allow_regex,
230 deny_regex_string, deny_regex,
232 if (n_tests_added >= 0)
233 libMesh::out <<
"--- Running " << n_tests_added <<
" tests in total." << std::endl;
238 owned_suite.
reset(suite);
241 runner.addTest(suite);
244 std::unique_ptr<CppUnit::TestResult> controller;
245 std::unique_ptr<CppUnit::BriefTestProgressListener> listener;
251 listener = std::make_unique<CppUnit::BriefTestProgressListener>();
252 runner.eventManager().addListener(listener.get());
256 runner.eventManager().addListener(&failure_reporter);
258 bool succeeded = runner.run();
261#ifndef LIBMESH_ENABLE_PERFORMANCE_LOGGING
263 driver_unitlog.
clear();
virtual void addFailure(const CppUnit::TestFailure &failure) override
virtual int getChildTestCount() const override
virtual std::string getName() const override
virtual void run(CppUnit::TestResult *result) override
virtual int countTestCases() const override
virtual bool findTestPath(const CppUnit::Test *test, CppUnit::TestPath &testPath) const override
TestShim(CppUnit::Test &shimmed_test)
virtual CppUnit::TestPath resolveTestPath(const std::string &testPath) const override
virtual CppUnit::Test * findTest(const std::string &testName) const override
virtual CppUnit::Test * doGetChildTestAt(int index) const override
CppUnit::Test & _shimmed_test
virtual bool findTestPath(const std::string &testName, CppUnit::TestPath &testPath) const override
void reset(streamT &target)
Reset the proxy to point to a different target.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The PerfLog class allows monitoring of specific events.
void clear()
Clears all the internal data and restores the data structures to a pristine state.
void enable_summarized_logs()
Tells the PerfLog to only print log results summarized by header.
static constexpr int added_whole_suite
libMesh::PerfLog * unitlog
libMesh::Parallel::Communicator * TestCommWorld
int add_matching_tests_to_runner(CppUnit::Test *test, const std::string &allow_r_str, const std::regex &allow_r, const std::string &deny_r_str, const std::regex &deny_r, CppUnit::TextUi::TestRunner &runner)
processor_id_type global_processor_id()
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
processor_id_type global_n_processors()
void libmesh_abort()
Abort as soon as possible.
bool on_command_line(std::string arg)