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