Skip to content

Commit 04af055

Browse files
committed
Add unit tests.
1 parent a64a3e8 commit 04af055

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

libc/test/include/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,21 @@ add_libc_test(
484484
libc.include.llvm-libc-macros.math_function_macros
485485
)
486486

487+
add_libc_test(
488+
math_constants_c_test
489+
C_TEST
490+
UNIT_TEST_ONLY
491+
SUITE
492+
libc_include_tests
493+
SRCS
494+
math_constants_test.c
495+
COMPILE_OPTIONS
496+
-Wall
497+
-Werror
498+
DEPENDS
499+
libc.include.llvm-libc-macros.math_macros
500+
)
501+
487502
# Test `#include <...>` of each header in each available language mode.
488503
# This is gated on -DLLVM_LIBC_BUILD_HEADER_TESTS=ON until all the bugs
489504
# in headers are fixed so the tests all compile.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Unittests for math constants --------------------------------------===//
2+
//
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
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#include "include/llvm-libc-macros/math-macros.h"
9+
10+
#define IS_DOUBLE(X) _Generic((X), double: 1, default: 0)
11+
12+
#define IS_FLOAT(X) _Generic((X), float: 1, default: 0)
13+
14+
// check if macro is defined
15+
#ifndef M_PI
16+
#error "M_PI macro is not defined"
17+
#else
18+
int main(void) {
19+
_Static_assert(IS_DOUBLE(M_PI), "M_PI is not of double type.");
20+
_Static_assert(IS_FLOAT(M_PIf), "M_PIf is not of float type.");
21+
return 0;
22+
}
23+
#endif

0 commit comments

Comments
 (0)