BuildBot fix, compiler complains about array decay to pointer
[llvm-core.git] / unittests / Support / ErrnoTest.cpp
blob701ac96082514b0a22b8058db9199c843277d17a
1 //===- ErrnoTest.cpp - Error handling unit tests --------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/Errno.h"
11 #include "gtest/gtest.h"
13 using namespace llvm::sys;
15 TEST(ErrnoTest, RetryAfterSignal) {
16 EXPECT_EQ(1, RetryAfterSignal(-1, [] { return 1; }));
18 EXPECT_EQ(-1, RetryAfterSignal(-1, [] {
19 errno = EAGAIN;
20 return -1;
21 }));
22 EXPECT_EQ(EAGAIN, errno);
24 unsigned calls = 0;
25 EXPECT_EQ(1, RetryAfterSignal(-1, [&calls] {
26 errno = EINTR;
27 ++calls;
28 return calls == 1 ? -1 : 1;
29 }));
30 EXPECT_EQ(2u, calls);
32 EXPECT_EQ(1, RetryAfterSignal(-1, [](int x) { return x; }, 1));
34 std::unique_ptr<int> P(RetryAfterSignal(nullptr, [] { return new int(47); }));
35 EXPECT_EQ(47, *P);
37 errno = EINTR;
38 EXPECT_EQ(-1, RetryAfterSignal(-1, [] { return -1; }));