mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:10:12 +01:00
Create Error type (#1137)
Co-authored-by: Geoff Romer <gromer@google.com> Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Geoff Romer
Chandler Carruth
parent
31fa2608d4
commit
c546c81d07
@@ -0,0 +1,47 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "common/error.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Carbon::Testing {
|
||||
namespace {
|
||||
|
||||
TEST(ErrorTest, Error) {
|
||||
Error err("test");
|
||||
EXPECT_EQ(err.message(), "test");
|
||||
}
|
||||
|
||||
TEST(ErrorTest, ErrorEmptyString) {
|
||||
ASSERT_DEATH({ Error err(""); }, "CHECK failure at");
|
||||
}
|
||||
|
||||
auto IndirectError() -> Error { return Error("test"); }
|
||||
|
||||
TEST(ErrorTest, IndirectError) { EXPECT_EQ(IndirectError().message(), "test"); }
|
||||
|
||||
TEST(ErrorTest, ErrorOr) {
|
||||
ErrorOr<int> err(Error("test"));
|
||||
EXPECT_FALSE(err.ok());
|
||||
EXPECT_EQ(err.error().message(), "test");
|
||||
}
|
||||
|
||||
TEST(ErrorTest, ErrorOrValue) { EXPECT_TRUE(ErrorOr<int>(0).ok()); }
|
||||
|
||||
auto IndirectErrorOrTest() -> ErrorOr<int> { return Error("test"); }
|
||||
|
||||
TEST(ErrorTest, IndirectErrorOr) { EXPECT_FALSE(IndirectErrorOrTest().ok()); }
|
||||
|
||||
struct Val {
|
||||
int val;
|
||||
};
|
||||
|
||||
TEST(ErrorTest, ErrorOrArrowOp) {
|
||||
ErrorOr<Val> err({1});
|
||||
EXPECT_EQ(err->val, 1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace Carbon::Testing
|
||||
Reference in New Issue
Block a user