aboutsummaryrefslogtreecommitdiff
path: root/unittests/Support
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2013-01-23 00:18:31 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2013-01-23 00:18:31 +0000
commitbdd4e1311830bea92c8b8c09f0644cba15421241 (patch)
treefa243ee56abe28a8ff8802924fdd0bf83b05dff9 /unittests/Support
parent0ec35ac4fcd5c83e2ec35d04fc20db9eb387d289 (diff)
[Support][ErrorOr] Add optimized specialization of ErrorOr<void>.
ErrorOr<void> represents an operation that returns nothing, but can still fail. It should be used in cases where you need the aditional user data that ErrorOr provides over error_code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173209 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Support')
-rw-r--r--unittests/Support/ErrorOrTest.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/unittests/Support/ErrorOrTest.cpp b/unittests/Support/ErrorOrTest.cpp
index b30895cdbd..a8608860b8 100644
--- a/unittests/Support/ErrorOrTest.cpp
+++ b/unittests/Support/ErrorOrTest.cpp
@@ -45,6 +45,9 @@ TEST(ErrorOr, Types) {
*a = 42;
EXPECT_EQ(42, x);
+ EXPECT_FALSE(ErrorOr<void>(make_error_code(errc::broken_pipe)));
+ EXPECT_TRUE(ErrorOr<void>(make_error_code(errc::success)));
+
#if LLVM_HAS_CXX11_STDLIB
// Move only types.
EXPECT_EQ(3, **t3());
@@ -71,10 +74,18 @@ ErrorOr<int> t4() {
return InvalidArgError("adena");
}
+ErrorOr<void> t5() {
+ return InvalidArgError("pie");
+}
+
namespace {
TEST(ErrorOr, UserErrorData) {
ErrorOr<int> a = t4();
EXPECT_EQ(errc::invalid_argument, a);
EXPECT_EQ("adena", t4().getError<InvalidArgError>().ArgName);
+
+ ErrorOr<void> b = t5();
+ EXPECT_EQ(errc::invalid_argument, b);
+ EXPECT_EQ("pie", b.getError<InvalidArgError>().ArgName);
}
} // end anon namespace