Skip to main content

Test Framework

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

Macros

EXPECT(expr)

Asserts that an expression is true.

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

SKIP(reason)

Skips a test with a message.

SKIP("not implemented on Windows");

TEST(name)

Defines a test.

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

TEST_CASE(name)

Registers a test case.

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

Initialization

dcr test --init

Creates:

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

Structure

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).