Documentation

Test framework (EXPECT, TEST, ...)

DCR has a built-in minimal test framework for C.

Macros

EXPECT(expr)

Asserts that an expression is true.

Editor
EXPECT(1 + 1 == 2);
EXPECT(ptr != NULL);

SKIP(reason)

Skips a test with a message.

Editor
SKIP("not implemented on Windows");

TEST(name)

Defines a test.

Editor
TEST(addition) {
    EXPECT(1 + 1 == 2);
    EXPECT(2 + 2 == 4);
}

TEST_CASE(name)

Registers a test case.

Editor
TEST_CASE(math) {
    EXPECT(1 + 1 == 2);
}

Initialization

Terminal
dcr test --init

Creates:

  • tests/dcr_test.h — framework header (do not edit)
  • tests/test.c — template with example test

Structure

Editor
tests/
├── dcr_test.h      # framework (do not edit)
├── test.c          # main tests
└── ...             # additional .c test files

Only .c files are compiled (.cpp is not supported).