Loading...
Searching...
No Matches
expect.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Kaspar Schleiser <kaspar@schleiser.de>
3 * Copyright (C) 2015 INRIA
4 * Copyright (C) 2016 Freie Universität Berlin
5 *
6 * This file is subject to the terms and conditions of the GNU Lesser
7 * General Public License v2.1. See the file LICENSE in the top level
8 * directory for more details.
9 */
10
25#ifndef TEST_UTILS_EXPECT_H
26#define TEST_UTILS_EXPECT_H
27
28#include <stdio.h>
29#include "compiler_hints.h"
30#include "panic.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
46NORETURN static inline void _expect_failure(const char *file, unsigned line)
47{
48 printf("%s:%u => failed condition\n", file, line);
49 core_panic(PANIC_EXPECT_FAIL, "CONDITION FAILED.");
50}
51
80#define expect(cond) (likely(cond) ? (void)0 : _expect_failure(__FILE__, __LINE__))
81
82#ifdef __cplusplus
83}
84#endif
85
86#endif /* TEST_UTILS_EXPECT_H */
Common macros and compiler attributes/pragmas configuration.
#define NORETURN
The NORETURN keyword tells the compiler to assume that the function cannot return.
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
Definition stdio.h:60
static NORETURN void _expect_failure(const char *file, unsigned line)
Function to handle failed expectation.
Definition expect.h:46
Crash handling header.
NORETURN void core_panic(core_panic_t crash_code, const char *message)
Handle an unrecoverable error by halting or rebooting the system.
stdio wrapper to extend the C libs stdio