[RDF] Add RegisterRef::idx and make toUnitId constexpr
[llvm-project.git] / libc / test / UnitTest / FPExceptMatcher.h
blob1563561854abdb5d798ddee00a61189253d232d4
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_UTILS_UNITTEST_FPEXCEPTMATCHER_H
10 #define LLVM_LIBC_UTILS_UNITTEST_FPEXCEPTMATCHER_H
12 #ifndef LIBC_COPT_TEST_USE_FUCHSIA
14 #include "test/UnitTest/Test.h"
16 namespace __llvm_libc {
17 namespace testing {
19 // TODO: Make the matcher match specific exceptions instead of just identifying
20 // that an exception was raised.
21 class FPExceptMatcher : public Matcher<bool> {
22 bool exceptionRaised;
24 public:
25 class FunctionCaller {
26 public:
27 virtual ~FunctionCaller(){};
28 virtual void call() = 0;
31 template <typename Func> static FunctionCaller *getFunctionCaller(Func func) {
32 struct Callable : public FunctionCaller {
33 Func f;
34 explicit Callable(Func theFunc) : f(theFunc) {}
35 void call() override { f(); }
38 return new Callable(func);
41 // Takes ownership of func.
42 explicit FPExceptMatcher(FunctionCaller *func);
44 bool match(bool unused) { return exceptionRaised; }
46 void explainError() override {
47 tlog << "A floating point exception should have been raised but it "
48 << "wasn't\n";
52 } // namespace testing
53 } // namespace __llvm_libc
55 #define ASSERT_RAISES_FP_EXCEPT(func) \
56 ASSERT_THAT( \
57 true, \
58 __llvm_libc::testing::FPExceptMatcher( \
59 __llvm_libc::testing::FPExceptMatcher::getFunctionCaller(func)))
60 #else
61 #define ASSERT_RAISES_FP_EXCEPT(func) ASSERT_DEATH(func, WITH_SIGNAL(SIGFPE))
62 #endif // LIBC_COPT_TEST_USE_FUCHSIA
64 #endif // LLVM_LIBC_UTILS_UNITTEST_FPEXCEPTMATCHER_H