[clang][bytecode] Support vector-to-vector bitcasts (#118230)
[llvm-project.git] / libc / test / UnitTest / FPExceptMatcher.h
blob978501df7e3ed3da6087227e44f57e8cd8f2163d
1 //===-- FPExceptMatcher.h ---------------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_TEST_UNITTEST_FPEXCEPTMATCHER_H
10 #define LLVM_LIBC_TEST_UNITTEST_FPEXCEPTMATCHER_H
12 #include "src/__support/macros/config.h"
13 #include "test/UnitTest/Test.h"
14 #include "test/UnitTest/TestLogger.h"
16 #if LIBC_TEST_HAS_MATCHERS()
18 namespace LIBC_NAMESPACE_DECL {
19 namespace testing {
21 // TODO: Make the matcher match specific exceptions instead of just identifying
22 // that an exception was raised.
23 class FPExceptMatcher : public Matcher<bool> {
24 bool exceptionRaised;
26 public:
27 class FunctionCaller {
28 public:
29 virtual ~FunctionCaller() {}
30 virtual void call() = 0;
33 template <typename Func> static FunctionCaller *getFunctionCaller(Func func) {
34 struct Callable : public FunctionCaller {
35 Func f;
36 explicit Callable(Func theFunc) : f(theFunc) {}
37 void call() override { f(); }
40 return new Callable(func);
43 // Takes ownership of func.
44 explicit FPExceptMatcher(FunctionCaller *func);
46 bool match(bool unused) { return exceptionRaised; }
48 void explainError() override {
49 tlog << "A floating point exception should have been raised but it "
50 << "wasn't\n";
54 } // namespace testing
55 } // namespace LIBC_NAMESPACE_DECL
57 #define ASSERT_RAISES_FP_EXCEPT(func) \
58 ASSERT_THAT( \
59 true, \
60 LIBC_NAMESPACE::testing::FPExceptMatcher( \
61 LIBC_NAMESPACE::testing::FPExceptMatcher::getFunctionCaller(func)))
63 #else // !LIBC_TEST_HAS_MATCHERS()
65 #define ASSERT_RAISES_FP_EXCEPT(func) ASSERT_DEATH(func, WITH_SIGNAL(SIGFPE))
67 #endif // LIBC_TEST_HAS_MATCHERS()
69 #endif // LLVM_LIBC_TEST_UNITTEST_FPEXCEPTMATCHER_H