scsl 1.0.1
Shimmering Clarity Standard Library
Loading...
Searching...
No Matches
SimpleSuite.h
Go to the documentation of this file.
1
22
23#ifndef SCTEST_SIMPLESUITE_H
24#define SCTEST_SIMPLESUITE_H
25
26
27#include <functional>
28#include <string>
29#include <vector>
30
31#include <sctest/Report.h>
32
33namespace sctest {
34
35
39struct UnitTest {
41 std::string name;
42
44 std::function<bool()> test;
45
47 bool expect;
48};
49
55public:
57
59 void Silence();
60
66 void Setup(std::function<bool(void)> setupFn) { fnSetup = setupFn; }
67
72 void Teardown(std::function<bool(void)> teardownFn) { fnTeardown = teardownFn; }
73
80 void AddTest(std::string label, std::function<bool(void)> test);
81
88 void AddFailingTest(std::string label, std::function<bool(void)> test);
89
93 bool Run();
94
96
101 void Reset();
102
104 bool HasRun() const;
105
110
111private:
112 bool quiet;
113 std::function<bool(void)> fnSetup, fnTeardown;
114 std::vector<UnitTest> tests;
115
116 // Report functions.
117 Report report;
118 bool hasRun; // Have the tests been run yet?
119 bool hasPassed;
120};
121
122
123std::ostream& operator<<(std::ostream& os, SimpleSuite &suite);
124
125
126} // namespace sctest
127#endif
Unit test reporting class.
A Report holds test run results.
Definition Report.h:34
SimpleSuite is a test-running harness for simple tests.
Definition SimpleSuite.h:54
void Reset()
Reporting methods.
void Setup(std::function< bool(void)> setupFn)
Define a suite setup function.
Definition SimpleSuite.h:66
Report GetReport()
Retrieve the test run results.
void AddTest(std::string label, std::function< bool(void)> test)
Register a new simple test.
bool HasRun() const
Returns true if Run has been called.
bool Run()
Run all the registered tests.
void AddFailingTest(std::string label, std::function< bool(void)> test)
Register a test that is expected to return false.
void Teardown(std::function< bool(void)> teardownFn)
Define a teardown function.
Definition SimpleSuite.h:72
void Silence()
Silence suppresses output.
Shimmering Clarity testing library.
Definition sctest.h:34
std::ostream & operator<<(std::ostream &os, const Report &report)
UnitTest describes a single unit test.
Definition SimpleSuite.h:39
std::function< bool()> test
This is the test function to be run.
Definition SimpleSuite.h:44
bool expect
This is the value the test returns if it passes.
Definition SimpleSuite.h:47
std::string name
What name should be shown when running tests?
Definition SimpleSuite.h:41