1 //===-- Simple checkers for integrations tests ------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_UTILS_INTEGRATION_TEST_TEST_H
10 #define LLVM_LIBC_UTILS_INTEGRATION_TEST_TEST_H
12 #include "src/__support/OSUtil/io.h"
13 #include "src/__support/OSUtil/quick_exit.h"
15 #define __AS_STRING(val) #val
16 #define __CHECK_TRUE(file, line, val, should_exit) \
18 LIBC_NAMESPACE::write_to_stderr(file ":" __AS_STRING( \
19 line) ": Expected '" #val "' to be true, but is false\n"); \
21 LIBC_NAMESPACE::quick_exit(127); \
24 #define __CHECK_FALSE(file, line, val, should_exit) \
26 LIBC_NAMESPACE::write_to_stderr(file ":" __AS_STRING( \
27 line) ": Expected '" #val "' to be false, but is true\n"); \
29 LIBC_NAMESPACE::quick_exit(127); \
32 #define __CHECK_EQ(file, line, val1, val2, should_exit) \
33 if ((val1) != (val2)) { \
34 LIBC_NAMESPACE::write_to_stderr(file ":" __AS_STRING( \
35 line) ": Expected '" #val1 "' to be equal to '" #val2 "'\n"); \
37 LIBC_NAMESPACE::quick_exit(127); \
40 #define __CHECK_NE(file, line, val1, val2, should_exit) \
41 if ((val1) == (val2)) { \
42 LIBC_NAMESPACE::write_to_stderr(file ":" __AS_STRING( \
43 line) ": Expected '" #val1 "' to not be equal to '" #val2 "'\n"); \
45 LIBC_NAMESPACE::quick_exit(127); \
48 #define EXPECT_TRUE(val) __CHECK_TRUE(__FILE__, __LINE__, val, false)
49 #define ASSERT_TRUE(val) __CHECK_TRUE(__FILE__, __LINE__, val, true)
50 #define EXPECT_FALSE(val) __CHECK_FALSE(__FILE__, __LINE__, val, false)
51 #define ASSERT_FALSE(val) __CHECK_FALSE(__FILE__, __LINE__, val, true)
52 #define EXPECT_EQ(val1, val2) \
53 __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), false)
54 #define ASSERT_EQ(val1, val2) \
55 __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)
56 #define EXPECT_NE(val1, val2) \
57 __CHECK_NE(__FILE__, __LINE__, (val1), (val2), false)
58 #define ASSERT_NE(val1, val2) \
59 __CHECK_NE(__FILE__, __LINE__, (val1), (val2), true)
61 // Integration tests are compiled with -ffreestanding which stops treating
62 // the main function as a non-overloadable special function. Hence, we use a
63 // convenience macro which declares it 'extern "C"'.
65 // When we are able to reuse the unit test infrastructure for integration
66 // tests, then we should not need to explicitly declare/define the main
67 // function in individual integration tests. We will not need this macro
69 #define TEST_MAIN extern "C" int main
71 #endif // LLVM_LIBC_UTILS_INTEGRATION_TEST_TEST_H