Skip to content

Instantly share code, notes, and snippets.

@tpatel
Created September 26, 2013 13:56
Show Gist options
  • Select an option

  • Save tpatel/6714607 to your computer and use it in GitHub Desktop.

Select an option

Save tpatel/6714607 to your computer and use it in GitHub Desktop.
CppTester, the simplest test suite.
/**
CppTester, the simplest test suite
*/
#include <iostream>
#include <vector>
struct Test;
std::vector<Test*> tests;
struct Test {
Test() {tests.push_back(this);}
virtual bool operator()()=0;
};
int main() {
std::cout << "Begin tests..." << std::endl;
unsigned int passed = tests.size();
for(unsigned int i=0; i<tests.size(); i++) {
bool returned = (*tests[i])(); //Execute the test
if(!returned) {
std::cout << "Test " << i << " failed" << std::endl;
passed--;
}
}
std::cout << "Tests finished: " << passed << "/" << tests.size() << " tests passed.";
if(passed == tests.size()) {
std::cout << " Good Job!";
}
std::cout << std::endl;
}
// TESTS
struct T1: Test { virtual bool operator()() {
return 1 == 1;
} } t1;
struct T2: Test { virtual bool operator()() {
return 2 * 21 == 42;
} } t2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment