Home

Awesome

<div align="center"> <h1>Tau τ</h1>

Standard Standard License Twitter Download Docs

</div>

A Micro Unit Testing Framework for >C11/C++11 projects, with the promise of always being tiny - about 1k lines of code. This framework is a much simpler, much lighter and much faster alternative to heavier frameworks like Google Test, & Catch2, making it suitable for on-to-go testing (embedded developers will especially love us!).

I initially wrote Tau to be a unit testing framework for C; however, initial results showed great promise of compiling with (and testing) C++ code. While Tau doesn't currently support mocking, or a way to test for exceptions in C++, its limitations are in fact its biggest strength - you get negligible overhead & fast compilation speeds for the sacrifice of a few constructs.

Features

Installation

None! Tau is header-only, so simply include it in your project.

#include <tau/tau.h>

To build Tau with CMake, read through the CMake Quickstart Guide.

Alternatively, use -I tau to add the repository directory to the compiler search paths.

<!-- ## Basic Concepts Tau provides several variants of Assertion Macros for us - `CHECK`s which are *non-fatal* asserts, and `REQUIRE`s which are *fatal* asserts. The result of an assertion is either *success*, *non-fatal failure* or a *fatal failure*. Unless the latter takes place, the program continues normally. In Tau, you would normally define a ***Test Suite*** which contains multiple tests. These test suites should ideally reflect the structure of your tested code. -->

Prerequistes

To begin, you must include the following in any (but only one) C/C++ file. This initializes Tau to set up all your tests:

TAU_MAIN() // IMPORTANT: No semicolon at the end

This defines a main function, so if you write a main() function and declare TAU_MAIN(), your compiler will throw a redeclaration of main error.

If you must write a main() function, use the following instead:

TAU_NO_MAIN()

This won't define a main function, but sets up any variables/methods that Tau needs to run properly.

Getting Started

Defining a Test Suite

To define a test suite, simply do the following:

TEST(TestSuiteName, TestName) {
    CHECK(1); // does not fail
    ... rest of the test body ...
}

The TEST macro takes two parameters - the first is the name of the Test Suite, and the second is the name of the test. This allows tests to be grouped for convenience.

Testing Macros

Tau provides two variants of Assertion Macros - CHECKs and ASSERTs. These resemble function calls. When these assertions fail, Tau prints the source code location (file + line number) along with a failure message.

ASSERTs generate fatal failures - the test suite will cease its execution and move on to the next test suite to run.

CHECKs generate non-fatal failures - the remainder of the test suite will still execute, allowing for further checks to run.

Read the Primer for more details, including the other testing macros Tau provides you with.

Example Usage

Below is a slightly contrived example showing a number of possible supported operations:

#include <tau/tau.h>
TAU_MAIN() // sets up Tau (+ main function)

TEST(foo, bar1) {
    int a = 42;
    int b = 13;
    CHECK_GE(a, b); // pass :)
    CHECK_LE(b, 8); // fail - Test suite not aborted
}

TEST(foo, bar2) {
    char* a = "foo";
    char* b = "foobar";
    REQUIRE_STREQ(a, a); // pass :)
    REQUIRE_STREQ(a, b); // fail - Test suite aborted
}

Supported Platforms

Tau supports codebases and compilers that are compliant with the C11/C++11 standard or newer. Tau's source code is officially supported on the following platforms. If you notice any problems on your platform, please file an issue on the Tau Github Issue Tracker. PRs with fixes are welcome!

Operating SystemsCompilers
Linuxgcc 5.0+
macOSclang 5.0+
WindowsMSVC 2017+

Contributing

We appreciate all contributions, feedback and issues. If you plan to contribute new features, utility functions, or extensions to the core, please go through our Contribution Guidelines.

To contribute, start working through the Tau codebase, read the Documentation, navigate to the Issues tab and start looking through interesting issues.

Asking for help

If you have any questions, please:

  1. Read the docs.
  2. Look it up in our Github Discussions (or add a new question).
  3. Search through the issues.

Who uses Tau?

In addition to several of my personal projects, Tau is also used in the following notable projects:

Supporting This Project

If you are able to and would like to sponsor this project, you may do so using either of the links below. Thank you very much in advance :)

<p align="center"> <!-- <a href="https://www.buymeacoffee.com/jasmcaus" target = "_blank"><img alt="Buy Jason a Coffee" width="48px" src="https://raw.githubusercontent.com/adi1090x/files/master/other/1.png"></a> --> <a href="https://www.ko-fi.com/jasmcaus" target="_blank"><img alt="Buy Jason a Coffee" width="48px" src="https://raw.githubusercontent.com/adi1090x/files/master/other/2.png"></a> <a href="https://www.paypal.me/jasmcaus" target="_blank"><img alt="Buy Jason a Coffee" width="48px" src="https://raw.githubusercontent.com/adi1090x/files/master/other/3.png"></a> <a href="https://www.patreon.com/jasmcaus" target="_blank"><img alt="Buy Jason a Coffee" width=48px src="https://raw.githubusercontent.com/adi1090x/files/master/other/4.png"></a> </p>

License

This project was written by Jason Dsouza and licensed under the MIT License.