1 //===- unittests/ErrorOrTest.cpp - ErrorOr.h tests ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/ErrorOr.h"
11 #include "gtest/gtest.h"
18 ErrorOr<int> t1() {return 1;}
19 ErrorOr<int> t2() { return errc::invalid_argument; }
21 TEST(ErrorOr, SimpleValue) {
22 ErrorOr<int> a = t1();
28 EXPECT_EQ(errc::invalid_argument, a.getError());
29 #ifdef EXPECT_DEBUG_DEATH
30 EXPECT_DEBUG_DEATH(*a, "Cannot get value when an error exists");
34 #if LLVM_HAS_CXX11_STDLIB
35 ErrorOr<std::unique_ptr<int> > t3() {
36 return std::unique_ptr<int>(new int(3));
40 TEST(ErrorOr, Types) {
46 #if LLVM_HAS_CXX11_STDLIB
55 TEST(ErrorOr, Covariant) {
56 ErrorOr<B*> b(ErrorOr<D*>(0));
59 #if LLVM_HAS_CXX11_STDLIB
60 ErrorOr<std::unique_ptr<B> > b1(ErrorOr<std::unique_ptr<D> >(0));
61 b1 = ErrorOr<std::unique_ptr<D> >(0);
64 } // end anon namespace