ROSE 0.11.145.192
SelfTest.h
1#ifndef ROSE_CommandLine_SelfTest_H
2#define ROSE_CommandLine_SelfTest_H
3#include <RoseFirst.h>
4
5#include <rosedll.h>
6
7#include <Sawyer/CommandLine.h>
8#include <Sawyer/SharedObject.h>
9#include <Sawyer/SharedPointer.h>
10
11namespace Rose {
12namespace CommandLine {
13
19class ROSE_DLL_API SelfTest: public Sawyer::SharedObject {
20public:
22
27 virtual std::string name() const = 0;
28
32 virtual bool operator()() = 0;
33};
34
39ROSE_DLL_API extern std::vector<SelfTest::Ptr> selfTests;
40
45ROSE_DLL_API void runSelfTestsAndExit();
46
48template<class SelfTest>
50 selfTests.push_back(typename SelfTest::Ptr(new SelfTest));
51}
52
55protected:
56 SelfTests() {}
57
58public:
60
61 static Ptr instance() {
62 return Ptr(new SelfTests);
63 }
64
65protected:
66 void operator()(const Sawyer::CommandLine::ParserResult &cmdline) {
67 ASSERT_always_require(cmdline.have("self-test"));
69 }
70};
71
72} // namespace
73} // namespace
74
75#endif
Base class for self tests.
Definition SelfTest.h:19
virtual bool operator()()=0
The actual test.
virtual std::string name() const =0
Short name for test.
Run self tests from the command-line, then exit.
Definition SelfTest.h:54
The result from parsing a command line.
size_t have(const std::string &switchKey) const
Returns the number of values for the specified key.
Base class for switch actions.
Base class for reference counted objects.
Reference-counting intrusive smart pointer.
ROSE_DLL_API void runSelfTestsAndExit()
Runs the self tests and then exits the program.
void insertSelfTest()
Convenient way to add a command-line self test.
Definition SelfTest.h:49
ROSE_DLL_API std::vector< SelfTest::Ptr > selfTests
Collection of self tests to be run by –self-tests switch.
The ROSE library.