Add ability to use `{EXPECT|ASSERT}_THAT` with Diagnostics.
This CL adds the ability to use the `EXPECT_THAT` and `ASSERT_THAT` macros with a `Diagnostics::List` object. The diagnostic string will be emitted as part of the error message. The `Resolver` is updated to provide access to the `Diagnostics` and the `AppendVector` tests are updated to use the resolvers diagnostics instead of the `error()` method. Change-Id: I94682311fe6f135b7fceae9ec7a5108379fd32be Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125060 Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
e8e3f9ada5
commit
86216f5180
|
@ -43,4 +43,9 @@ std::string List::str() const {
|
||||||
return Formatter{style}.format(*this);
|
return Formatter{style}.format(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& out, const List& list) {
|
||||||
|
out << list.str();
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace tint::diag
|
} // namespace tint::diag
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#define SRC_TINT_DIAGNOSTIC_DIAGNOSTIC_H_
|
#define SRC_TINT_DIAGNOSTIC_DIAGNOSTIC_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -231,6 +232,10 @@ class List {
|
||||||
size_t error_count() const { return error_count_; }
|
size_t error_count() const { return error_count_; }
|
||||||
/// @returns the number of entries in the list.
|
/// @returns the number of entries in the list.
|
||||||
size_t count() const { return entries_.size(); }
|
size_t count() const { return entries_.size(); }
|
||||||
|
/// @returns true if the diagnostics list is empty
|
||||||
|
bool empty() const { return entries_.empty(); }
|
||||||
|
/// @returns the number of entrise in the diagnostics list
|
||||||
|
size_t size() const { return entries_.size(); }
|
||||||
/// @returns the first diagnostic in the list.
|
/// @returns the first diagnostic in the list.
|
||||||
iterator begin() const { return entries_.begin(); }
|
iterator begin() const { return entries_.begin(); }
|
||||||
/// @returns the last diagnostic in the list.
|
/// @returns the last diagnostic in the list.
|
||||||
|
@ -244,6 +249,12 @@ class List {
|
||||||
size_t error_count_ = 0;
|
size_t error_count_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Write the diagnostic list to the given stream
|
||||||
|
/// @param out the output stream
|
||||||
|
/// @param list the list to emit
|
||||||
|
/// @returns the output stream
|
||||||
|
std::ostream& operator<<(std::ostream& out, const List& list);
|
||||||
|
|
||||||
} // namespace tint::diag
|
} // namespace tint::diag
|
||||||
|
|
||||||
#endif // SRC_TINT_DIAGNOSTIC_DIAGNOSTIC_H_
|
#endif // SRC_TINT_DIAGNOSTIC_DIAGNOSTIC_H_
|
||||||
|
|
|
@ -88,6 +88,9 @@ class Resolver {
|
||||||
/// @returns error messages from the resolver
|
/// @returns error messages from the resolver
|
||||||
std::string error() const { return diagnostics_.str(); }
|
std::string error() const { return diagnostics_.str(); }
|
||||||
|
|
||||||
|
/// @returns the list of diagnostics raised by the generator.
|
||||||
|
const diag::List& Diagnostics() const { return diagnostics_; }
|
||||||
|
|
||||||
/// @returns true if the resolver was successful
|
/// @returns true if the resolver was successful
|
||||||
bool Resolve();
|
bool Resolve();
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include "src/tint/resolver/resolver.h"
|
#include "src/tint/resolver/resolver.h"
|
||||||
#include "src/tint/sem/value_constructor.h"
|
#include "src/tint/sem/value_constructor.h"
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
using namespace tint::number_suffixes; // NOLINT
|
using namespace tint::number_suffixes; // NOLINT
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ TEST_F(AppendVectorTest, Vec2i32_i32) {
|
||||||
WrapInFunction(vec_12, scalar_3);
|
WrapInFunction(vec_12, scalar_3);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_12, scalar_3);
|
auto* append = AppendVector(this, vec_12, scalar_3);
|
||||||
|
|
||||||
|
@ -76,7 +77,8 @@ TEST_F(AppendVectorTest, Vec2i32_u32) {
|
||||||
WrapInFunction(vec_12, scalar_3);
|
WrapInFunction(vec_12, scalar_3);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_12, scalar_3);
|
auto* append = AppendVector(this, vec_12, scalar_3);
|
||||||
|
|
||||||
|
@ -123,7 +125,8 @@ TEST_F(AppendVectorTest, Vec2i32FromVec2u32_u32) {
|
||||||
WrapInFunction(vec_12, scalar_3);
|
WrapInFunction(vec_12, scalar_3);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_12, scalar_3);
|
auto* append = AppendVector(this, vec_12, scalar_3);
|
||||||
|
|
||||||
|
@ -171,7 +174,8 @@ TEST_F(AppendVectorTest, Vec2i32_f32) {
|
||||||
WrapInFunction(vec_12, scalar_3);
|
WrapInFunction(vec_12, scalar_3);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_12, scalar_3);
|
auto* append = AppendVector(this, vec_12, scalar_3);
|
||||||
|
|
||||||
|
@ -216,7 +220,8 @@ TEST_F(AppendVectorTest, Vec3i32_i32) {
|
||||||
WrapInFunction(vec_123, scalar_4);
|
WrapInFunction(vec_123, scalar_4);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_123, scalar_4);
|
auto* append = AppendVector(this, vec_123, scalar_4);
|
||||||
|
|
||||||
|
@ -258,7 +263,8 @@ TEST_F(AppendVectorTest, Vec2i32Var_i32) {
|
||||||
WrapInFunction(vec_12, scalar_3);
|
WrapInFunction(vec_12, scalar_3);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_12, scalar_3);
|
auto* append = AppendVector(this, vec_12, scalar_3);
|
||||||
|
|
||||||
|
@ -296,7 +302,8 @@ TEST_F(AppendVectorTest, Vec2i32_i32Var) {
|
||||||
WrapInFunction(vec_12, scalar_3);
|
WrapInFunction(vec_12, scalar_3);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_12, scalar_3);
|
auto* append = AppendVector(this, vec_12, scalar_3);
|
||||||
|
|
||||||
|
@ -336,7 +343,8 @@ TEST_F(AppendVectorTest, Vec2i32Var_i32Var) {
|
||||||
WrapInFunction(vec_12, scalar_3);
|
WrapInFunction(vec_12, scalar_3);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_12, scalar_3);
|
auto* append = AppendVector(this, vec_12, scalar_3);
|
||||||
|
|
||||||
|
@ -373,7 +381,8 @@ TEST_F(AppendVectorTest, Vec2i32Var_f32Var) {
|
||||||
WrapInFunction(vec_12, scalar_3);
|
WrapInFunction(vec_12, scalar_3);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_12, scalar_3);
|
auto* append = AppendVector(this, vec_12, scalar_3);
|
||||||
|
|
||||||
|
@ -414,7 +423,8 @@ TEST_F(AppendVectorTest, Vec2boolVar_boolVar) {
|
||||||
WrapInFunction(vec_12, scalar_3);
|
WrapInFunction(vec_12, scalar_3);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec_12, scalar_3);
|
auto* append = AppendVector(this, vec_12, scalar_3);
|
||||||
|
|
||||||
|
@ -449,7 +459,8 @@ TEST_F(AppendVectorTest, ZeroVec3i32_i32) {
|
||||||
WrapInFunction(vec000, scalar);
|
WrapInFunction(vec000, scalar);
|
||||||
|
|
||||||
resolver::Resolver resolver(this);
|
resolver::Resolver resolver(this);
|
||||||
ASSERT_TRUE(resolver.Resolve()) << resolver.error();
|
EXPECT_TRUE(resolver.Resolve());
|
||||||
|
ASSERT_THAT(resolver.Diagnostics(), testing::IsEmpty());
|
||||||
|
|
||||||
auto* append = AppendVector(this, vec000, scalar);
|
auto* append = AppendVector(this, vec000, scalar);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue