ROSE  0.11.96.11
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_require(cmdline.have("self-test"));
68  }
69 };
70 
71 } // namespace
72 } // namespace
73 
74 #endif
Rose::CommandLine::insertSelfTest
void insertSelfTest()
Convenient way to add a command-line self test.
Definition: SelfTest.h:48
Sawyer::CommandLine::ParserResult::have
size_t have(const std::string &switchKey) const
Returns the number of values for the specified key.
Definition: util/Sawyer/CommandLine.h:3375
Rose::CommandLine::SelfTest
Base class for self tests.
Definition: SelfTest.h:18
Rose::CommandLine::runSelfTestsAndExit
ROSE_DLL_API void runSelfTestsAndExit()
Runs the self tests and then exits the program.
Sawyer::CommandLine::ParserResult
The result from parsing a command line.
Definition: util/Sawyer/CommandLine.h:3333
Sawyer::SharedPointer
Reference-counting intrusive smart pointer.
Definition: SharedPointer.h:68
Rose
Main namespace for the ROSE library.
Definition: BinaryTutorial.dox:3
Sawyer::SharedObject
Base class for reference counted objects.
Definition: SharedObject.h:64
Sawyer::CommandLine::SwitchAction
Base class for switch actions.
Definition: util/Sawyer/CommandLine.h:1612
Rose::CommandLine::selfTests
ROSE_DLL_API std::vector< SelfTest::Ptr > selfTests
Collection of self tests to be run by –self-tests switch.
Rose::CommandLine::SelfTests
Run self tests from the command-line, then exit.
Definition: SelfTest.h:53