---
name: "zt_check"
section: "3"
platform: "linux"
package: "libzt-doc"
version: "0.3.1-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/zt_check"
---

# zt\_check(3)

verify a test claim

## NAME

**zt\_check**, **zt\_assert** – verify a test claim

## SYNOPSIS

**#include \<zt.h\>**

*void*\

**zt\_check**(*zt\_t t*, *zt\_claim claim*);

*void*\

**zt\_assert**(*zt\_t t*, *zt\_claim claim*);

## DESCRIPTION

Both **zt\_check**() and **zt\_assert**() verify a claim, encompassing a function with arguments, and is meant to be used inside test functions.

The first argument is a pointer to opaque type encapsulating test outcome. The second argument is usually constructed with a helper macro, such as **ZT\_CMP\_TRUE**() or **ZT\_CMP\_FALSE**().

If the claim holds then happens and execution continues normally. If the claim does not hold then the test is marked as failed and a diagnostic message is printed to *stderr*.

The only difference between **zt\_check**() and **zt\_assert**() is that the former allows the test to continue executing while the latter performs a non-local exit from the test function. Note that only the currently executing test function is affected. Other tests cases and test suites will still execute normally.

**zt\_check**() should be used when it is safe to execute remainder of the test even if the claim is not true. This approach allows each failure to be accompanied by as much diagnostic output as possible, without causing the test program to crash.

**zt\_assert**() should be used when it is not safe or meaningless to execute remainder of the test on failure.

## IMPLEMENTATION NOTES

Non-local exit from **zt\_assert**() is implemented using **siglongjump**(). One should not depend on neither C++ destructors nor the GCC cleanup function extension for correct resource management.

## RETURN VALUES

Neither function return anything. Failures are remembered inside the opaque **zt\_test** structure passed by pointer (aka **zt\_t**) as the first argument.

## EXAMPLES

A minimal test program that looks up the UNIX user *root* and measures several properties of the returned record.

```
#include <sys/types.h>
#include <pwd.h>
#include <zt.h>
static void test_root_user(zt_t t) {
    struct passwd *p = getpwnam("root");
    zt_assert(t, ZT_NOT_NULL(p));
    zt_check(t, ZT_CMP_CSTR(p->pw_name, ==, "root"));
    zt_check(t, ZT_CMP_INT(p->pw_uid, ==, 0));
    zt_check(t, ZT_CMP_INT(p->pw_gid, ==, 0));
}
static void test_suite(zt_visitor v) {
    ZT_VISIT_TEST_CASE(v, test_root_user);
}
int main(int argc, char** argv, char** envp) {
    return zt_main(argc, argv, envp, test_suite);
}
```

## SEE ALSO

[ZT\_CMP\_BOOL(3)](/ZT_CMP_BOOL/3.md), ZT\_CMP\_CSTR(3), [ZT\_CMP\_INT(3)](/ZT_CMP_INT/3.md), [ZT\_CMP\_PTR(3)](/ZT_CMP_PTR/3.md), [ZT\_CMP\_UINT(3)](/ZT_CMP_UINT/3.md), [ZT\_FALSE(3)](/ZT_FALSE/3.md), [ZT\_NOT\_NULL(3)](/ZT_NOT_NULL/3.md), [ZT\_NULL(3)](/ZT_NULL/3.md), [ZT\_TRUE(3)](/ZT_TRUE/3.md)

## HISTORY

The **zt\_check**() and the **zt\_assert**() functions first appeared in libzt 0.1

## AUTHORS

Zygmunt Krynicki ⟨*me@zygoon.pl*⟩
