1 //===- ErrnoTest.cpp - Error handling unit tests --------------------------===//
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 #include "llvm/Support/Errno.h"
10 #include "gtest/gtest.h"
12 using namespace llvm::sys
;
14 TEST(ErrnoTest
, RetryAfterSignal
) {
15 EXPECT_EQ(1, RetryAfterSignal(-1, [] { return 1; }));
17 EXPECT_EQ(-1, RetryAfterSignal(-1, [] {
21 EXPECT_EQ(EAGAIN
, errno
);
24 EXPECT_EQ(1, RetryAfterSignal(-1, [&calls
] {
27 return calls
== 1 ? -1 : 1;
31 EXPECT_EQ(1, RetryAfterSignal(-1, [](int x
) { return x
; }, 1));
33 std::unique_ptr
<int> P(RetryAfterSignal(nullptr, [] { return new int(47); }));
37 EXPECT_EQ(-1, RetryAfterSignal(-1, [] { return -1; }));