Cleanup WGSL writer.

This Cl removes the boolean return values from most of the WGSL writer
methods. The diagnostics are used to determine if the generation was
successful. The writer itself just continues until complete.

Change-Id: Iff33128c1df286cab799f08dab8c3defc5651d76
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/124680
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:
dan sinclair 2023-04-13 02:57:27 +00:00 committed by Dawn LUCI CQ
parent 818865925d
commit 27c7722620
34 changed files with 605 additions and 798 deletions

View File

@ -17,6 +17,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/generator_impl.h" #include "src/tint/writer/wgsl/generator_impl.h"
#include "gmock/gmock.h"
namespace tint::reader::spirv::test { namespace tint::reader::spirv::test {
// Default to not dumping the SPIR-V assembly. // Default to not dumping the SPIR-V assembly.
@ -35,7 +37,9 @@ ParserImplWrapperForTest::~ParserImplWrapperForTest() {
std::string ToString(const Program& program) { std::string ToString(const Program& program) {
writer::wgsl::GeneratorImpl writer(&program); writer::wgsl::GeneratorImpl writer(&program);
if (!writer.Generate()) { writer.Generate();
if (!writer.Diagnostics().empty()) {
return "WGSL writer error: " + writer.Diagnostics().str(); return "WGSL writer error: " + writer.Diagnostics().str();
} }
return writer.result(); return writer.result();
@ -44,9 +48,10 @@ std::string ToString(const Program& program) {
std::string ToString(const Program& program, utils::VectorRef<const ast::Statement*> stmts) { std::string ToString(const Program& program, utils::VectorRef<const ast::Statement*> stmts) {
writer::wgsl::GeneratorImpl writer(&program); writer::wgsl::GeneratorImpl writer(&program);
for (const auto* stmt : stmts) { for (const auto* stmt : stmts) {
if (!writer.EmitStatement(stmt)) { writer.EmitStatement(stmt);
return "WGSL writer error: " + writer.Diagnostics().str(); }
} if (!writer.Diagnostics().empty()) {
return "WGSL writer error: " + writer.Diagnostics().str();
} }
return writer.result(); return writer.result();
} }
@ -57,13 +62,15 @@ std::string ToString(const Program& program, const ast::Node* node) {
node, node,
[&](const ast::Expression* expr) { [&](const ast::Expression* expr) {
utils::StringStream out; utils::StringStream out;
if (!writer.EmitExpression(out, expr)) { writer.EmitExpression(out, expr);
if (!writer.Diagnostics().empty()) {
return "WGSL writer error: " + writer.Diagnostics().str(); return "WGSL writer error: " + writer.Diagnostics().str();
} }
return out.str(); return out.str();
}, },
[&](const ast::Statement* stmt) { [&](const ast::Statement* stmt) {
if (!writer.EmitStatement(stmt)) { writer.EmitStatement(stmt);
if (!writer.Diagnostics().empty()) {
return "WGSL writer error: " + writer.Diagnostics().str(); return "WGSL writer error: " + writer.Diagnostics().str();
} }
return writer.result(); return writer.result();

View File

@ -26,7 +26,8 @@ Result Generate(const Program* program, const Options&) {
// Generate the WGSL code. // Generate the WGSL code.
auto impl = std::make_unique<GeneratorImpl>(program); auto impl = std::make_unique<GeneratorImpl>(program);
result.success = impl->Generate(); impl->Generate();
result.success = impl->Diagnostics().empty();
result.error = impl->Diagnostics().str(); result.error = impl->Diagnostics().str();
result.wgsl = impl->result(); result.wgsl = impl->result();

File diff suppressed because it is too large Load Diff

View File

@ -49,181 +49,141 @@ class GeneratorImpl : public TextGenerator {
~GeneratorImpl(); ~GeneratorImpl();
/// Generates the result data /// Generates the result data
/// @returns true on successful generation; false otherwise void Generate();
bool Generate();
/// Handles generating a diagnostic control /// Handles generating a diagnostic control
/// @param out the output stream /// @param out the output stream
/// @param diagnostic the diagnostic control node /// @param diagnostic the diagnostic control node
/// @returns true if the diagnostic control was emitted void EmitDiagnosticControl(utils::StringStream& out, const ast::DiagnosticControl& diagnostic);
bool EmitDiagnosticControl(utils::StringStream& out, const ast::DiagnosticControl& diagnostic);
/// Handles generating an enable directive /// Handles generating an enable directive
/// @param enable the enable node /// @param enable the enable node
/// @returns true if the enable directive was emitted void EmitEnable(const ast::Enable* enable);
bool EmitEnable(const ast::Enable* enable);
/// Handles generating a declared type /// Handles generating a declared type
/// @param ty the declared type to generate /// @param ty the declared type to generate
/// @returns true if the declared type was emitted void EmitTypeDecl(const ast::TypeDecl* ty);
bool EmitTypeDecl(const ast::TypeDecl* ty);
/// Handles an index accessor expression /// Handles an index accessor expression
/// @param out the output stream /// @param out the output stream
/// @param expr the expression to emit /// @param expr the expression to emit
/// @returns true if the index accessor was emitted void EmitIndexAccessor(utils::StringStream& out, const ast::IndexAccessorExpression* expr);
bool EmitIndexAccessor(utils::StringStream& out, const ast::IndexAccessorExpression* expr);
/// Handles an assignment statement /// Handles an assignment statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully void EmitAssign(const ast::AssignmentStatement* stmt);
bool EmitAssign(const ast::AssignmentStatement* stmt);
/// Handles generating a binary expression /// Handles generating a binary expression
/// @param out the output stream /// @param out the output stream
/// @param expr the binary expression /// @param expr the binary expression
/// @returns true if the expression was emitted, false otherwise void EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr);
bool EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr);
/// Handles generating a binary operator /// Handles generating a binary operator
/// @param out the output stream /// @param out the output stream
/// @param op the binary operator /// @param op the binary operator
/// @returns true if the operator was emitted, false otherwise void EmitBinaryOp(utils::StringStream& out, const ast::BinaryOp op);
bool EmitBinaryOp(utils::StringStream& out, const ast::BinaryOp op);
/// Handles generating a bitcast expression /// Handles generating a bitcast expression
/// @param out the output stream /// @param out the output stream
/// @param expr the bitcast expression /// @param expr the bitcast expression
/// @returns true if the bitcast was emitted void EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr);
bool EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr);
/// Handles a block statement /// Handles a block statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully void EmitBlock(const ast::BlockStatement* stmt);
bool EmitBlock(const ast::BlockStatement* stmt);
/// Handles emitting the start of a block statement (including attributes) /// Handles emitting the start of a block statement (including attributes)
/// @param out the output stream to write the header to /// @param out the output stream to write the header to
/// @param stmt the block statement to emit the header for /// @param stmt the block statement to emit the header for
/// @returns true if the statement was emitted successfully void EmitBlockHeader(utils::StringStream& out, const ast::BlockStatement* stmt);
bool EmitBlockHeader(utils::StringStream& out, const ast::BlockStatement* stmt);
/// Handles a break statement /// Handles a break statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully void EmitBreak(const ast::BreakStatement* stmt);
bool EmitBreak(const ast::BreakStatement* stmt);
/// Handles a break-if statement /// Handles a break-if statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully void EmitBreakIf(const ast::BreakIfStatement* stmt);
bool EmitBreakIf(const ast::BreakIfStatement* stmt);
/// Handles generating a call expression /// Handles generating a call expression
/// @param out the output stream /// @param out the output stream
/// @param expr the call expression /// @param expr the call expression
/// @returns true if the call expression is emitted void EmitCall(utils::StringStream& out, const ast::CallExpression* expr);
bool EmitCall(utils::StringStream& out, const ast::CallExpression* expr);
/// Handles a case statement /// Handles a case statement
/// @param stmt the statement /// @param stmt the statement
/// @returns true if the statment was emitted successfully void EmitCase(const ast::CaseStatement* stmt);
bool EmitCase(const ast::CaseStatement* stmt);
/// Handles a compound assignment statement /// Handles a compound assignment statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully void EmitCompoundAssign(const ast::CompoundAssignmentStatement* stmt);
bool EmitCompoundAssign(const ast::CompoundAssignmentStatement* stmt);
/// Handles generating a literal expression /// Handles generating a literal expression
/// @param out the output stream /// @param out the output stream
/// @param expr the literal expression expression /// @param expr the literal expression expression
/// @returns true if the literal expression is emitted void EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* expr);
bool EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* expr);
/// Handles a continue statement /// Handles a continue statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully void EmitContinue(const ast::ContinueStatement* stmt);
bool EmitContinue(const ast::ContinueStatement* stmt);
/// Handles generate an Expression /// Handles generate an Expression
/// @param out the output stream /// @param out the output stream
/// @param expr the expression /// @param expr the expression
/// @returns true if the expression was emitted void EmitExpression(utils::StringStream& out, const ast::Expression* expr);
bool EmitExpression(utils::StringStream& out, const ast::Expression* expr);
/// Handles generating a function /// Handles generating a function
/// @param func the function to generate /// @param func the function to generate
/// @returns true if the function was emitted void EmitFunction(const ast::Function* func);
bool EmitFunction(const ast::Function* func);
/// Handles generating an identifier expression /// Handles generating an identifier expression
/// @param out the output stream /// @param out the output stream
/// @param expr the identifier expression /// @param expr the identifier expression
/// @returns true if the identifier was emitted void EmitIdentifier(utils::StringStream& out, const ast::IdentifierExpression* expr);
bool EmitIdentifier(utils::StringStream& out, const ast::IdentifierExpression* expr);
/// Handles generating an identifier /// Handles generating an identifier
/// @param out the output of the expression stream /// @param out the output of the expression stream
/// @param ident the identifier /// @param ident the identifier
/// @returns true if the identifier was emitted void EmitIdentifier(utils::StringStream& out, const ast::Identifier* ident);
bool EmitIdentifier(utils::StringStream& out, const ast::Identifier* ident);
/// Handles an if statement /// Handles an if statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted void EmitIf(const ast::IfStatement* stmt);
bool EmitIf(const ast::IfStatement* stmt);
/// Handles an increment/decrement statement /// Handles an increment/decrement statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted void EmitIncrementDecrement(const ast::IncrementDecrementStatement* stmt);
bool EmitIncrementDecrement(const ast::IncrementDecrementStatement* stmt);
/// Handles generating a discard statement /// Handles generating a discard statement
/// @param stmt the discard statement /// @param stmt the discard statement
/// @returns true if the statement was successfully emitted void EmitDiscard(const ast::DiscardStatement* stmt);
bool EmitDiscard(const ast::DiscardStatement* stmt);
/// Handles a loop statement /// Handles a loop statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emtited void EmitLoop(const ast::LoopStatement* stmt);
bool EmitLoop(const ast::LoopStatement* stmt);
/// Handles a for-loop statement /// Handles a for-loop statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emtited void EmitForLoop(const ast::ForLoopStatement* stmt);
bool EmitForLoop(const ast::ForLoopStatement* stmt);
/// Handles a while statement /// Handles a while statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emtited void EmitWhile(const ast::WhileStatement* stmt);
bool EmitWhile(const ast::WhileStatement* stmt);
/// Handles a member accessor expression /// Handles a member accessor expression
/// @param out the output stream /// @param out the output stream
/// @param expr the member accessor expression /// @param expr the member accessor expression
/// @returns true if the member accessor was emitted void EmitMemberAccessor(utils::StringStream& out, const ast::MemberAccessorExpression* expr);
bool EmitMemberAccessor(utils::StringStream& out, const ast::MemberAccessorExpression* expr);
/// Handles return statements /// Handles return statements
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted void EmitReturn(const ast::ReturnStatement* stmt);
bool EmitReturn(const ast::ReturnStatement* stmt);
/// Handles const assertion statements /// Handles const assertion statements
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted void EmitConstAssert(const ast::ConstAssert* stmt);
bool EmitConstAssert(const ast::ConstAssert* stmt);
/// Handles statement /// Handles statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted void EmitStatement(const ast::Statement* stmt);
bool EmitStatement(const ast::Statement* stmt);
/// Handles a statement list /// Handles a statement list
/// @param stmts the statements to emit /// @param stmts the statements to emit
/// @returns true if the statements were emitted void EmitStatements(utils::VectorRef<const ast::Statement*> stmts);
bool EmitStatements(utils::VectorRef<const ast::Statement*> stmts);
/// Handles a statement list with an increased indentation /// Handles a statement list with an increased indentation
/// @param stmts the statements to emit /// @param stmts the statements to emit
/// @returns true if the statements were emitted void EmitStatementsWithIndent(utils::VectorRef<const ast::Statement*> stmts);
bool EmitStatementsWithIndent(utils::VectorRef<const ast::Statement*> stmts);
/// Handles generating a switch statement /// Handles generating a switch statement
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was emitted void EmitSwitch(const ast::SwitchStatement* stmt);
bool EmitSwitch(const ast::SwitchStatement* stmt);
/// Handles generating a struct declaration /// Handles generating a struct declaration
/// @param str the struct /// @param str the struct
/// @returns true if the struct is emitted void EmitStructType(const ast::Struct* str);
bool EmitStructType(const ast::Struct* str);
/// Handles emitting an image format /// Handles emitting an image format
/// @param out the output stream /// @param out the output stream
/// @param fmt the format to generate /// @param fmt the format to generate
/// @returns true if the format is emitted void EmitImageFormat(utils::StringStream& out, const builtin::TexelFormat fmt);
bool EmitImageFormat(utils::StringStream& out, const builtin::TexelFormat fmt);
/// Handles a unary op expression /// Handles a unary op expression
/// @param out the output stream /// @param out the output stream
/// @param expr the expression to emit /// @param expr the expression to emit
/// @returns true if the expression was emitted void EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr);
bool EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr);
/// Handles generating a variable /// Handles generating a variable
/// @param out the output stream /// @param out the output stream
/// @param var the variable to generate /// @param var the variable to generate
/// @returns true if the variable was emitted void EmitVariable(utils::StringStream& out, const ast::Variable* var);
bool EmitVariable(utils::StringStream& out, const ast::Variable* var);
/// Handles generating a attribute list /// Handles generating a attribute list
/// @param out the output stream /// @param out the output stream
/// @param attrs the attribute list /// @param attrs the attribute list
/// @returns true if the attributes were emitted void EmitAttributes(utils::StringStream& out, utils::VectorRef<const ast::Attribute*> attrs);
bool EmitAttributes(utils::StringStream& out, utils::VectorRef<const ast::Attribute*> attrs);
}; };
} // namespace tint::writer::wgsl } // namespace tint::writer::wgsl

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -23,8 +25,9 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_F32) {
auto* alias = Alias("a", ty.f32()); auto* alias = Alias("a", ty.f32());
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.EmitTypeDecl(alias);
ASSERT_TRUE(gen.EmitTypeDecl(alias)) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(alias a = f32; EXPECT_EQ(gen.result(), R"(alias a = f32;
)"); )");
} }
@ -38,9 +41,11 @@ TEST_F(WgslGeneratorImplTest, EmitTypeDecl_Struct) {
auto* alias = Alias("B", ty.Of(s)); auto* alias = Alias("B", ty.Of(s));
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.EmitTypeDecl(s);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
ASSERT_TRUE(gen.EmitTypeDecl(s)) << gen.Diagnostics(); gen.EmitTypeDecl(alias);
ASSERT_TRUE(gen.EmitTypeDecl(alias)) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(struct A { EXPECT_EQ(gen.result(), R"(struct A {
a : f32, a : f32,
b : i32, b : i32,
@ -59,7 +64,8 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_ToStruct) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitTypeDecl(alias)) << gen.Diagnostics(); gen.EmitTypeDecl(alias);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(alias B = A; EXPECT_EQ(gen.result(), R"(alias B = A;
)"); )");
} }

View File

@ -15,6 +15,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -30,7 +32,8 @@ TEST_F(WgslGeneratorImplTest, IndexAccessor) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); gen.EmitExpression(out, expr);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "ary[5i]"); EXPECT_EQ(out.str(), "ary[5i]");
} }
@ -44,7 +47,8 @@ TEST_F(WgslGeneratorImplTest, IndexAccessor_OfDref) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); gen.EmitExpression(out, expr);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "(*(p))[5i]"); EXPECT_EQ(out.str(), "(*(p))[5i]");
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Assign) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(assign)) << gen.Diagnostics(); gen.EmitStatement(assign);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " lhs = rhs;\n"); EXPECT_EQ(gen.result(), " lhs = rhs;\n");
} }

View File

@ -15,6 +15,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -51,7 +53,8 @@ TEST_P(WgslBinaryTest, Emit) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); gen.EmitExpression(out, expr);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), params.result); EXPECT_EQ(out.str(), params.result);
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(

View File

@ -15,6 +15,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Bitcast) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.Diagnostics(); gen.EmitExpression(out, bitcast);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "bitcast<f32>(1i)"); EXPECT_EQ(out.str(), "bitcast<f32>(1i)");
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -27,7 +29,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Block) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(b)) << gen.Diagnostics(); gen.EmitStatement(b);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( { EXPECT_EQ(gen.result(), R"( {
return; return;
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -27,7 +29,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Break) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(b)) << gen.Diagnostics(); gen.EmitStatement(b);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " break;\n"); EXPECT_EQ(gen.result(), " break;\n");
} }

View File

@ -16,6 +16,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -35,7 +37,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.Diagnostics(); gen.EmitExpression(out, call);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "my_func()"); EXPECT_EQ(out.str(), "my_func()");
} }
@ -58,7 +61,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Call_WithParams) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.Diagnostics(); gen.EmitExpression(out, call);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "my_func(param1, param2)"); EXPECT_EQ(out.str(), "my_func(param1, param2)");
} }
@ -79,7 +83,8 @@ TEST_F(WgslGeneratorImplTest, EmitStatement_Call) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); gen.EmitStatement(stmt);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " my_func(param1, param2);\n"); EXPECT_EQ(gen.result(), " my_func(param1, param2);\n");
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -30,7 +32,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Case) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.Diagnostics(); gen.EmitCase(s->body[0]);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( case 5i: { EXPECT_EQ(gen.result(), R"( case 5i: {
break; break;
} }
@ -52,7 +55,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.Diagnostics(); gen.EmitCase(s->body[0]);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( case 5i, 6i: { EXPECT_EQ(gen.result(), R"( case 5i, 6i: {
break; break;
} }
@ -67,7 +71,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_Default) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.Diagnostics(); gen.EmitCase(s->body[0]);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( default: { EXPECT_EQ(gen.result(), R"( default: {
break; break;
} }

View File

@ -15,6 +15,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Cast_Scalar_F32_From_I32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.Diagnostics(); gen.EmitExpression(out, cast);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "f32(1i)"); EXPECT_EQ(out.str(), "f32(1i)");
} }
@ -42,7 +45,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Cast_Scalar_F16_From_I32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.Diagnostics(); gen.EmitExpression(out, cast);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "f16(1i)"); EXPECT_EQ(out.str(), "f16(1i)");
} }
@ -53,7 +57,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Cast_Vector_F32_From_I32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.Diagnostics(); gen.EmitExpression(out, cast);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "vec3<f32>(vec3<i32>(1i, 2i, 3i))"); EXPECT_EQ(out.str(), "vec3<f32>(vec3<i32>(1i, 2i, 3i))");
} }
@ -66,7 +71,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Cast_Vector_F16_From_I32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.Diagnostics(); gen.EmitExpression(out, cast);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "vec3<f16>(vec3<i32>(1i, 2i, 3i))"); EXPECT_EQ(out.str(), "vec3<f16>(vec3<i32>(1i, 2i, 3i))");
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -25,8 +27,8 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalConstAssert) {
GlobalConstAssert(true); GlobalConstAssert(true);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(const_assert true; EXPECT_EQ(gen.result(), R"(const_assert true;
)"); )");
} }
@ -35,8 +37,8 @@ TEST_F(WgslGeneratorImplTest, Emit_FunctionConstAssert) {
Func("f", utils::Empty, ty.void_(), utils::Vector{ConstAssert(true)}); Func("f", utils::Empty, ty.void_(), utils::Vector{ConstAssert(true)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const_assert true; const_assert true;
} }

View File

@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "gmock/gmock.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using ::testing::HasSubstr; using ::testing::HasSubstr;
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
@ -28,8 +29,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Bool) {
WrapInFunction(Expr(false)); WrapInFunction(Expr(false));
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("false")); EXPECT_THAT(gen.result(), HasSubstr("false"));
} }
@ -37,8 +38,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Int) {
WrapInFunction(Expr(-12345_i)); WrapInFunction(Expr(-12345_i));
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("-12345")); EXPECT_THAT(gen.result(), HasSubstr("-12345"));
} }
@ -46,8 +47,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, UInt) {
WrapInFunction(Expr(56779_u)); WrapInFunction(Expr(56779_u));
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("56779u")); EXPECT_THAT(gen.result(), HasSubstr("56779u"));
} }
@ -57,7 +58,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("1073741824.0f")); EXPECT_THAT(gen.result(), HasSubstr("1073741824.0f"));
} }
@ -69,7 +71,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("32752.0h")); EXPECT_THAT(gen.result(), HasSubstr("32752.0h"));
} }
@ -78,7 +81,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("f32(-0.00001200000042445026f)")); EXPECT_THAT(gen.result(), HasSubstr("f32(-0.00001200000042445026f)"));
} }
@ -89,7 +93,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("f16(-0.00001198053359985352h)")); EXPECT_THAT(gen.result(), HasSubstr("f16(-0.00001198053359985352h)"));
} }
@ -98,7 +103,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Bool) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("bool(true)")); EXPECT_THAT(gen.result(), HasSubstr("bool(true)"));
} }
@ -107,7 +113,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Int) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("i32(-12345i)")); EXPECT_THAT(gen.result(), HasSubstr("i32(-12345i)"));
} }
@ -116,7 +123,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Uint) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("u32(12345u)")); EXPECT_THAT(gen.result(), HasSubstr("u32(12345u)"));
} }
@ -125,7 +133,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Vec_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("vec3<f32>(1.0f, 2.0f, 3.0f)")); EXPECT_THAT(gen.result(), HasSubstr("vec3<f32>(1.0f, 2.0f, 3.0f)"));
} }
@ -136,7 +145,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Vec_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("vec3<f16>(1.0h, 2.0h, 3.0h)")); EXPECT_THAT(gen.result(), HasSubstr("vec3<f16>(1.0h, 2.0h, 3.0h)"));
} }
@ -145,7 +155,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Mat_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("mat2x3<f32>(vec3<f32>(1.0f, 2.0f, 3.0f), " EXPECT_THAT(gen.result(), HasSubstr("mat2x3<f32>(vec3<f32>(1.0f, 2.0f, 3.0f), "
"vec3<f32>(3.0f, 4.0f, 5.0f))")); "vec3<f32>(3.0f, 4.0f, 5.0f))"));
} }
@ -157,7 +168,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Mat_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), HasSubstr("mat2x3<f16>(vec3<f16>(1.0h, 2.0h, 3.0h), " EXPECT_THAT(gen.result(), HasSubstr("mat2x3<f16>(vec3<f16>(1.0h, 2.0h, 3.0h), "
"vec3<f16>(3.0h, 4.0h, 5.0h))")); "vec3<f16>(3.0h, 4.0h, 5.0h))"));
} }
@ -168,7 +180,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Array) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), EXPECT_THAT(gen.result(),
HasSubstr("array<vec3<f32>, 3u>(vec3<f32>(1.0f, 2.0f, 3.0f), " HasSubstr("array<vec3<f32>, 3u>(vec3<f32>(1.0f, 2.0f, 3.0f), "
"vec3<f32>(4.0f, 5.0f, 6.0f), vec3<f32>(7.0f, 8.0f, 9.0f))")); "vec3<f32>(4.0f, 5.0f, 6.0f), vec3<f32>(7.0f, 8.0f, 9.0f))"));
@ -180,7 +193,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_ImplicitArray) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_THAT(gen.result(), EXPECT_THAT(gen.result(),
HasSubstr("array(vec3<f32>(1.0f, 2.0f, 3.0f), " HasSubstr("array(vec3<f32>(1.0f, 2.0f, 3.0f), "
"vec3<f32>(4.0f, 5.0f, 6.0f), vec3<f32>(7.0f, 8.0f, 9.0f))")); "vec3<f32>(4.0f, 5.0f, 6.0f), vec3<f32>(7.0f, 8.0f, 9.0f))"));

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Continue) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(c)) << gen.Diagnostics(); gen.EmitStatement(c);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " continue;\n"); EXPECT_EQ(gen.result(), " continue;\n");
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -23,8 +25,8 @@ TEST_F(WgslGeneratorImplTest, Emit_DiagnosticDirective) {
DiagnosticDirective(builtin::DiagnosticSeverity::kError, "chromium_unreachable_code"); DiagnosticDirective(builtin::DiagnosticSeverity::kError, "chromium_unreachable_code");
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(diagnostic(error, chromium_unreachable_code); EXPECT_EQ(gen.result(), R"(diagnostic(error, chromium_unreachable_code);
)"); )");
@ -36,8 +38,8 @@ TEST_F(WgslGeneratorImplTest, Emit_DiagnosticAttribute) {
Func("foo", {}, ty.void_(), {}, utils::Vector{attr}); Func("foo", {}, ty.void_(), {}, utils::Vector{attr});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(@diagnostic(error, chromium_unreachable_code) EXPECT_EQ(gen.result(), R"(@diagnostic(error, chromium_unreachable_code)
fn foo() { fn foo() {
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Discard) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); gen.EmitStatement(stmt);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " discard;\n"); EXPECT_EQ(gen.result(), " discard;\n");
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -24,7 +26,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Enable) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitEnable(enable)); gen.EmitEnable(enable);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(enable f16; EXPECT_EQ(gen.result(), R"(enable f16;
)"); )");
} }

View File

@ -18,6 +18,8 @@
#include "src/tint/builtin/builtin_value.h" #include "src/tint/builtin/builtin_value.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -34,8 +36,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.EmitFunction(func);
ASSERT_TRUE(gen.EmitFunction(func)); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( fn my_func() { EXPECT_EQ(gen.result(), R"( fn my_func() {
return; return;
} }
@ -56,8 +58,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.EmitFunction(func);
ASSERT_TRUE(gen.EmitFunction(func)); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( fn my_func(a : f32, b : i32) { EXPECT_EQ(gen.result(), R"( fn my_func(a : f32, b : i32) {
return; return;
} }
@ -77,8 +79,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithAttribute_WorkgroupSize) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.EmitFunction(func);
ASSERT_TRUE(gen.EmitFunction(func)); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( @compute @workgroup_size(2i, 4i, 6i) EXPECT_EQ(gen.result(), R"( @compute @workgroup_size(2i, 4i, 6i)
fn my_func() { fn my_func() {
return; return;
@ -98,8 +100,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithAttribute_MustUse) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.EmitFunction(func);
ASSERT_TRUE(gen.EmitFunction(func)); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( @must_use EXPECT_EQ(gen.result(), R"( @must_use
fn my_func() -> i32 { fn my_func() -> i32 {
return 1i; return 1i;
@ -121,8 +123,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithAttribute_WorkgroupSize_WithIden
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.EmitFunction(func);
ASSERT_TRUE(gen.EmitFunction(func)); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( @compute @workgroup_size(2i, height) EXPECT_EQ(gen.result(), R"( @compute @workgroup_size(2i, height)
fn my_func() { fn my_func() {
return; return;
@ -148,8 +150,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.EmitFunction(func);
ASSERT_TRUE(gen.EmitFunction(func)); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( @fragment EXPECT_EQ(gen.result(), R"( @fragment
fn frag_main(@builtin(position) coord : vec4<f32>, @location(1) loc1 : f32) { fn frag_main(@builtin(position) coord : vec4<f32>, @location(1) loc1 : f32) {
} }
@ -171,8 +173,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_ReturnValue) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.EmitFunction(func);
ASSERT_TRUE(gen.EmitFunction(func)); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( @fragment EXPECT_EQ(gen.result(), R"( @fragment
fn frag_main() -> @location(1) f32 { fn frag_main() -> @location(1) f32 {
return 1.0f; return 1.0f;
@ -234,7 +236,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_Multiple_EntryPoint_With_Same_Module
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(struct Data { EXPECT_EQ(gen.result(), R"(struct Data {
d : f32, d : f32,
} }

View File

@ -18,6 +18,8 @@
#include "src/tint/type/texture_dimension.h" #include "src/tint/type/texture_dimension.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -34,8 +36,8 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalDeclAfterFunction) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( @compute @workgroup_size(1i, 1i, 1i) EXPECT_EQ(gen.result(), R"( @compute @workgroup_size(1i, 1i, 1i)
fn test_function() { fn test_function() {
var a : f32; var a : f32;
@ -78,8 +80,8 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalsInterleaved) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( var<private> a0 : f32; EXPECT_EQ(gen.result(), R"( var<private> a0 : f32;
struct S0 { struct S0 {
@ -111,8 +113,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Global_Sampler) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " @group(0) @binding(0) var s : sampler;\n"); EXPECT_EQ(gen.result(), " @group(0) @binding(0) var s : sampler;\n");
} }
@ -123,8 +125,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Global_Texture) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " @group(0) @binding(0) var t : texture_1d<f32>;\n"); EXPECT_EQ(gen.result(), " @group(0) @binding(0) var t : texture_1d<f32>;\n");
} }
@ -135,8 +137,8 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalConst) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( const explicit : f32 = 1.0f; EXPECT_EQ(gen.result(), R"( const explicit : f32 = 1.0f;
const inferred = 1.0f; const inferred = 1.0f;
@ -150,8 +152,8 @@ TEST_F(WgslGeneratorImplTest, Emit_OverridableConstants) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( override a : f32; EXPECT_EQ(gen.result(), R"( override a : f32;
@id(7) override b : f32; @id(7) override b : f32;

View File

@ -15,6 +15,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -28,7 +30,8 @@ TEST_F(WgslGeneratorImplTest, EmitIdentifierExpression_Single) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, i)) << gen.Diagnostics(); gen.EmitExpression(out, i);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "glsl"); EXPECT_EQ(out.str(), "glsl");
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -31,7 +33,8 @@ TEST_F(WgslGeneratorImplTest, Emit_If) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(i)) << gen.Diagnostics(); gen.EmitStatement(i);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( if (cond) { EXPECT_EQ(gen.result(), R"( if (cond) {
return; return;
} }
@ -54,7 +57,8 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(i)) << gen.Diagnostics(); gen.EmitStatement(i);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( if (cond) { EXPECT_EQ(gen.result(), R"( if (cond) {
return; return;
} else if (else_cond) { } else if (else_cond) {
@ -77,7 +81,8 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElse) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(i)) << gen.Diagnostics(); gen.EmitStatement(i);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( if (cond) { EXPECT_EQ(gen.result(), R"( if (cond) {
return; return;
} else { } else {
@ -105,7 +110,8 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithMultiple) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(i)) << gen.Diagnostics(); gen.EmitStatement(i);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( if (cond) { EXPECT_EQ(gen.result(), R"( if (cond) {
return; return;
} else if (else_cond) { } else if (else_cond) {

View File

@ -17,6 +17,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -116,7 +118,8 @@ TEST_P(WgslGenerator_F32LiteralTest, Emit) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitLiteral(out, v)) << gen.Diagnostics(); gen.EmitLiteral(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), GetParam().expected); EXPECT_EQ(out.str(), GetParam().expected);
} }
@ -164,7 +167,8 @@ TEST_P(WgslGenerator_F16LiteralTest, Emit) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitLiteral(out, v)) << gen.Diagnostics(); gen.EmitLiteral(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), GetParam().expected); EXPECT_EQ(out.str(), GetParam().expected);
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -33,7 +35,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Loop) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(l)) << gen.Diagnostics(); gen.EmitStatement(l);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( loop { EXPECT_EQ(gen.result(), R"( loop {
break; break;
} }
@ -54,7 +57,8 @@ TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(l)) << gen.Diagnostics(); gen.EmitStatement(l);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( loop { EXPECT_EQ(gen.result(), R"( loop {
break; break;
@ -79,7 +83,8 @@ TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing_BreakIf) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(l)) << gen.Diagnostics(); gen.EmitStatement(l);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( loop { EXPECT_EQ(gen.result(), R"( loop {
discard; discard;
@ -105,7 +110,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtInit) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); gen.EmitStatement(f);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( for({ EXPECT_EQ(gen.result(), R"( for({
_ = 1i; _ = 1i;
_ = 2i; _ = 2i;
@ -127,7 +133,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithSimpleCond) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); gen.EmitStatement(f);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( for(; true; ) { EXPECT_EQ(gen.result(), R"( for(; true; ) {
return; return;
} }
@ -147,7 +154,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithSimpleCont) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); gen.EmitStatement(f);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( for(; ; i = (i + 1i)) { EXPECT_EQ(gen.result(), R"( for(; ; i = (i + 1i)) {
return; return;
} }
@ -169,7 +177,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtCont) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); gen.EmitStatement(f);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( for(; ; { EXPECT_EQ(gen.result(), R"( for(; ; {
_ = 1i; _ = 1i;
_ = 2i; _ = 2i;
@ -191,7 +200,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithSimpleInitCondCont) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); gen.EmitStatement(f);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( for(var i : i32; true; i = (i + 1i)) { EXPECT_EQ(gen.result(), R"( for(var i : i32; true; i = (i + 1i)) {
return; return;
} }
@ -213,7 +223,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtInitCondCont) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); gen.EmitStatement(f);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( for({ EXPECT_EQ(gen.result(), R"( for({
_ = 1i; _ = 1i;
_ = 2i; _ = 2i;
@ -238,7 +249,8 @@ TEST_F(WgslGeneratorImplTest, Emit_While) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); gen.EmitStatement(f);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( while(true) { EXPECT_EQ(gen.result(), R"( while(true) {
return; return;
} }
@ -257,7 +269,8 @@ TEST_F(WgslGeneratorImplTest, Emit_While_WithContinue) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); gen.EmitStatement(f);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( while(true) { EXPECT_EQ(gen.result(), R"( while(true) {
continue; continue;
} }
@ -278,7 +291,8 @@ TEST_F(WgslGeneratorImplTest, Emit_WhileMultiCond) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); gen.EmitStatement(f);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( while((true && false)) { EXPECT_EQ(gen.result(), R"( while((true && false)) {
return; return;
} }

View File

@ -15,6 +15,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -30,7 +32,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_MemberAccessor) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); gen.EmitExpression(out, expr);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "str.mem"); EXPECT_EQ(out.str(), "str.mem");
} }
@ -45,7 +48,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_MemberAccessor_OfDref) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); gen.EmitExpression(out, expr);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "(*(p)).mem"); EXPECT_EQ(out.str(), "(*(p)).mem");
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Return) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(r)) << gen.Diagnostics(); gen.EmitStatement(r);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " return;\n"); EXPECT_EQ(gen.result(), " return;\n");
} }
@ -41,7 +44,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ReturnWithValue) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(r)) << gen.Diagnostics(); gen.EmitStatement(r);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " return 123i;\n"); EXPECT_EQ(gen.result(), " return 123i;\n");
} }

View File

@ -14,6 +14,8 @@
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -43,7 +45,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Switch) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(s)) << gen.Diagnostics(); gen.EmitStatement(s);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( switch(cond) { EXPECT_EQ(gen.result(), R"( switch(cond) {
case 5i: { case 5i: {
break; break;
@ -68,8 +71,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Switch_MixedDefault) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.increment_indent(); gen.increment_indent();
gen.EmitStatement(s);
ASSERT_TRUE(gen.EmitStatement(s)) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"( switch(cond) { EXPECT_EQ(gen.result(), R"( switch(cond) {
case 5i, default: { case 5i, default: {
break; break;

View File

@ -15,6 +15,8 @@
#include "src/tint/sem/variable.h" #include "src/tint/sem/variable.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -25,7 +27,8 @@ TEST_F(WgslGeneratorImplTest, Generate) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); gen.Generate();
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn my_func() { EXPECT_EQ(gen.result(), R"(fn my_func() {
} }
)"); )");

View File

@ -20,6 +20,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -34,7 +36,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Alias) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "alias"); EXPECT_EQ(out.str(), "alias");
} }
@ -44,7 +47,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Array) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "array<bool, 4u>"); EXPECT_EQ(out.str(), "array<bool, 4u>");
} }
@ -55,7 +59,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Array_Attribute) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "@stride(16) array<bool, 4u>"); EXPECT_EQ(out.str(), "@stride(16) array<bool, 4u>");
} }
@ -65,7 +70,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "array<bool>"); EXPECT_EQ(out.str(), "array<bool>");
} }
@ -75,7 +81,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Bool) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "bool"); EXPECT_EQ(out.str(), "bool");
} }
@ -85,7 +92,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "f32"); EXPECT_EQ(out.str(), "f32");
} }
@ -97,7 +105,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "f16"); EXPECT_EQ(out.str(), "f16");
} }
@ -107,7 +116,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_I32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "i32"); EXPECT_EQ(out.str(), "i32");
} }
@ -117,7 +127,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Matrix_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "mat2x3<f32>"); EXPECT_EQ(out.str(), "mat2x3<f32>");
} }
@ -129,7 +140,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Matrix_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "mat2x3<f16>"); EXPECT_EQ(out.str(), "mat2x3<f16>");
} }
@ -140,7 +152,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Pointer) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "ptr<workgroup, f32>"); EXPECT_EQ(out.str(), "ptr<workgroup, f32>");
} }
@ -152,7 +165,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_PointerAccessMode) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "ptr<storage, f32, read_write>"); EXPECT_EQ(out.str(), "ptr<storage, f32, read_write>");
} }
@ -166,7 +180,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "S"); EXPECT_EQ(out.str(), "S");
} }
@ -178,7 +193,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructOffsetDecl) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStructType(s)) << gen.Diagnostics(); gen.EmitStructType(s);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(struct S { EXPECT_EQ(gen.result(), R"(struct S {
@size(8) @size(8)
padding : u32, padding : u32,
@ -201,7 +217,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructOffsetDecl_WithSymbolCollisions) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStructType(s)) << gen.Diagnostics(); gen.EmitStructType(s);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(struct S { EXPECT_EQ(gen.result(), R"(struct S {
@size(8) @size(8)
padding : u32, padding : u32,
@ -223,7 +240,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructAlignDecl) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStructType(s)) << gen.Diagnostics(); gen.EmitStructType(s);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(struct S { EXPECT_EQ(gen.result(), R"(struct S {
@align(8) @align(8)
a : i32, a : i32,
@ -241,7 +259,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructSizeDecl) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStructType(s)) << gen.Diagnostics(); gen.EmitStructType(s);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(struct S { EXPECT_EQ(gen.result(), R"(struct S {
@size(16) @size(16)
a : i32, a : i32,
@ -259,7 +278,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithAttribute) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStructType(s)) << gen.Diagnostics(); gen.EmitStructType(s);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(struct S { EXPECT_EQ(gen.result(), R"(struct S {
a : i32, a : i32,
@align(8) @align(8)
@ -277,7 +297,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithEntryPointAttributes) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitStructType(s)) << gen.Diagnostics(); gen.EmitStructType(s);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(struct S { EXPECT_EQ(gen.result(), R"(struct S {
@builtin(vertex_index) @builtin(vertex_index)
a : u32, a : u32,
@ -293,7 +314,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_U32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "u32"); EXPECT_EQ(out.str(), "u32");
} }
@ -303,7 +325,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Vector_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "vec3<f32>"); EXPECT_EQ(out.str(), "vec3<f32>");
} }
@ -315,7 +338,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Vector_F16) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "vec3<f16>"); EXPECT_EQ(out.str(), "vec3<f16>");
} }
@ -337,7 +361,8 @@ TEST_P(WgslGenerator_DepthTextureTest, EmitType_DepthTexture) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), param.name); EXPECT_EQ(out.str(), param.name);
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -358,7 +383,8 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), std::string(param.name) + "<f32>"); EXPECT_EQ(out.str(), std::string(param.name) + "<f32>");
} }
@ -371,7 +397,8 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_I32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), std::string(param.name) + "<i32>"); EXPECT_EQ(out.str(), std::string(param.name) + "<i32>");
} }
@ -384,7 +411,8 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_U32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), std::string(param.name) + "<u32>"); EXPECT_EQ(out.str(), std::string(param.name) + "<u32>");
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -407,7 +435,8 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), std::string(param.name) + "<f32>"); EXPECT_EQ(out.str(), std::string(param.name) + "<f32>");
} }
@ -420,7 +449,8 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_I32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), std::string(param.name) + "<i32>"); EXPECT_EQ(out.str(), std::string(param.name) + "<i32>");
} }
@ -433,7 +463,8 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_U32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), std::string(param.name) + "<u32>"); EXPECT_EQ(out.str(), std::string(param.name) + "<u32>");
} }
INSTANTIATE_TEST_SUITE_P(WgslGeneratorImplTest, INSTANTIATE_TEST_SUITE_P(WgslGeneratorImplTest,
@ -461,7 +492,8 @@ TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), param.name); EXPECT_EQ(out.str(), param.name);
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -492,7 +524,8 @@ TEST_P(WgslGenerator_ImageFormatTest, EmitType_StorageTexture_ImageFormat) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitImageFormat(out, param.fmt)) << gen.Diagnostics(); gen.EmitImageFormat(out, param.fmt);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), param.name); EXPECT_EQ(out.str(), param.name);
} }
@ -523,7 +556,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Sampler) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "sampler"); EXPECT_EQ(out.str(), "sampler");
} }
@ -534,7 +568,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_SamplerComparison) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.Diagnostics(); gen.EmitExpression(out, type);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "sampler_comparison"); EXPECT_EQ(out.str(), "sampler_comparison");
} }

View File

@ -15,6 +15,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
namespace { namespace {
@ -28,7 +30,8 @@ TEST_F(WgslUnaryOpTest, AddressOf) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); gen.EmitExpression(out, op);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "&(expr)"); EXPECT_EQ(out.str(), "&(expr)");
} }
@ -40,7 +43,8 @@ TEST_F(WgslUnaryOpTest, Complement) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); gen.EmitExpression(out, op);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "~(expr)"); EXPECT_EQ(out.str(), "~(expr)");
} }
@ -53,7 +57,8 @@ TEST_F(WgslUnaryOpTest, Indirection) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); gen.EmitExpression(out, op);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "*(expr)"); EXPECT_EQ(out.str(), "*(expr)");
} }
@ -65,7 +70,8 @@ TEST_F(WgslUnaryOpTest, Not) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); gen.EmitExpression(out, op);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "!(expr)"); EXPECT_EQ(out.str(), "!(expr)");
} }
@ -77,7 +83,8 @@ TEST_F(WgslUnaryOpTest, Negation) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); gen.EmitExpression(out, op);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), "-(expr)"); EXPECT_EQ(out.str(), "-(expr)");
} }

View File

@ -15,6 +15,8 @@
#include "src/tint/ast/variable_decl_statement.h" #include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -32,7 +34,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); gen.EmitStatement(stmt);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " var a : f32;\n"); EXPECT_EQ(gen.result(), " var a : f32;\n");
} }
@ -46,7 +49,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_InferredType) {
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); gen.EmitStatement(stmt);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), " var a = 123i;\n"); EXPECT_EQ(gen.result(), " var a = 123i;\n");
} }
@ -59,9 +63,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_AInt) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = 1; const C = 1;
let l = C; let l = C;
@ -78,9 +81,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_AFloat) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = 1.0; const C = 1.0;
let l = C; let l = C;
@ -97,9 +99,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_i32) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = 1i; const C = 1i;
let l = C; let l = C;
@ -116,9 +117,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_u32) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = 1u; const C = 1u;
let l = C; let l = C;
@ -135,9 +135,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_f32) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = 1.0f; const C = 1.0f;
let l = C; let l = C;
@ -156,9 +155,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_f16) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(enable f16; EXPECT_EQ(gen.result(), R"(enable f16;
fn f() { fn f() {
@ -177,9 +175,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_AInt) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = vec3(1, 2, 3); const C = vec3(1, 2, 3);
let l = C; let l = C;
@ -196,9 +193,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_AFloat) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = vec3(1.0, 2.0, 3.0); const C = vec3(1.0, 2.0, 3.0);
let l = C; let l = C;
@ -215,9 +211,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_f32) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = vec3<f32>(1.0f, 2.0f, 3.0f); const C = vec3<f32>(1.0f, 2.0f, 3.0f);
let l = C; let l = C;
@ -236,9 +231,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_f16) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(enable f16; EXPECT_EQ(gen.result(), R"(enable f16;
fn f() { fn f() {
@ -257,9 +251,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_mat2x3_AFloat) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = mat2x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0); const C = mat2x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
let l = C; let l = C;
@ -276,9 +269,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_mat2x3_f32) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = mat2x3<f32>(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f); const C = mat2x3<f32>(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f);
let l = C; let l = C;
@ -297,9 +289,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_mat2x3_f16) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(enable f16; EXPECT_EQ(gen.result(), R"(enable f16;
fn f() { fn f() {
@ -318,9 +309,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_arr_f32) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = array<f32, 3u>(1.0f, 2.0f, 3.0f); const C = array<f32, 3u>(1.0f, 2.0f, 3.0f);
let l = C; let l = C;
@ -340,9 +330,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_arr_vec2_bool) {
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
gen.Generate();
ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(gen.result(), R"(fn f() { EXPECT_EQ(gen.result(), R"(fn f() {
const C = array<vec2<bool>, 3u>(vec2<bool>(true, false), vec2<bool>(false, true), vec2<bool>(true, true)); const C = array<vec2<bool>, 3u>(vec2<bool>(true, false), vec2<bool>(false, true), vec2<bool>(true, true));
let l = C; let l = C;

View File

@ -15,6 +15,8 @@
#include "src/tint/utils/string_stream.h" #include "src/tint/utils/string_stream.h"
#include "src/tint/writer/wgsl/test_helper.h" #include "src/tint/writer/wgsl/test_helper.h"
#include "gmock/gmock.h"
using namespace tint::number_suffixes; // NOLINT using namespace tint::number_suffixes; // NOLINT
namespace tint::writer::wgsl { namespace tint::writer::wgsl {
@ -28,7 +30,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(var<private> a : f32;)"); EXPECT_EQ(out.str(), R"(var<private> a : f32;)");
} }
@ -38,7 +41,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_AddressSpace) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(var<private> a : f32;)"); EXPECT_EQ(out.str(), R"(var<private> a : f32;)");
} }
@ -50,7 +54,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Access_Read) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(@binding(0) @group(0) var<storage, read> a : S;)"); EXPECT_EQ(out.str(), R"(@binding(0) @group(0) var<storage, read> a : S;)");
} }
@ -62,7 +67,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Access_ReadWrite) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(@binding(0) @group(0) var<storage, read_write> a : S;)"); EXPECT_EQ(out.str(), R"(@binding(0) @group(0) var<storage, read_write> a : S;)");
} }
@ -72,7 +78,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(@group(1) @binding(2) var a : sampler;)"); EXPECT_EQ(out.str(), R"(@group(1) @binding(2) var a : sampler;)");
} }
@ -82,7 +89,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Initializer) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(var<private> a : f32 = 1.0f;)"); EXPECT_EQ(out.str(), R"(var<private> a : f32 = 1.0f;)");
} }
@ -93,7 +101,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Let_Explicit) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(let a : f32 = 1.0f;)"); EXPECT_EQ(out.str(), R"(let a : f32 = 1.0f;)");
} }
@ -104,7 +113,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Let_Inferred) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(let a = 1.0f;)"); EXPECT_EQ(out.str(), R"(let a = 1.0f;)");
} }
@ -115,7 +125,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Const_Explicit) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(const a : f32 = 1.0f;)"); EXPECT_EQ(out.str(), R"(const a : f32 = 1.0f;)");
} }
@ -126,7 +137,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Const_Inferred) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
utils::StringStream out; utils::StringStream out;
ASSERT_TRUE(gen.EmitVariable(out, v)) << gen.Diagnostics(); gen.EmitVariable(out, v);
EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty());
EXPECT_EQ(out.str(), R"(const a = 1.0f;)"); EXPECT_EQ(out.str(), R"(const a = 1.0f;)");
} }