Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Latest commit

 

History

History
51 lines (40 loc) · 1.39 KB

README.md

File metadata and controls

51 lines (40 loc) · 1.39 KB

Build Status

Moka

A simple C++ test framework inspired by Mocha and named after my coffee maker.

Example

This is a simple example that shows off all the main features of Moka. It has tests organized into contexts like in Mocha.js, and uses macro assertions inside them to check whatever conditions you want. A more complete example can be found in test/meta.cpp.

#include "../moka.h"

Moka::Context test("Moka Demo!", [](Moka::Context& it) {
  it.should("test for equality", []() {
    must_equal(2 + 2, 4);
  });

  it.should("test for inequality", []() {
    must_not_equal("war",       "peace");
    must_not_equal("freedom",   "slavery");
    must_not_equal("ignorance", "strength");
  });

  it.should("test for exceptions", []() {
    must_throw(std::logic_error, []() {
      throw std::logic_error("doublethink");
    });
  });
});

int main() {
  return test.run();
}

Compiling the above program (you'll need C++ 11) will result in an executable with three tests. When you run it, you should see them all pass.

[21:16:14 holt@Minerva moka]$ clang++ -std=c++11 test/demo.cpp
[21:16:33 holt@Minerva moka]$ ./a.out
Moka Demo!
  ✔ should test for equality
  ✔ should test for inequality
  ✔ should test for exceptions