Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.71 KB

README.md

File metadata and controls

51 lines (38 loc) · 1.71 KB

Bugged

Your code is bugged? Your functions try hard to fight their interfaces and documentation? Your exceptions multiply at the rate of rabbits and you are lost in all of it?
Good news! You don't need a >20k-loc framework to fight back!

Just a single header for modern C++ unit testing.
Released into the public domain to spare you from any additional license headaches.
Does not perform any macro and template magic that itself provides a nice habitat for those little beasts. Does only what it has to. And this well. You don't need any magic to exterminate bugs. (Requires C++11 though since it got way better flamethrowers than the old and boring stuff).

Use these 3 weapons instead:

TEST(<test function name>) { <tests> } // function will be automatically called
EXPECT(<expression>, <expected>); // checks if expressions evaluates to expected
ERROR(<expression>, <expected error>); // checks if expression throws the expected error

Example:

#include "bugged.hpp"
#include <stdexcept>

int returns0() { return 0; }
void throws() { throw std::logic_error("Go Away!"); }

// declare a test method
TEST(FirstTest) {
	EXPECT(returns0(), 0); // will succeed
	EXPECT(returns0(), 1); // will fail

	ERROR(returns0(), int); // will fail
	ERROR(throws(), std::logic_error); // will succeed
	ERROR(throws(), std::runtime_error); // will fail

	throws(); // will end the test and output the exception.
}

// empty tests or ones only with static_asserts or other checks are ok as well
TEST(EmptyTest) {}

The output of the test above could look like this: Here should go a beautiful picture of bugged in action. So sad!

Contributions of all kind are welcome!