Skip to content

Latest commit

 

History

History
101 lines (63 loc) · 2.2 KB

File metadata and controls

101 lines (63 loc) · 2.2 KB

TECT: Explicitly Controlled Testing

You can test C code without hiding control flow in macros.

This repository is a goofy illustration of that, written in GNU C23.

Example

Macros tect_once and tect_report hide checking and reporting logic.

// example_one.c
SCRIPT_CONTENT

This outputs:

SCRIPT_OUTPUT

Note that we run check_example twice. Returning and retrying gives you freedom to interpret and handle the returned value however the language allows.

See example_two.c for a more involved example.

This repeated-run style is inspired by (and not an implementation of) Andrei Alexandrescu's "Unit Test Should Nest", which is inspired by Catch2.

Non-Example

Common C testing tools use such powerful macros that their code does not resemble C.

They instead define new, domain-specific languages, because their macros hide both declarations and control flow.

For example, a pastiche of the C testing tools from Awesome C could look like:

DECLARE_TEST(context, "some associated text") {
    CHECK(6 * 9 == 42);
    CHECK(3 == 4);
}

By hiding core language features, such designs make me I feel uncomfortably incapable of composing these tools with core language features.

Our tect_* macros also hide state and output.

And they are arguably disgusting abuses of language extensions.

But they do give users control of control flow.

Usage

Install tools in Ubuntu 23.04:

sudo apt install clang-format gcc-13 make

Build and run our examples:

make

Other make commands:

make check # Run some basic tests on the examples' outputs.

make fmt # Auto-format our C source files.

make README.md # Generate `README.md` from the template file.

For development, please run make -s README.md fmt check before each commit.

Documentation

We generate this section from comments in tect.h.