mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-20 02:41:48 +00:00
Instead of using builder.Diagnostics().contains_errors() Produces cleaner code and reduces scope of error handling. Bug: tint:1661 Change-Id: I35af5ad1c6553f2cf74d1ce92dc14984f93b9db4 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/102161 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
68 lines
1.5 KiB
C++
68 lines
1.5 KiB
C++
// Copyright 2022 The Tint Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "src/tint/utils/result.h"
|
|
|
|
#include <string>
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
namespace tint::utils {
|
|
namespace {
|
|
|
|
TEST(ResultTest, SuccessInt) {
|
|
auto r = Result<int>(123);
|
|
EXPECT_TRUE(r);
|
|
EXPECT_FALSE(!r);
|
|
EXPECT_EQ(r.Get(), 123);
|
|
}
|
|
|
|
TEST(ResultTest, SuccessStruct) {
|
|
struct S {
|
|
int value;
|
|
};
|
|
auto r = Result<S>({123});
|
|
EXPECT_TRUE(r);
|
|
EXPECT_FALSE(!r);
|
|
EXPECT_EQ(r->value, 123);
|
|
}
|
|
|
|
TEST(ResultTest, Failure) {
|
|
auto r = Result<int>(Failure);
|
|
EXPECT_FALSE(r);
|
|
EXPECT_TRUE(!r);
|
|
}
|
|
|
|
TEST(ResultTest, CustomFailure) {
|
|
auto r = Result<int, std::string>("oh noes!");
|
|
EXPECT_FALSE(r);
|
|
EXPECT_TRUE(!r);
|
|
EXPECT_EQ(r.Failure(), "oh noes!");
|
|
}
|
|
|
|
TEST(ResultTest, ValueCast) {
|
|
struct X {};
|
|
struct Y : X {};
|
|
|
|
Y* y = nullptr;
|
|
auto r_y = Result<Y*>{y};
|
|
auto r_x = Result<X*>{r_y};
|
|
|
|
(void)r_x;
|
|
(void)r_y;
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace tint::utils
|