1 //===-- ErrnoSetterMatcher.h ------------------------------------*- 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_TEST_ERRNOSETTERMATCHER_H
10 #define LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H
12 #include "utils/UnitTest/Test.h"
16 namespace __llvm_libc
{
21 extern "C" char *strerror(int);
23 template <typename T
> class ErrnoSetterMatcher
: public Matcher
<T
> {
30 ErrnoSetterMatcher(T ExpectedReturn
, int ExpectedErrno
)
31 : ExpectedReturn(ExpectedReturn
), ExpectedErrno(ExpectedErrno
) {}
33 void explainError(testutils::StreamWrapper
&OS
) override
{
34 if (ActualReturn
!= ExpectedReturn
)
35 OS
<< "Expected return to be " << ExpectedReturn
<< " but got "
36 << ActualReturn
<< ".\nExpecte errno to be " << strerror(ExpectedErrno
)
37 << " but got " << strerror(ActualErrno
) << ".\n";
39 OS
<< "Correct value " << ExpectedReturn
40 << " was returned\nBut errno was unexpectely set to "
41 << strerror(ActualErrno
) << ".\n";
48 return Got
== ExpectedReturn
&& ActualErrno
== ExpectedErrno
;
52 } // namespace internal
54 namespace ErrnoSetterMatcher
{
56 template <typename RetT
= int>
57 static internal::ErrnoSetterMatcher
<RetT
> Succeeds(RetT ExpectedReturn
= 0,
58 int ExpectedErrno
= 0) {
59 return {ExpectedReturn
, ExpectedErrno
};
62 template <typename RetT
= int>
63 static internal::ErrnoSetterMatcher
<RetT
> Fails(int ExpectedErrno
,
64 RetT ExpectedReturn
= -1) {
65 return {ExpectedReturn
, ExpectedErrno
};
68 } // namespace ErrnoSetterMatcher
70 } // namespace testing
71 } // namespace __llvm_libc
73 #endif // LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H