diff --git a/src/tint/reader/spirv/parser_impl_test_helper.cc b/src/tint/reader/spirv/parser_impl_test_helper.cc index 3af217a157..4a57379e14 100644 --- a/src/tint/reader/spirv/parser_impl_test_helper.cc +++ b/src/tint/reader/spirv/parser_impl_test_helper.cc @@ -17,6 +17,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/generator_impl.h" +#include "gmock/gmock.h" + namespace tint::reader::spirv::test { // Default to not dumping the SPIR-V assembly. @@ -35,7 +37,9 @@ ParserImplWrapperForTest::~ParserImplWrapperForTest() { std::string ToString(const Program& program) { writer::wgsl::GeneratorImpl writer(&program); - if (!writer.Generate()) { + writer.Generate(); + + if (!writer.Diagnostics().empty()) { return "WGSL writer error: " + writer.Diagnostics().str(); } return writer.result(); @@ -44,9 +48,10 @@ std::string ToString(const Program& program) { std::string ToString(const Program& program, utils::VectorRef stmts) { writer::wgsl::GeneratorImpl writer(&program); for (const auto* stmt : stmts) { - if (!writer.EmitStatement(stmt)) { - return "WGSL writer error: " + writer.Diagnostics().str(); - } + writer.EmitStatement(stmt); + } + if (!writer.Diagnostics().empty()) { + return "WGSL writer error: " + writer.Diagnostics().str(); } return writer.result(); } @@ -57,13 +62,15 @@ std::string ToString(const Program& program, const ast::Node* node) { node, [&](const ast::Expression* expr) { utils::StringStream out; - if (!writer.EmitExpression(out, expr)) { + writer.EmitExpression(out, expr); + if (!writer.Diagnostics().empty()) { return "WGSL writer error: " + writer.Diagnostics().str(); } return out.str(); }, [&](const ast::Statement* stmt) { - if (!writer.EmitStatement(stmt)) { + writer.EmitStatement(stmt); + if (!writer.Diagnostics().empty()) { return "WGSL writer error: " + writer.Diagnostics().str(); } return writer.result(); diff --git a/src/tint/writer/wgsl/generator.cc b/src/tint/writer/wgsl/generator.cc index b4e9713d78..f1f3f6896d 100644 --- a/src/tint/writer/wgsl/generator.cc +++ b/src/tint/writer/wgsl/generator.cc @@ -26,7 +26,8 @@ Result Generate(const Program* program, const Options&) { // Generate the WGSL code. auto impl = std::make_unique(program); - result.success = impl->Generate(); + impl->Generate(); + result.success = impl->Diagnostics().empty(); result.error = impl->Diagnostics().str(); result.wgsl = impl->result(); diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index e1bf9fc7eb..744bbd2606 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -46,20 +46,16 @@ GeneratorImpl::GeneratorImpl(const Program* program) : TextGenerator(program) {} GeneratorImpl::~GeneratorImpl() = default; -bool GeneratorImpl::Generate() { +void GeneratorImpl::Generate() { // Generate directives before any other global declarations. bool has_directives = false; for (auto enable : program_->AST().Enables()) { - if (!EmitEnable(enable)) { - return false; - } + EmitEnable(enable); has_directives = true; } for (auto diagnostic : program_->AST().DiagnosticDirectives()) { auto out = line(); - if (!EmitDiagnosticControl(out, diagnostic->control)) { - return false; - } + EmitDiagnosticControl(out, diagnostic->control); out << ";"; has_directives = true; } @@ -71,34 +67,26 @@ bool GeneratorImpl::Generate() { if (decl->IsAnyOf()) { continue; } - if (!Switch( - decl, // - [&](const ast::TypeDecl* td) { return EmitTypeDecl(td); }, - [&](const ast::Function* func) { return EmitFunction(func); }, - [&](const ast::Variable* var) { return EmitVariable(line(), var); }, - [&](const ast::ConstAssert* ca) { return EmitConstAssert(ca); }, - [&](Default) { - TINT_UNREACHABLE(Writer, diagnostics_); - return false; - })) { - return false; - } + Switch( + decl, // + [&](const ast::TypeDecl* td) { return EmitTypeDecl(td); }, + [&](const ast::Function* func) { return EmitFunction(func); }, + [&](const ast::Variable* var) { return EmitVariable(line(), var); }, + [&](const ast::ConstAssert* ca) { return EmitConstAssert(ca); }, + [&](Default) { TINT_UNREACHABLE(Writer, diagnostics_); }); if (decl != program_->AST().GlobalDeclarations().Back()) { line(); } } - - return true; } -bool GeneratorImpl::EmitDiagnosticControl(utils::StringStream& out, +void GeneratorImpl::EmitDiagnosticControl(utils::StringStream& out, const ast::DiagnosticControl& diagnostic) { out << "diagnostic(" << diagnostic.severity << ", " << program_->Symbols().NameFor(diagnostic.rule_name->symbol) << ")"; - return true; } -bool GeneratorImpl::EmitEnable(const ast::Enable* enable) { +void GeneratorImpl::EmitEnable(const ast::Enable* enable) { auto out = line(); out << "enable "; for (auto* ext : enable->extensions) { @@ -108,69 +96,40 @@ bool GeneratorImpl::EmitEnable(const ast::Enable* enable) { out << ext->name; } out << ";"; - return true; } -bool GeneratorImpl::EmitTypeDecl(const ast::TypeDecl* ty) { - return Switch( - ty, - [&](const ast::Alias* alias) { // +void GeneratorImpl::EmitTypeDecl(const ast::TypeDecl* ty) { + Switch( + ty, // + [&](const ast::Alias* alias) { auto out = line(); out << "alias " << program_->Symbols().NameFor(alias->name->symbol) << " = "; - if (!EmitExpression(out, alias->type)) { - return false; - } + EmitExpression(out, alias->type); out << ";"; - return true; }, - [&](const ast::Struct* str) { // - return EmitStructType(str); - }, - [&](Default) { // + [&](const ast::Struct* str) { EmitStructType(str); }, + [&](Default) { diagnostics_.add_error(diag::System::Writer, "unknown declared type: " + std::string(ty->TypeInfo().name)); - return false; }); } -bool GeneratorImpl::EmitExpression(utils::StringStream& out, const ast::Expression* expr) { - return Switch( - expr, - [&](const ast::IndexAccessorExpression* a) { // - return EmitIndexAccessor(out, a); - }, - [&](const ast::BinaryExpression* b) { // - return EmitBinary(out, b); - }, - [&](const ast::BitcastExpression* b) { // - return EmitBitcast(out, b); - }, - [&](const ast::CallExpression* c) { // - return EmitCall(out, c); - }, - [&](const ast::IdentifierExpression* i) { // - return EmitIdentifier(out, i); - }, - [&](const ast::LiteralExpression* l) { // - return EmitLiteral(out, l); - }, - [&](const ast::MemberAccessorExpression* m) { // - return EmitMemberAccessor(out, m); - }, - [&](const ast::PhonyExpression*) { // - out << "_"; - return true; - }, - [&](const ast::UnaryOpExpression* u) { // - return EmitUnaryOp(out, u); - }, - [&](Default) { - diagnostics_.add_error(diag::System::Writer, "unknown expression type"); - return false; - }); +void GeneratorImpl::EmitExpression(utils::StringStream& out, const ast::Expression* expr) { + Switch( + expr, // + [&](const ast::IndexAccessorExpression* a) { EmitIndexAccessor(out, a); }, + [&](const ast::BinaryExpression* b) { EmitBinary(out, b); }, + [&](const ast::BitcastExpression* b) { EmitBitcast(out, b); }, + [&](const ast::CallExpression* c) { EmitCall(out, c); }, + [&](const ast::IdentifierExpression* i) { EmitIdentifier(out, i); }, + [&](const ast::LiteralExpression* l) { EmitLiteral(out, l); }, + [&](const ast::MemberAccessorExpression* m) { EmitMemberAccessor(out, m); }, + [&](const ast::PhonyExpression*) { out << "_"; }, + [&](const ast::UnaryOpExpression* u) { EmitUnaryOp(out, u); }, + [&](Default) { diagnostics_.add_error(diag::System::Writer, "unknown expression type"); }); } -bool GeneratorImpl::EmitIndexAccessor(utils::StringStream& out, +void GeneratorImpl::EmitIndexAccessor(utils::StringStream& out, const ast::IndexAccessorExpression* expr) { bool paren_lhs = !expr->object @@ -178,23 +137,17 @@ bool GeneratorImpl::EmitIndexAccessor(utils::StringStream& out, if (paren_lhs) { out << "("; } - if (!EmitExpression(out, expr->object)) { - return false; - } + EmitExpression(out, expr->object); if (paren_lhs) { out << ")"; } out << "["; - if (!EmitExpression(out, expr->index)) { - return false; - } + EmitExpression(out, expr->index); out << "]"; - - return true; } -bool GeneratorImpl::EmitMemberAccessor(utils::StringStream& out, +void GeneratorImpl::EmitMemberAccessor(utils::StringStream& out, const ast::MemberAccessorExpression* expr) { bool paren_lhs = !expr->object @@ -202,36 +155,25 @@ bool GeneratorImpl::EmitMemberAccessor(utils::StringStream& out, if (paren_lhs) { out << "("; } - if (!EmitExpression(out, expr->object)) { - return false; - } + EmitExpression(out, expr->object); if (paren_lhs) { out << ")"; } out << "." << program_->Symbols().NameFor(expr->member->symbol); - return true; } -bool GeneratorImpl::EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr) { +void GeneratorImpl::EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr) { out << "bitcast<"; - if (!EmitExpression(out, expr->type)) { - return false; - } + EmitExpression(out, expr->type); out << ">("; - if (!EmitExpression(out, expr->expr)) { - return false; - } - + EmitExpression(out, expr->expr); out << ")"; - return true; } -bool GeneratorImpl::EmitCall(utils::StringStream& out, const ast::CallExpression* expr) { - if (!EmitExpression(out, expr->target)) { - return false; - } +void GeneratorImpl::EmitCall(utils::StringStream& out, const ast::CallExpression* expr) { + EmitExpression(out, expr->target); out << "("; bool first = true; @@ -242,24 +184,16 @@ bool GeneratorImpl::EmitCall(utils::StringStream& out, const ast::CallExpression } first = false; - if (!EmitExpression(out, arg)) { - return false; - } + EmitExpression(out, arg); } - out << ")"; - - return true; } -bool GeneratorImpl::EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* lit) { - return Switch( - lit, - [&](const ast::BoolLiteralExpression* l) { // - out << (l->value ? "true" : "false"); - return true; - }, - [&](const ast::FloatLiteralExpression* l) { // +void GeneratorImpl::EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* lit) { + Switch( + lit, // + [&](const ast::BoolLiteralExpression* l) { out << (l->value ? "true" : "false"); }, + [&](const ast::FloatLiteralExpression* l) { // f16 literals are also emitted as float value with suffix "h". // Note that all normal and subnormal f16 values are normal f32 values, and since NaN // and Inf are not allowed to be spelled in literal, it should be fine to emit f16 @@ -269,24 +203,17 @@ bool GeneratorImpl::EmitLiteral(utils::StringStream& out, const ast::LiteralExpr } else { out << FloatToBitPreservingString(static_cast(l->value)) << l->suffix; } - return true; }, - [&](const ast::IntLiteralExpression* l) { // - out << l->value << l->suffix; - return true; - }, - [&](Default) { // - diagnostics_.add_error(diag::System::Writer, "unknown literal type"); - return false; - }); + [&](const ast::IntLiteralExpression* l) { out << l->value << l->suffix; }, + [&](Default) { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); }); } -bool GeneratorImpl::EmitIdentifier(utils::StringStream& out, +void GeneratorImpl::EmitIdentifier(utils::StringStream& out, const ast::IdentifierExpression* expr) { - return EmitIdentifier(out, expr->identifier); + EmitIdentifier(out, expr->identifier); } -bool GeneratorImpl::EmitIdentifier(utils::StringStream& out, const ast::Identifier* ident) { +void GeneratorImpl::EmitIdentifier(utils::StringStream& out, const ast::Identifier* ident) { if (auto* tmpl_ident = ident->As()) { if (!tmpl_ident->attributes.IsEmpty()) { EmitAttributes(out, tmpl_ident->attributes); @@ -298,21 +225,16 @@ bool GeneratorImpl::EmitIdentifier(utils::StringStream& out, const ast::Identifi if (expr != tmpl_ident->arguments.Front()) { out << ", "; } - if (!EmitExpression(out, expr)) { - return false; - } + EmitExpression(out, expr); } } else { out << program_->Symbols().NameFor(ident->symbol); } - return true; } -bool GeneratorImpl::EmitFunction(const ast::Function* func) { +void GeneratorImpl::EmitFunction(const ast::Function* func) { if (func->attributes.Length()) { - if (!EmitAttributes(line(), func->attributes)) { - return false; - } + EmitAttributes(line(), func->attributes); } { auto out = line(); @@ -326,17 +248,13 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { first = false; if (!v->attributes.IsEmpty()) { - if (!EmitAttributes(out, v->attributes)) { - return false; - } + EmitAttributes(out, v->attributes); out << " "; } out << program_->Symbols().NameFor(v->name->symbol) << " : "; - if (!EmitExpression(out, v->type)) { - return false; - } + EmitExpression(out, v->type); } out << ")"; @@ -345,51 +263,39 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { out << " -> "; if (!func->return_type_attributes.IsEmpty()) { - if (!EmitAttributes(out, func->return_type_attributes)) { - return false; - } + EmitAttributes(out, func->return_type_attributes); out << " "; } - if (!EmitExpression(out, func->return_type)) { - return false; - } + EmitExpression(out, func->return_type); } if (func->body) { out << " "; - if (!EmitBlockHeader(out, func->body)) { - return false; - } + EmitBlockHeader(out, func->body); } } if (func->body) { - if (!EmitStatementsWithIndent(func->body->statements)) { - return false; - } + EmitStatementsWithIndent(func->body->statements); line() << "}"; } - - return true; } -bool GeneratorImpl::EmitImageFormat(utils::StringStream& out, const builtin::TexelFormat fmt) { +void GeneratorImpl::EmitImageFormat(utils::StringStream& out, const builtin::TexelFormat fmt) { switch (fmt) { case builtin::TexelFormat::kUndefined: diagnostics_.add_error(diag::System::Writer, "unknown image format"); - return false; + break; default: out << fmt; + break; } - return true; } -bool GeneratorImpl::EmitStructType(const ast::Struct* str) { +void GeneratorImpl::EmitStructType(const ast::Struct* str) { if (str->attributes.Length()) { - if (!EmitAttributes(line(), str->attributes)) { - return false; - } + EmitAttributes(line(), str->attributes); } line() << "struct " << program_->Symbols().NameFor(str->name->symbol) << " {"; @@ -424,9 +330,7 @@ bool GeneratorImpl::EmitStructType(const ast::Struct* str) { if (attr->Is()) { auto l = line(); l << "/* "; - if (!EmitAttributes(l, utils::Vector{attr})) { - return false; - } + EmitAttributes(l, utils::Vector{attr}); l << " */"; } else { attributes_sanitized.Push(attr); @@ -434,92 +338,60 @@ bool GeneratorImpl::EmitStructType(const ast::Struct* str) { } if (!attributes_sanitized.IsEmpty()) { - if (!EmitAttributes(line(), attributes_sanitized)) { - return false; - } + EmitAttributes(line(), attributes_sanitized); } auto out = line(); out << program_->Symbols().NameFor(mem->name->symbol) << " : "; - if (!EmitExpression(out, mem->type)) { - return false; - } + EmitExpression(out, mem->type); out << ","; } decrement_indent(); line() << "}"; - return true; } -bool GeneratorImpl::EmitVariable(utils::StringStream& out, const ast::Variable* v) { +void GeneratorImpl::EmitVariable(utils::StringStream& out, const ast::Variable* v) { if (!v->attributes.IsEmpty()) { - if (!EmitAttributes(out, v->attributes)) { - return false; - } + EmitAttributes(out, v->attributes); out << " "; } - bool ok = Switch( + Switch( v, // [&](const ast::Var* var) { out << "var"; if (var->declared_address_space || var->declared_access) { out << "<"; TINT_DEFER(out << ">"); - if (!EmitExpression(out, var->declared_address_space)) { - return false; - } + EmitExpression(out, var->declared_address_space); if (var->declared_access) { out << ", "; - if (!EmitExpression(out, var->declared_access)) { - return false; - } + EmitExpression(out, var->declared_access); } } - return true; - }, - [&](const ast::Let*) { - out << "let"; - return true; - }, - [&](const ast::Override*) { - out << "override"; - return true; - }, - [&](const ast::Const*) { - out << "const"; - return true; }, + [&](const ast::Let*) { out << "let"; }, [&](const ast::Override*) { out << "override"; }, + [&](const ast::Const*) { out << "const"; }, [&](Default) { TINT_ICE(Writer, diagnostics_) << "unhandled variable type " << v->TypeInfo().name; - return false; }); - if (!ok) { - return false; - } out << " " << program_->Symbols().NameFor(v->name->symbol); if (auto ty = v->type) { out << " : "; - if (!EmitExpression(out, ty)) { - return false; - } + EmitExpression(out, ty); } if (v->initializer != nullptr) { out << " = "; - if (!EmitExpression(out, v->initializer)) { - return false; - } + EmitExpression(out, v->initializer); } out << ";"; - - return true; } -bool GeneratorImpl::EmitAttributes(utils::StringStream& out, +void GeneratorImpl::EmitAttributes(utils::StringStream& out, utils::VectorRef attrs) { bool first = true; for (auto* attr : attrs) { @@ -528,8 +400,8 @@ bool GeneratorImpl::EmitAttributes(utils::StringStream& out, } first = false; out << "@"; - bool ok = Switch( - attr, + Switch( + attr, // [&](const ast::WorkgroupAttribute* workgroup) { auto values = workgroup->Values(); out << "workgroup_size("; @@ -538,150 +410,90 @@ bool GeneratorImpl::EmitAttributes(utils::StringStream& out, if (i > 0) { out << ", "; } - if (!EmitExpression(out, values[i])) { - return false; - } + EmitExpression(out, values[i]); } } out << ")"; - return true; - }, - [&](const ast::StageAttribute* stage) { - out << stage->stage; - return true; }, + [&](const ast::StageAttribute* stage) { out << stage->stage; }, [&](const ast::BindingAttribute* binding) { out << "binding("; - if (!EmitExpression(out, binding->expr)) { - return false; - } + EmitExpression(out, binding->expr); out << ")"; - return true; }, [&](const ast::GroupAttribute* group) { out << "group("; - if (!EmitExpression(out, group->expr)) { - return false; - } + EmitExpression(out, group->expr); out << ")"; - return true; }, [&](const ast::LocationAttribute* location) { out << "location("; - if (!EmitExpression(out, location->expr)) { - return false; - } + EmitExpression(out, location->expr); out << ")"; - return true; }, [&](const ast::BuiltinAttribute* builtin) { out << "builtin("; - if (!EmitExpression(out, builtin->builtin)) { - return false; - } + EmitExpression(out, builtin->builtin); out << ")"; - return true; }, [&](const ast::DiagnosticAttribute* diagnostic) { - return EmitDiagnosticControl(out, diagnostic->control); + EmitDiagnosticControl(out, diagnostic->control); }, [&](const ast::InterpolateAttribute* interpolate) { out << "interpolate("; - if (!EmitExpression(out, interpolate->type)) { - return false; - } + EmitExpression(out, interpolate->type); if (interpolate->sampling) { out << ", "; - if (!EmitExpression(out, interpolate->sampling)) { - return false; - } + EmitExpression(out, interpolate->sampling); } out << ")"; - return true; - }, - [&](const ast::InvariantAttribute*) { - out << "invariant"; - return true; }, + [&](const ast::InvariantAttribute*) { out << "invariant"; }, [&](const ast::IdAttribute* override_deco) { out << "id("; - if (!EmitExpression(out, override_deco->expr)) { - return false; - } + EmitExpression(out, override_deco->expr); out << ")"; - return true; - }, - [&](const ast::MustUseAttribute*) { - out << "must_use"; - return true; }, + [&](const ast::MustUseAttribute*) { out << "must_use"; }, [&](const ast::StructMemberOffsetAttribute* offset) { out << "offset("; - if (!EmitExpression(out, offset->expr)) { - return false; - } + EmitExpression(out, offset->expr); out << ")"; - return true; }, [&](const ast::StructMemberSizeAttribute* size) { out << "size("; - if (!EmitExpression(out, size->expr)) { - return false; - } + EmitExpression(out, size->expr); out << ")"; - return true; }, [&](const ast::StructMemberAlignAttribute* align) { out << "align("; - if (!EmitExpression(out, align->expr)) { - return false; - } + EmitExpression(out, align->expr); out << ")"; - return true; - }, - [&](const ast::StrideAttribute* stride) { - out << "stride(" << stride->stride << ")"; - return true; }, + [&](const ast::StrideAttribute* stride) { out << "stride(" << stride->stride << ")"; }, [&](const ast::InternalAttribute* internal) { out << "internal(" << internal->InternalName() << ")"; - return true; }, [&](Default) { TINT_ICE(Writer, diagnostics_) << "Unsupported attribute '" << attr->TypeInfo().name << "'"; - return false; }); - - if (!ok) { - return false; - } } - - return true; } -bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr) { +void GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr) { out << "("; - if (!EmitExpression(out, expr->lhs)) { - return false; - } + EmitExpression(out, expr->lhs); out << " "; - if (!EmitBinaryOp(out, expr->op)) { - return false; - } + EmitBinaryOp(out, expr->op); out << " "; - if (!EmitExpression(out, expr->rhs)) { - return false; - } - + EmitExpression(out, expr->rhs); out << ")"; - return true; } -bool GeneratorImpl::EmitBinaryOp(utils::StringStream& out, const ast::BinaryOp op) { +void GeneratorImpl::EmitBinaryOp(utils::StringStream& out, const ast::BinaryOp op) { switch (op) { case ast::BinaryOp::kAnd: out << "&"; @@ -739,12 +551,11 @@ bool GeneratorImpl::EmitBinaryOp(utils::StringStream& out, const ast::BinaryOp o break; case ast::BinaryOp::kNone: diagnostics_.add_error(diag::System::Writer, "missing binary operation type"); - return false; + break; } - return true; } -bool GeneratorImpl::EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr) { +void GeneratorImpl::EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr) { switch (expr->op) { case ast::UnaryOp::kAddressOf: out << "&"; @@ -763,131 +574,94 @@ bool GeneratorImpl::EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpr break; } out << "("; - - if (!EmitExpression(out, expr->expr)) { - return false; - } - + EmitExpression(out, expr->expr); out << ")"; - - return true; } -bool GeneratorImpl::EmitBlock(const ast::BlockStatement* stmt) { +void GeneratorImpl::EmitBlock(const ast::BlockStatement* stmt) { { auto out = line(); - if (!EmitBlockHeader(out, stmt)) { - return false; - } - } - if (!EmitStatementsWithIndent(stmt->statements)) { - return false; + EmitBlockHeader(out, stmt); } + EmitStatementsWithIndent(stmt->statements); line() << "}"; - - return true; } -bool GeneratorImpl::EmitBlockHeader(utils::StringStream& out, const ast::BlockStatement* stmt) { +void GeneratorImpl::EmitBlockHeader(utils::StringStream& out, const ast::BlockStatement* stmt) { if (!stmt->attributes.IsEmpty()) { - if (!EmitAttributes(out, stmt->attributes)) { - return false; - } + EmitAttributes(out, stmt->attributes); out << " "; } out << "{"; - return true; } -bool GeneratorImpl::EmitStatement(const ast::Statement* stmt) { - return Switch( +void GeneratorImpl::EmitStatement(const ast::Statement* stmt) { + Switch( stmt, // - [&](const ast::AssignmentStatement* a) { return EmitAssign(a); }, - [&](const ast::BlockStatement* b) { return EmitBlock(b); }, - [&](const ast::BreakStatement* b) { return EmitBreak(b); }, - [&](const ast::BreakIfStatement* b) { return EmitBreakIf(b); }, + [&](const ast::AssignmentStatement* a) { EmitAssign(a); }, + [&](const ast::BlockStatement* b) { EmitBlock(b); }, + [&](const ast::BreakStatement* b) { EmitBreak(b); }, + [&](const ast::BreakIfStatement* b) { EmitBreakIf(b); }, [&](const ast::CallStatement* c) { auto out = line(); - if (!EmitCall(out, c->expr)) { - return false; - } + EmitCall(out, c->expr); out << ";"; - return true; }, - [&](const ast::CompoundAssignmentStatement* c) { return EmitCompoundAssign(c); }, - [&](const ast::ContinueStatement* c) { return EmitContinue(c); }, - [&](const ast::DiscardStatement* d) { return EmitDiscard(d); }, - [&](const ast::IfStatement* i) { return EmitIf(i); }, - [&](const ast::IncrementDecrementStatement* l) { return EmitIncrementDecrement(l); }, - [&](const ast::LoopStatement* l) { return EmitLoop(l); }, - [&](const ast::ForLoopStatement* l) { return EmitForLoop(l); }, - [&](const ast::WhileStatement* l) { return EmitWhile(l); }, - [&](const ast::ReturnStatement* r) { return EmitReturn(r); }, - [&](const ast::ConstAssert* c) { return EmitConstAssert(c); }, - [&](const ast::SwitchStatement* s) { return EmitSwitch(s); }, - [&](const ast::VariableDeclStatement* v) { return EmitVariable(line(), v->variable); }, + [&](const ast::CompoundAssignmentStatement* c) { EmitCompoundAssign(c); }, + [&](const ast::ContinueStatement* c) { EmitContinue(c); }, + [&](const ast::DiscardStatement* d) { EmitDiscard(d); }, + [&](const ast::IfStatement* i) { EmitIf(i); }, + [&](const ast::IncrementDecrementStatement* l) { EmitIncrementDecrement(l); }, + [&](const ast::LoopStatement* l) { EmitLoop(l); }, + [&](const ast::ForLoopStatement* l) { EmitForLoop(l); }, + [&](const ast::WhileStatement* l) { EmitWhile(l); }, + [&](const ast::ReturnStatement* r) { EmitReturn(r); }, + [&](const ast::ConstAssert* c) { EmitConstAssert(c); }, + [&](const ast::SwitchStatement* s) { EmitSwitch(s); }, + [&](const ast::VariableDeclStatement* v) { EmitVariable(line(), v->variable); }, [&](Default) { diagnostics_.add_error(diag::System::Writer, "unknown statement type: " + std::string(stmt->TypeInfo().name)); - return false; }); } -bool GeneratorImpl::EmitStatements(utils::VectorRef stmts) { +void GeneratorImpl::EmitStatements(utils::VectorRef stmts) { for (auto* s : stmts) { - if (!EmitStatement(s)) { - return false; - } + EmitStatement(s); } - return true; } -bool GeneratorImpl::EmitStatementsWithIndent(utils::VectorRef stmts) { +void GeneratorImpl::EmitStatementsWithIndent(utils::VectorRef stmts) { ScopedIndent si(this); - return EmitStatements(stmts); + EmitStatements(stmts); } -bool GeneratorImpl::EmitAssign(const ast::AssignmentStatement* stmt) { +void GeneratorImpl::EmitAssign(const ast::AssignmentStatement* stmt) { auto out = line(); - if (!EmitExpression(out, stmt->lhs)) { - return false; - } - + EmitExpression(out, stmt->lhs); out << " = "; - - if (!EmitExpression(out, stmt->rhs)) { - return false; - } - + EmitExpression(out, stmt->rhs); out << ";"; - - return true; } -bool GeneratorImpl::EmitBreak(const ast::BreakStatement*) { +void GeneratorImpl::EmitBreak(const ast::BreakStatement*) { line() << "break;"; - return true; } -bool GeneratorImpl::EmitBreakIf(const ast::BreakIfStatement* b) { +void GeneratorImpl::EmitBreakIf(const ast::BreakIfStatement* b) { auto out = line(); out << "break if "; - if (!EmitExpression(out, b->condition)) { - return false; - } + EmitExpression(out, b->condition); out << ";"; - return true; } -bool GeneratorImpl::EmitCase(const ast::CaseStatement* stmt) { +void GeneratorImpl::EmitCase(const ast::CaseStatement* stmt) { if (stmt->selectors.Length() == 1 && stmt->ContainsDefault()) { auto out = line(); out << "default: "; - if (!EmitBlockHeader(out, stmt->body)) { - return false; - } + EmitBlockHeader(out, stmt->body); } else { auto out = line(); out << "case "; @@ -902,74 +676,48 @@ bool GeneratorImpl::EmitCase(const ast::CaseStatement* stmt) { if (sel->IsDefault()) { out << "default"; - } else if (!EmitExpression(out, sel->expr)) { - return false; + } else { + EmitExpression(out, sel->expr); } } out << ": "; - if (!EmitBlockHeader(out, stmt->body)) { - return false; - } + EmitBlockHeader(out, stmt->body); } - if (!EmitStatementsWithIndent(stmt->body->statements)) { - return false; - } - + EmitStatementsWithIndent(stmt->body->statements); line() << "}"; - return true; } -bool GeneratorImpl::EmitCompoundAssign(const ast::CompoundAssignmentStatement* stmt) { +void GeneratorImpl::EmitCompoundAssign(const ast::CompoundAssignmentStatement* stmt) { auto out = line(); - if (!EmitExpression(out, stmt->lhs)) { - return false; - } - + EmitExpression(out, stmt->lhs); out << " "; - if (!EmitBinaryOp(out, stmt->op)) { - return false; - } + EmitBinaryOp(out, stmt->op); out << "= "; - - if (!EmitExpression(out, stmt->rhs)) { - return false; - } - + EmitExpression(out, stmt->rhs); out << ";"; - - return true; } -bool GeneratorImpl::EmitContinue(const ast::ContinueStatement*) { +void GeneratorImpl::EmitContinue(const ast::ContinueStatement*) { line() << "continue;"; - return true; } -bool GeneratorImpl::EmitIf(const ast::IfStatement* stmt) { +void GeneratorImpl::EmitIf(const ast::IfStatement* stmt) { { auto out = line(); if (!stmt->attributes.IsEmpty()) { - if (!EmitAttributes(out, stmt->attributes)) { - return false; - } + EmitAttributes(out, stmt->attributes); out << " "; } out << "if ("; - if (!EmitExpression(out, stmt->condition)) { - return false; - } + EmitExpression(out, stmt->condition); out << ") "; - if (!EmitBlockHeader(out, stmt->body)) { - return false; - } + EmitBlockHeader(out, stmt->body); } - if (!EmitStatementsWithIndent(stmt->body->statements)) { - return false; - } + EmitStatementsWithIndent(stmt->body->statements); const ast::Statement* e = stmt->else_statement; while (e) { @@ -977,74 +725,52 @@ bool GeneratorImpl::EmitIf(const ast::IfStatement* stmt) { { auto out = line(); out << "} else if ("; - if (!EmitExpression(out, elseif->condition)) { - return false; - } + EmitExpression(out, elseif->condition); out << ") "; - if (!EmitBlockHeader(out, elseif->body)) { - return false; - } - } - if (!EmitStatementsWithIndent(elseif->body->statements)) { - return false; + EmitBlockHeader(out, elseif->body); } + EmitStatementsWithIndent(elseif->body->statements); e = elseif->else_statement; } else { auto* body = e->As(); { auto out = line(); out << "} else "; - if (!EmitBlockHeader(out, body)) { - return false; - } - } - if (!EmitStatementsWithIndent(body->statements)) { - return false; + EmitBlockHeader(out, body); } + EmitStatementsWithIndent(body->statements); break; } } line() << "}"; - - return true; } -bool GeneratorImpl::EmitIncrementDecrement(const ast::IncrementDecrementStatement* stmt) { +void GeneratorImpl::EmitIncrementDecrement(const ast::IncrementDecrementStatement* stmt) { auto out = line(); - if (!EmitExpression(out, stmt->lhs)) { - return false; - } + EmitExpression(out, stmt->lhs); out << (stmt->increment ? "++" : "--") << ";"; - return true; } -bool GeneratorImpl::EmitDiscard(const ast::DiscardStatement*) { +void GeneratorImpl::EmitDiscard(const ast::DiscardStatement*) { line() << "discard;"; - return true; } -bool GeneratorImpl::EmitLoop(const ast::LoopStatement* stmt) { +void GeneratorImpl::EmitLoop(const ast::LoopStatement* stmt) { { auto out = line(); if (!stmt->attributes.IsEmpty()) { - if (!EmitAttributes(out, stmt->attributes)) { - return false; - } + EmitAttributes(out, stmt->attributes); out << " "; } out << "loop "; - if (!EmitBlockHeader(out, stmt->body)) { - return false; - } + EmitBlockHeader(out, stmt->body); } increment_indent(); - if (!EmitStatements(stmt->body->statements)) { - return false; - } + EmitStatements(stmt->body->statements); if (stmt->continuing && !stmt->continuing->Empty()) { line(); @@ -1052,49 +778,37 @@ bool GeneratorImpl::EmitLoop(const ast::LoopStatement* stmt) { auto out = line(); out << "continuing "; if (!stmt->continuing->attributes.IsEmpty()) { - if (!EmitAttributes(out, stmt->continuing->attributes)) { - return false; - } + EmitAttributes(out, stmt->continuing->attributes); out << " "; } out << "{"; } - if (!EmitStatementsWithIndent(stmt->continuing->statements)) { - return false; - } + EmitStatementsWithIndent(stmt->continuing->statements); line() << "}"; } decrement_indent(); line() << "}"; - - return true; } -bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { +void GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { TextBuffer init_buf; if (auto* init = stmt->initializer) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &init_buf); - if (!EmitStatement(init)) { - return false; - } + EmitStatement(init); } TextBuffer cont_buf; if (auto* cont = stmt->continuing) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cont_buf); - if (!EmitStatement(cont)) { - return false; - } + EmitStatement(cont); } { auto out = line(); if (!stmt->attributes.IsEmpty()) { - if (!EmitAttributes(out, stmt->attributes)) { - return false; - } + EmitAttributes(out, stmt->attributes); out << " "; } @@ -1119,9 +833,7 @@ bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { out << "; "; if (auto* cond = stmt->condition) { - if (!EmitExpression(out, cond)) { - return false; - } + EmitExpression(out, cond); } out << "; "; @@ -1142,28 +854,20 @@ bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { } } out << " "; - if (!EmitBlockHeader(out, stmt->body)) { - return false; - } + EmitBlockHeader(out, stmt->body); } - if (!EmitStatementsWithIndent(stmt->body->statements)) { - return false; - } + EmitStatementsWithIndent(stmt->body->statements); line() << "}"; - - return true; } -bool GeneratorImpl::EmitWhile(const ast::WhileStatement* stmt) { +void GeneratorImpl::EmitWhile(const ast::WhileStatement* stmt) { { auto out = line(); if (!stmt->attributes.IsEmpty()) { - if (!EmitAttributes(out, stmt->attributes)) { - return false; - } + EmitAttributes(out, stmt->attributes); out << " "; } @@ -1172,69 +876,50 @@ bool GeneratorImpl::EmitWhile(const ast::WhileStatement* stmt) { ScopedParen sp(out); auto* cond = stmt->condition; - if (!EmitExpression(out, cond)) { - return false; - } + EmitExpression(out, cond); } out << " "; - if (!EmitBlockHeader(out, stmt->body)) { - return false; - } + EmitBlockHeader(out, stmt->body); } - if (!EmitStatementsWithIndent(stmt->body->statements)) { - return false; - } + EmitStatementsWithIndent(stmt->body->statements); line() << "}"; - - return true; } -bool GeneratorImpl::EmitReturn(const ast::ReturnStatement* stmt) { +void GeneratorImpl::EmitReturn(const ast::ReturnStatement* stmt) { auto out = line(); + out << "return"; if (stmt->value) { out << " "; - if (!EmitExpression(out, stmt->value)) { - return false; - } + EmitExpression(out, stmt->value); } out << ";"; - return true; } -bool GeneratorImpl::EmitConstAssert(const ast::ConstAssert* stmt) { +void GeneratorImpl::EmitConstAssert(const ast::ConstAssert* stmt) { auto out = line(); out << "const_assert "; - if (!EmitExpression(out, stmt->condition)) { - return false; - } + EmitExpression(out, stmt->condition); out << ";"; - return true; } -bool GeneratorImpl::EmitSwitch(const ast::SwitchStatement* stmt) { +void GeneratorImpl::EmitSwitch(const ast::SwitchStatement* stmt) { { auto out = line(); if (!stmt->attributes.IsEmpty()) { - if (!EmitAttributes(out, stmt->attributes)) { - return false; - } + EmitAttributes(out, stmt->attributes); out << " "; } out << "switch("; - if (!EmitExpression(out, stmt->condition)) { - return false; - } + EmitExpression(out, stmt->condition); out << ") "; if (!stmt->body_attributes.IsEmpty()) { - if (!EmitAttributes(out, stmt->body_attributes)) { - return false; - } + EmitAttributes(out, stmt->body_attributes); out << " "; } @@ -1244,14 +929,11 @@ bool GeneratorImpl::EmitSwitch(const ast::SwitchStatement* stmt) { { ScopedIndent si(this); for (auto* s : stmt->body) { - if (!EmitCase(s)) { - return false; - } + EmitCase(s); } } line() << "}"; - return true; } } // namespace tint::writer::wgsl diff --git a/src/tint/writer/wgsl/generator_impl.h b/src/tint/writer/wgsl/generator_impl.h index c72d95edcd..5d69821b2e 100644 --- a/src/tint/writer/wgsl/generator_impl.h +++ b/src/tint/writer/wgsl/generator_impl.h @@ -49,181 +49,141 @@ class GeneratorImpl : public TextGenerator { ~GeneratorImpl(); /// Generates the result data - /// @returns true on successful generation; false otherwise - bool Generate(); + void Generate(); /// Handles generating a diagnostic control /// @param out the output stream /// @param diagnostic the diagnostic control node - /// @returns true if the diagnostic control was emitted - bool EmitDiagnosticControl(utils::StringStream& out, const ast::DiagnosticControl& diagnostic); + void EmitDiagnosticControl(utils::StringStream& out, const ast::DiagnosticControl& diagnostic); /// Handles generating an enable directive /// @param enable the enable node - /// @returns true if the enable directive was emitted - bool EmitEnable(const ast::Enable* enable); + void EmitEnable(const ast::Enable* enable); /// Handles generating a declared type /// @param ty the declared type to generate - /// @returns true if the declared type was emitted - bool EmitTypeDecl(const ast::TypeDecl* ty); + void EmitTypeDecl(const ast::TypeDecl* ty); /// Handles an index accessor expression /// @param out the output stream /// @param expr the expression to emit - /// @returns true if the index accessor was emitted - bool EmitIndexAccessor(utils::StringStream& out, const ast::IndexAccessorExpression* expr); + void EmitIndexAccessor(utils::StringStream& out, const ast::IndexAccessorExpression* expr); /// Handles an assignment statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitAssign(const ast::AssignmentStatement* stmt); + void EmitAssign(const ast::AssignmentStatement* stmt); /// Handles generating a binary expression /// @param out the output stream /// @param expr the binary expression - /// @returns true if the expression was emitted, false otherwise - bool EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr); + void EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr); /// Handles generating a binary operator /// @param out the output stream /// @param op the binary operator - /// @returns true if the operator was emitted, false otherwise - bool EmitBinaryOp(utils::StringStream& out, const ast::BinaryOp op); + void EmitBinaryOp(utils::StringStream& out, const ast::BinaryOp op); /// Handles generating a bitcast expression /// @param out the output stream /// @param expr the bitcast expression - /// @returns true if the bitcast was emitted - bool EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr); + void EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr); /// Handles a block statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitBlock(const ast::BlockStatement* stmt); + void EmitBlock(const ast::BlockStatement* stmt); /// Handles emitting the start of a block statement (including attributes) /// @param out the output stream to write the header to /// @param stmt the block statement to emit the header for - /// @returns true if the statement was emitted successfully - bool EmitBlockHeader(utils::StringStream& out, const ast::BlockStatement* stmt); + void EmitBlockHeader(utils::StringStream& out, const ast::BlockStatement* stmt); /// Handles a break statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitBreak(const ast::BreakStatement* stmt); + void EmitBreak(const ast::BreakStatement* stmt); /// Handles a break-if statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitBreakIf(const ast::BreakIfStatement* stmt); + void EmitBreakIf(const ast::BreakIfStatement* stmt); /// Handles generating a call expression /// @param out the output stream /// @param expr the call expression - /// @returns true if the call expression is emitted - bool EmitCall(utils::StringStream& out, const ast::CallExpression* expr); + void EmitCall(utils::StringStream& out, const ast::CallExpression* expr); /// Handles a case statement /// @param stmt the statement - /// @returns true if the statment was emitted successfully - bool EmitCase(const ast::CaseStatement* stmt); + void EmitCase(const ast::CaseStatement* stmt); /// Handles a compound assignment statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitCompoundAssign(const ast::CompoundAssignmentStatement* stmt); + void EmitCompoundAssign(const ast::CompoundAssignmentStatement* stmt); /// Handles generating a literal expression /// @param out the output stream /// @param expr the literal expression expression - /// @returns true if the literal expression is emitted - bool EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* expr); + void EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* expr); /// Handles a continue statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitContinue(const ast::ContinueStatement* stmt); + void EmitContinue(const ast::ContinueStatement* stmt); /// Handles generate an Expression /// @param out the output stream /// @param expr the expression - /// @returns true if the expression was emitted - bool EmitExpression(utils::StringStream& out, const ast::Expression* expr); + void EmitExpression(utils::StringStream& out, const ast::Expression* expr); /// Handles generating a function /// @param func the function to generate - /// @returns true if the function was emitted - bool EmitFunction(const ast::Function* func); + void EmitFunction(const ast::Function* func); /// Handles generating an identifier expression /// @param out the output stream /// @param expr the identifier expression - /// @returns true if the identifier was emitted - bool EmitIdentifier(utils::StringStream& out, const ast::IdentifierExpression* expr); + void EmitIdentifier(utils::StringStream& out, const ast::IdentifierExpression* expr); /// Handles generating an identifier /// @param out the output of the expression stream /// @param ident the identifier - /// @returns true if the identifier was emitted - bool EmitIdentifier(utils::StringStream& out, const ast::Identifier* ident); + void EmitIdentifier(utils::StringStream& out, const ast::Identifier* ident); /// Handles an if statement /// @param stmt the statement to emit - /// @returns true if the statement was successfully emitted - bool EmitIf(const ast::IfStatement* stmt); + void EmitIf(const ast::IfStatement* stmt); /// Handles an increment/decrement statement /// @param stmt the statement to emit - /// @returns true if the statement was successfully emitted - bool EmitIncrementDecrement(const ast::IncrementDecrementStatement* stmt); + void EmitIncrementDecrement(const ast::IncrementDecrementStatement* stmt); /// Handles generating a discard statement /// @param stmt the discard statement - /// @returns true if the statement was successfully emitted - bool EmitDiscard(const ast::DiscardStatement* stmt); + void EmitDiscard(const ast::DiscardStatement* stmt); /// Handles a loop statement /// @param stmt the statement to emit - /// @returns true if the statement was emtited - bool EmitLoop(const ast::LoopStatement* stmt); + void EmitLoop(const ast::LoopStatement* stmt); /// Handles a for-loop statement /// @param stmt the statement to emit - /// @returns true if the statement was emtited - bool EmitForLoop(const ast::ForLoopStatement* stmt); + void EmitForLoop(const ast::ForLoopStatement* stmt); /// Handles a while statement /// @param stmt the statement to emit - /// @returns true if the statement was emtited - bool EmitWhile(const ast::WhileStatement* stmt); + void EmitWhile(const ast::WhileStatement* stmt); /// Handles a member accessor expression /// @param out the output stream /// @param expr the member accessor expression - /// @returns true if the member accessor was emitted - bool EmitMemberAccessor(utils::StringStream& out, const ast::MemberAccessorExpression* expr); + void EmitMemberAccessor(utils::StringStream& out, const ast::MemberAccessorExpression* expr); /// Handles return statements /// @param stmt the statement to emit - /// @returns true if the statement was successfully emitted - bool EmitReturn(const ast::ReturnStatement* stmt); + void EmitReturn(const ast::ReturnStatement* stmt); /// Handles const assertion statements /// @param stmt the statement to emit - /// @returns true if the statement was successfully emitted - bool EmitConstAssert(const ast::ConstAssert* stmt); + void EmitConstAssert(const ast::ConstAssert* stmt); /// Handles statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted - bool EmitStatement(const ast::Statement* stmt); + void EmitStatement(const ast::Statement* stmt); /// Handles a statement list /// @param stmts the statements to emit - /// @returns true if the statements were emitted - bool EmitStatements(utils::VectorRef stmts); + void EmitStatements(utils::VectorRef stmts); /// Handles a statement list with an increased indentation /// @param stmts the statements to emit - /// @returns true if the statements were emitted - bool EmitStatementsWithIndent(utils::VectorRef stmts); + void EmitStatementsWithIndent(utils::VectorRef stmts); /// Handles generating a switch statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted - bool EmitSwitch(const ast::SwitchStatement* stmt); + void EmitSwitch(const ast::SwitchStatement* stmt); /// Handles generating a struct declaration /// @param str the struct - /// @returns true if the struct is emitted - bool EmitStructType(const ast::Struct* str); + void EmitStructType(const ast::Struct* str); /// Handles emitting an image format /// @param out the output stream /// @param fmt the format to generate - /// @returns true if the format is emitted - bool EmitImageFormat(utils::StringStream& out, const builtin::TexelFormat fmt); + void EmitImageFormat(utils::StringStream& out, const builtin::TexelFormat fmt); /// Handles a unary op expression /// @param out the output stream /// @param expr the expression to emit - /// @returns true if the expression was emitted - bool EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr); + void EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr); /// Handles generating a variable /// @param out the output stream /// @param var the variable to generate - /// @returns true if the variable was emitted - bool EmitVariable(utils::StringStream& out, const ast::Variable* var); + void EmitVariable(utils::StringStream& out, const ast::Variable* var); /// Handles generating a attribute list /// @param out the output stream /// @param attrs the attribute list - /// @returns true if the attributes were emitted - bool EmitAttributes(utils::StringStream& out, utils::VectorRef attrs); + void EmitAttributes(utils::StringStream& out, utils::VectorRef attrs); }; } // namespace tint::writer::wgsl diff --git a/src/tint/writer/wgsl/generator_impl_alias_type_test.cc b/src/tint/writer/wgsl/generator_impl_alias_type_test.cc index 71bbc59ada..9c7614847b 100644 --- a/src/tint/writer/wgsl/generator_impl_alias_type_test.cc +++ b/src/tint/writer/wgsl/generator_impl_alias_type_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -23,8 +25,9 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_F32) { auto* alias = Alias("a", ty.f32()); 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; )"); } @@ -38,9 +41,11 @@ TEST_F(WgslGeneratorImplTest, EmitTypeDecl_Struct) { auto* alias = Alias("B", ty.Of(s)); GeneratorImpl& gen = Build(); + gen.EmitTypeDecl(s); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); - ASSERT_TRUE(gen.EmitTypeDecl(s)) << gen.Diagnostics(); - ASSERT_TRUE(gen.EmitTypeDecl(alias)) << gen.Diagnostics(); + gen.EmitTypeDecl(alias); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(struct A { a : f32, b : i32, @@ -59,7 +64,8 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_ToStruct) { 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; )"); } diff --git a/src/tint/writer/wgsl/generator_impl_array_accessor_test.cc b/src/tint/writer/wgsl/generator_impl_array_accessor_test.cc index b262ee838d..d24a1a72db 100644 --- a/src/tint/writer/wgsl/generator_impl_array_accessor_test.cc +++ b/src/tint/writer/wgsl/generator_impl_array_accessor_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -30,7 +32,8 @@ TEST_F(WgslGeneratorImplTest, IndexAccessor) { GeneratorImpl& gen = Build(); 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]"); } @@ -44,7 +47,8 @@ TEST_F(WgslGeneratorImplTest, IndexAccessor_OfDref) { GeneratorImpl& gen = Build(); 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]"); } diff --git a/src/tint/writer/wgsl/generator_impl_assign_test.cc b/src/tint/writer/wgsl/generator_impl_assign_test.cc index 0c9ed678ab..5d7ab238a3 100644 --- a/src/tint/writer/wgsl/generator_impl_assign_test.cc +++ b/src/tint/writer/wgsl/generator_impl_assign_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Assign) { 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"); } diff --git a/src/tint/writer/wgsl/generator_impl_binary_test.cc b/src/tint/writer/wgsl/generator_impl_binary_test.cc index ae8fdfb177..1829cf8445 100644 --- a/src/tint/writer/wgsl/generator_impl_binary_test.cc +++ b/src/tint/writer/wgsl/generator_impl_binary_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -51,7 +53,8 @@ TEST_P(WgslBinaryTest, Emit) { GeneratorImpl& gen = Build(); 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); } INSTANTIATE_TEST_SUITE_P( diff --git a/src/tint/writer/wgsl/generator_impl_bitcast_test.cc b/src/tint/writer/wgsl/generator_impl_bitcast_test.cc index 68442816e6..18c2f6de94 100644 --- a/src/tint/writer/wgsl/generator_impl_bitcast_test.cc +++ b/src/tint/writer/wgsl/generator_impl_bitcast_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Bitcast) { GeneratorImpl& gen = Build(); 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(1i)"); } diff --git a/src/tint/writer/wgsl/generator_impl_block_test.cc b/src/tint/writer/wgsl/generator_impl_block_test.cc index ca0b76ce6e..d5af3039dd 100644 --- a/src/tint/writer/wgsl/generator_impl_block_test.cc +++ b/src/tint/writer/wgsl/generator_impl_block_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -27,7 +29,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Block) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitStatement(b)) << gen.Diagnostics(); + gen.EmitStatement(b); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { return; } diff --git a/src/tint/writer/wgsl/generator_impl_break_test.cc b/src/tint/writer/wgsl/generator_impl_break_test.cc index cba2456954..d60cef475f 100644 --- a/src/tint/writer/wgsl/generator_impl_break_test.cc +++ b/src/tint/writer/wgsl/generator_impl_break_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -27,7 +29,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Break) { 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"); } diff --git a/src/tint/writer/wgsl/generator_impl_call_test.cc b/src/tint/writer/wgsl/generator_impl_call_test.cc index e0ebf11fec..5cb8eac021 100644 --- a/src/tint/writer/wgsl/generator_impl_call_test.cc +++ b/src/tint/writer/wgsl/generator_impl_call_test.cc @@ -16,6 +16,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -35,7 +37,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Call_WithoutParams) { GeneratorImpl& gen = Build(); 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()"); } @@ -58,7 +61,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Call_WithParams) { GeneratorImpl& gen = Build(); 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)"); } @@ -79,7 +83,8 @@ TEST_F(WgslGeneratorImplTest, EmitStatement_Call) { GeneratorImpl& gen = Build(); 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"); } diff --git a/src/tint/writer/wgsl/generator_impl_case_test.cc b/src/tint/writer/wgsl/generator_impl_case_test.cc index 8e8b90e044..05b0d9ed21 100644 --- a/src/tint/writer/wgsl/generator_impl_case_test.cc +++ b/src/tint/writer/wgsl/generator_impl_case_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -30,7 +32,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Case) { 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: { break; } @@ -52,7 +55,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) { 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: { break; } @@ -67,7 +71,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_Default) { 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: { break; } diff --git a/src/tint/writer/wgsl/generator_impl_cast_test.cc b/src/tint/writer/wgsl/generator_impl_cast_test.cc index 79e9047623..890c52c655 100644 --- a/src/tint/writer/wgsl/generator_impl_cast_test.cc +++ b/src/tint/writer/wgsl/generator_impl_cast_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Cast_Scalar_F32_From_I32) { GeneratorImpl& gen = Build(); 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)"); } @@ -42,7 +45,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Cast_Scalar_F16_From_I32) { GeneratorImpl& gen = Build(); 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)"); } @@ -53,7 +57,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Cast_Vector_F32_From_I32) { GeneratorImpl& gen = Build(); 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(vec3(1i, 2i, 3i))"); } @@ -66,7 +71,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_Cast_Vector_F16_From_I32) { GeneratorImpl& gen = Build(); 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(vec3(1i, 2i, 3i))"); } diff --git a/src/tint/writer/wgsl/generator_impl_const_assert_test.cc b/src/tint/writer/wgsl/generator_impl_const_assert_test.cc index c13ac6f2bb..d3f22efdc5 100644 --- a/src/tint/writer/wgsl/generator_impl_const_assert_test.cc +++ b/src/tint/writer/wgsl/generator_impl_const_assert_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -25,8 +27,8 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalConstAssert) { GlobalConstAssert(true); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); 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)}); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const_assert true; } diff --git a/src/tint/writer/wgsl/generator_impl_constructor_test.cc b/src/tint/writer/wgsl/generator_impl_constructor_test.cc index cdc7bdc990..fa40ff6bb0 100644 --- a/src/tint/writer/wgsl/generator_impl_constructor_test.cc +++ b/src/tint/writer/wgsl/generator_impl_constructor_test.cc @@ -12,9 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gmock/gmock.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using ::testing::HasSubstr; using namespace tint::number_suffixes; // NOLINT @@ -28,8 +29,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Bool) { WrapInFunction(Expr(false)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("false")); } @@ -37,8 +38,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Int) { WrapInFunction(Expr(-12345_i)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("-12345")); } @@ -46,8 +47,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, UInt) { WrapInFunction(Expr(56779_u)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("56779u")); } @@ -57,7 +58,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, F32) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("1073741824.0f")); } @@ -69,7 +71,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, F16) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("32752.0h")); } @@ -78,7 +81,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_F32) { 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)")); } @@ -89,7 +93,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_F16) { 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)")); } @@ -98,7 +103,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Bool) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("bool(true)")); } @@ -107,7 +113,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Int) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("i32(-12345i)")); } @@ -116,7 +123,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Uint) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("u32(12345u)")); } @@ -125,7 +133,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Vec_F32) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("vec3(1.0f, 2.0f, 3.0f)")); } @@ -136,7 +145,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Vec_F16) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("vec3(1.0h, 2.0h, 3.0h)")); } @@ -145,7 +155,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Mat_F32) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("mat2x3(vec3(1.0f, 2.0f, 3.0f), " "vec3(3.0f, 4.0f, 5.0f))")); } @@ -157,7 +168,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Mat_F16) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("mat2x3(vec3(1.0h, 2.0h, 3.0h), " "vec3(3.0h, 4.0h, 5.0h))")); } @@ -168,7 +180,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_Array) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("array, 3u>(vec3(1.0f, 2.0f, 3.0f), " "vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f))")); @@ -180,7 +193,8 @@ TEST_F(WgslGeneratorImplTest_Constructor, Type_ImplicitArray) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("array(vec3(1.0f, 2.0f, 3.0f), " "vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f))")); diff --git a/src/tint/writer/wgsl/generator_impl_continue_test.cc b/src/tint/writer/wgsl/generator_impl_continue_test.cc index 46201ab7e5..e1b9056639 100644 --- a/src/tint/writer/wgsl/generator_impl_continue_test.cc +++ b/src/tint/writer/wgsl/generator_impl_continue_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Continue) { 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"); } diff --git a/src/tint/writer/wgsl/generator_impl_diagnostic_test.cc b/src/tint/writer/wgsl/generator_impl_diagnostic_test.cc index 301bff4945..2a2f4b63b9 100644 --- a/src/tint/writer/wgsl/generator_impl_diagnostic_test.cc +++ b/src/tint/writer/wgsl/generator_impl_diagnostic_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -23,8 +25,8 @@ TEST_F(WgslGeneratorImplTest, Emit_DiagnosticDirective) { DiagnosticDirective(builtin::DiagnosticSeverity::kError, "chromium_unreachable_code"); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); 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}); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(@diagnostic(error, chromium_unreachable_code) fn foo() { } diff --git a/src/tint/writer/wgsl/generator_impl_discard_test.cc b/src/tint/writer/wgsl/generator_impl_discard_test.cc index a1167a8a7d..4a5ae25bd3 100644 --- a/src/tint/writer/wgsl/generator_impl_discard_test.cc +++ b/src/tint/writer/wgsl/generator_impl_discard_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Discard) { 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"); } diff --git a/src/tint/writer/wgsl/generator_impl_enable_test.cc b/src/tint/writer/wgsl/generator_impl_enable_test.cc index 739d893ad0..34d1614e5b 100644 --- a/src/tint/writer/wgsl/generator_impl_enable_test.cc +++ b/src/tint/writer/wgsl/generator_impl_enable_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -24,7 +26,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Enable) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.EmitEnable(enable)); + gen.EmitEnable(enable); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(enable f16; )"); } diff --git a/src/tint/writer/wgsl/generator_impl_function_test.cc b/src/tint/writer/wgsl/generator_impl_function_test.cc index 6cf270677f..14de0c25dd 100644 --- a/src/tint/writer/wgsl/generator_impl_function_test.cc +++ b/src/tint/writer/wgsl/generator_impl_function_test.cc @@ -18,6 +18,8 @@ #include "src/tint/builtin/builtin_value.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -34,8 +36,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitFunction(func)); + gen.EmitFunction(func); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( fn my_func() { return; } @@ -56,8 +58,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitFunction(func)); + gen.EmitFunction(func); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( fn my_func(a : f32, b : i32) { return; } @@ -77,8 +79,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithAttribute_WorkgroupSize) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitFunction(func)); + gen.EmitFunction(func); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( @compute @workgroup_size(2i, 4i, 6i) fn my_func() { return; @@ -98,8 +100,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithAttribute_MustUse) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitFunction(func)); + gen.EmitFunction(func); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( @must_use fn my_func() -> i32 { return 1i; @@ -121,8 +123,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithAttribute_WorkgroupSize_WithIden GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitFunction(func)); + gen.EmitFunction(func); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( @compute @workgroup_size(2i, height) fn my_func() { return; @@ -148,8 +150,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitFunction(func)); + gen.EmitFunction(func); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( @fragment fn frag_main(@builtin(position) coord : vec4, @location(1) loc1 : f32) { } @@ -171,8 +173,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_ReturnValue) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitFunction(func)); + gen.EmitFunction(func); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( @fragment fn frag_main() -> @location(1) f32 { return 1.0f; @@ -234,7 +236,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_Multiple_EntryPoint_With_Same_Module GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(struct Data { d : f32, } diff --git a/src/tint/writer/wgsl/generator_impl_global_decl_test.cc b/src/tint/writer/wgsl/generator_impl_global_decl_test.cc index 1428d44ea8..9d97f85ebc 100644 --- a/src/tint/writer/wgsl/generator_impl_global_decl_test.cc +++ b/src/tint/writer/wgsl/generator_impl_global_decl_test.cc @@ -18,6 +18,8 @@ #include "src/tint/type/texture_dimension.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -34,8 +36,8 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalDeclAfterFunction) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( @compute @workgroup_size(1i, 1i, 1i) fn test_function() { var a : f32; @@ -78,8 +80,8 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalsInterleaved) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( var a0 : f32; struct S0 { @@ -111,8 +113,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Global_Sampler) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); 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(); gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), " @group(0) @binding(0) var t : texture_1d;\n"); } @@ -135,8 +137,8 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalConst) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( const explicit : f32 = 1.0f; const inferred = 1.0f; @@ -150,8 +152,8 @@ TEST_F(WgslGeneratorImplTest, Emit_OverridableConstants) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( override a : f32; @id(7) override b : f32; diff --git a/src/tint/writer/wgsl/generator_impl_identifier_test.cc b/src/tint/writer/wgsl/generator_impl_identifier_test.cc index 9e95eab9ae..be2663fd17 100644 --- a/src/tint/writer/wgsl/generator_impl_identifier_test.cc +++ b/src/tint/writer/wgsl/generator_impl_identifier_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -28,7 +30,8 @@ TEST_F(WgslGeneratorImplTest, EmitIdentifierExpression_Single) { GeneratorImpl& gen = Build(); 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"); } diff --git a/src/tint/writer/wgsl/generator_impl_if_test.cc b/src/tint/writer/wgsl/generator_impl_if_test.cc index 7815a3ba64..968b03a6dc 100644 --- a/src/tint/writer/wgsl/generator_impl_if_test.cc +++ b/src/tint/writer/wgsl/generator_impl_if_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -31,7 +33,8 @@ TEST_F(WgslGeneratorImplTest, Emit_If) { 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) { return; } @@ -54,7 +57,8 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) { 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) { return; } else if (else_cond) { @@ -77,7 +81,8 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElse) { 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) { return; } else { @@ -105,7 +110,8 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithMultiple) { 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) { return; } else if (else_cond) { diff --git a/src/tint/writer/wgsl/generator_impl_literal_test.cc b/src/tint/writer/wgsl/generator_impl_literal_test.cc index 3bf0a47873..b170baafc3 100644 --- a/src/tint/writer/wgsl/generator_impl_literal_test.cc +++ b/src/tint/writer/wgsl/generator_impl_literal_test.cc @@ -17,6 +17,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -116,7 +118,8 @@ TEST_P(WgslGenerator_F32LiteralTest, Emit) { GeneratorImpl& gen = Build(); 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); } @@ -164,7 +167,8 @@ TEST_P(WgslGenerator_F16LiteralTest, Emit) { GeneratorImpl& gen = Build(); 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); } diff --git a/src/tint/writer/wgsl/generator_impl_loop_test.cc b/src/tint/writer/wgsl/generator_impl_loop_test.cc index 8aff678461..58b4ea8604 100644 --- a/src/tint/writer/wgsl/generator_impl_loop_test.cc +++ b/src/tint/writer/wgsl/generator_impl_loop_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -33,7 +35,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Loop) { 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 { break; } @@ -54,7 +57,8 @@ TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) { 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 { break; @@ -79,7 +83,8 @@ TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing_BreakIf) { 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 { discard; @@ -105,7 +110,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtInit) { 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({ _ = 1i; _ = 2i; @@ -127,7 +133,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithSimpleCond) { 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; ) { return; } @@ -147,7 +154,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithSimpleCont) { 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)) { return; } @@ -169,7 +177,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtCont) { 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(; ; { _ = 1i; _ = 2i; @@ -191,7 +200,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithSimpleInitCondCont) { 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)) { return; } @@ -213,7 +223,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtInitCondCont) { 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({ _ = 1i; _ = 2i; @@ -238,7 +249,8 @@ TEST_F(WgslGeneratorImplTest, Emit_While) { 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) { return; } @@ -257,7 +269,8 @@ TEST_F(WgslGeneratorImplTest, Emit_While_WithContinue) { 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) { continue; } @@ -278,7 +291,8 @@ TEST_F(WgslGeneratorImplTest, Emit_WhileMultiCond) { 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)) { return; } diff --git a/src/tint/writer/wgsl/generator_impl_member_accessor_test.cc b/src/tint/writer/wgsl/generator_impl_member_accessor_test.cc index 1d0be17a4e..4e5ce9a442 100644 --- a/src/tint/writer/wgsl/generator_impl_member_accessor_test.cc +++ b/src/tint/writer/wgsl/generator_impl_member_accessor_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -30,7 +32,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_MemberAccessor) { GeneratorImpl& gen = Build(); 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"); } @@ -45,7 +48,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_MemberAccessor_OfDref) { GeneratorImpl& gen = Build(); 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"); } diff --git a/src/tint/writer/wgsl/generator_impl_return_test.cc b/src/tint/writer/wgsl/generator_impl_return_test.cc index 6f89e002b0..631dbaf9a0 100644 --- a/src/tint/writer/wgsl/generator_impl_return_test.cc +++ b/src/tint/writer/wgsl/generator_impl_return_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -29,7 +31,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Return) { 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"); } @@ -41,7 +44,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ReturnWithValue) { 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"); } diff --git a/src/tint/writer/wgsl/generator_impl_switch_test.cc b/src/tint/writer/wgsl/generator_impl_switch_test.cc index 00d805d719..7ec5584298 100644 --- a/src/tint/writer/wgsl/generator_impl_switch_test.cc +++ b/src/tint/writer/wgsl/generator_impl_switch_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -43,7 +45,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Switch) { 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) { case 5i: { break; @@ -68,8 +71,8 @@ TEST_F(WgslGeneratorImplTest, Emit_Switch_MixedDefault) { GeneratorImpl& gen = Build(); 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) { case 5i, default: { break; diff --git a/src/tint/writer/wgsl/generator_impl_test.cc b/src/tint/writer/wgsl/generator_impl_test.cc index 17bd93d57f..b58c0becc2 100644 --- a/src/tint/writer/wgsl/generator_impl_test.cc +++ b/src/tint/writer/wgsl/generator_impl_test.cc @@ -15,6 +15,8 @@ #include "src/tint/sem/variable.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -25,7 +27,8 @@ TEST_F(WgslGeneratorImplTest, Generate) { 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() { } )"); diff --git a/src/tint/writer/wgsl/generator_impl_type_test.cc b/src/tint/writer/wgsl/generator_impl_type_test.cc index 19e86d46c6..9bf9a4c779 100644 --- a/src/tint/writer/wgsl/generator_impl_type_test.cc +++ b/src/tint/writer/wgsl/generator_impl_type_test.cc @@ -20,6 +20,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -34,7 +36,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Alias) { GeneratorImpl& gen = Build(); 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"); } @@ -44,7 +47,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Array) { GeneratorImpl& gen = Build(); 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"); } @@ -55,7 +59,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Array_Attribute) { GeneratorImpl& gen = Build(); 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"); } @@ -65,7 +70,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) { GeneratorImpl& gen = Build(); 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"); } @@ -75,7 +81,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Bool) { GeneratorImpl& gen = Build(); 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"); } @@ -85,7 +92,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_F32) { GeneratorImpl& gen = Build(); 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"); } @@ -97,7 +105,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_F16) { GeneratorImpl& gen = Build(); 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"); } @@ -107,7 +116,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_I32) { GeneratorImpl& gen = Build(); 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"); } @@ -117,7 +127,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Matrix_F32) { GeneratorImpl& gen = Build(); 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"); } @@ -129,7 +140,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Matrix_F16) { GeneratorImpl& gen = Build(); 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"); } @@ -140,7 +152,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Pointer) { GeneratorImpl& gen = Build(); 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"); } @@ -152,7 +165,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_PointerAccessMode) { GeneratorImpl& gen = Build(); 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"); } @@ -166,7 +180,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct) { GeneratorImpl& gen = Build(); 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"); } @@ -178,7 +193,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructOffsetDecl) { 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 { @size(8) padding : u32, @@ -201,7 +217,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructOffsetDecl_WithSymbolCollisions) { 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 { @size(8) padding : u32, @@ -223,7 +240,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructAlignDecl) { 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 { @align(8) a : i32, @@ -241,7 +259,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructSizeDecl) { 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 { @size(16) a : i32, @@ -259,7 +278,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithAttribute) { 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 { a : i32, @align(8) @@ -277,7 +297,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithEntryPointAttributes) { 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 { @builtin(vertex_index) a : u32, @@ -293,7 +314,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_U32) { GeneratorImpl& gen = Build(); 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"); } @@ -303,7 +325,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Vector_F32) { GeneratorImpl& gen = Build(); 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"); } @@ -315,7 +338,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Vector_F16) { GeneratorImpl& gen = Build(); 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"); } @@ -337,7 +361,8 @@ TEST_P(WgslGenerator_DepthTextureTest, EmitType_DepthTexture) { GeneratorImpl& gen = Build(); 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); } INSTANTIATE_TEST_SUITE_P( @@ -358,7 +383,8 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_F32) { GeneratorImpl& gen = Build(); 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) + ""); } @@ -371,7 +397,8 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_I32) { GeneratorImpl& gen = Build(); 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) + ""); } @@ -384,7 +411,8 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_U32) { GeneratorImpl& gen = Build(); 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) + ""); } INSTANTIATE_TEST_SUITE_P( @@ -407,7 +435,8 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_F32) { GeneratorImpl& gen = Build(); 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) + ""); } @@ -420,7 +449,8 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_I32) { GeneratorImpl& gen = Build(); 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) + ""); } @@ -433,7 +463,8 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_U32) { GeneratorImpl& gen = Build(); 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) + ""); } INSTANTIATE_TEST_SUITE_P(WgslGeneratorImplTest, @@ -461,7 +492,8 @@ TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) { GeneratorImpl& gen = Build(); 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); } INSTANTIATE_TEST_SUITE_P( @@ -492,7 +524,8 @@ TEST_P(WgslGenerator_ImageFormatTest, EmitType_StorageTexture_ImageFormat) { GeneratorImpl& gen = Build(); 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); } @@ -523,7 +556,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Sampler) { GeneratorImpl& gen = Build(); 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"); } @@ -534,7 +568,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_SamplerComparison) { GeneratorImpl& gen = Build(); 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"); } diff --git a/src/tint/writer/wgsl/generator_impl_unary_op_test.cc b/src/tint/writer/wgsl/generator_impl_unary_op_test.cc index fc135137ef..7c0ce546ce 100644 --- a/src/tint/writer/wgsl/generator_impl_unary_op_test.cc +++ b/src/tint/writer/wgsl/generator_impl_unary_op_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::wgsl { namespace { @@ -28,7 +30,8 @@ TEST_F(WgslUnaryOpTest, AddressOf) { GeneratorImpl& gen = Build(); 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)"); } @@ -40,7 +43,8 @@ TEST_F(WgslUnaryOpTest, Complement) { GeneratorImpl& gen = Build(); 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)"); } @@ -53,7 +57,8 @@ TEST_F(WgslUnaryOpTest, Indirection) { GeneratorImpl& gen = Build(); 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)"); } @@ -65,7 +70,8 @@ TEST_F(WgslUnaryOpTest, Not) { GeneratorImpl& gen = Build(); 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)"); } @@ -77,7 +83,8 @@ TEST_F(WgslUnaryOpTest, Negation) { GeneratorImpl& gen = Build(); 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)"); } diff --git a/src/tint/writer/wgsl/generator_impl_variable_decl_statement_test.cc b/src/tint/writer/wgsl/generator_impl_variable_decl_statement_test.cc index 6de698abd0..59d761efd5 100644 --- a/src/tint/writer/wgsl/generator_impl_variable_decl_statement_test.cc +++ b/src/tint/writer/wgsl/generator_impl_variable_decl_statement_test.cc @@ -15,6 +15,8 @@ #include "src/tint/ast/variable_decl_statement.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -32,7 +34,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) { 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"); } @@ -46,7 +49,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_InferredType) { 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"); } @@ -59,9 +63,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_AInt) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = 1; let l = C; @@ -78,9 +81,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_AFloat) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = 1.0; let l = C; @@ -97,9 +99,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_i32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = 1i; let l = C; @@ -116,9 +117,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_u32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = 1u; let l = C; @@ -135,9 +135,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_f32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = 1.0f; let l = C; @@ -156,9 +155,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_f16) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(enable f16; fn f() { @@ -177,9 +175,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_AInt) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = vec3(1, 2, 3); let l = C; @@ -196,9 +193,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_AFloat) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = vec3(1.0, 2.0, 3.0); let l = C; @@ -215,9 +211,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_f32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = vec3(1.0f, 2.0f, 3.0f); let l = C; @@ -236,9 +231,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_f16) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(enable f16; fn f() { @@ -257,9 +251,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_mat2x3_AFloat) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = mat2x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0); let l = C; @@ -276,9 +269,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_mat2x3_f32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = mat2x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f); let l = C; @@ -297,9 +289,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_mat2x3_f16) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(enable f16; fn f() { @@ -318,9 +309,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_arr_f32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = array(1.0f, 2.0f, 3.0f); let l = C; @@ -340,9 +330,8 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_arr_vec2_bool) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(fn f() { const C = array, 3u>(vec2(true, false), vec2(false, true), vec2(true, true)); let l = C; diff --git a/src/tint/writer/wgsl/generator_impl_variable_test.cc b/src/tint/writer/wgsl/generator_impl_variable_test.cc index 292dc12f5b..b9bbb40b3e 100644 --- a/src/tint/writer/wgsl/generator_impl_variable_test.cc +++ b/src/tint/writer/wgsl/generator_impl_variable_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/wgsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::wgsl { @@ -28,7 +30,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable) { GeneratorImpl& gen = Build(); 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 a : f32;)"); } @@ -38,7 +41,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_AddressSpace) { GeneratorImpl& gen = Build(); 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 a : f32;)"); } @@ -50,7 +54,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Access_Read) { GeneratorImpl& gen = Build(); 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 a : S;)"); } @@ -62,7 +67,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Access_ReadWrite) { GeneratorImpl& gen = Build(); 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 a : S;)"); } @@ -72,7 +78,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) { GeneratorImpl& gen = Build(); 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;)"); } @@ -82,7 +89,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Initializer) { GeneratorImpl& gen = Build(); 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 a : f32 = 1.0f;)"); } @@ -93,7 +101,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Let_Explicit) { GeneratorImpl& gen = Build(); 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;)"); } @@ -104,7 +113,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Let_Inferred) { GeneratorImpl& gen = Build(); 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;)"); } @@ -115,7 +125,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Const_Explicit) { GeneratorImpl& gen = Build(); 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;)"); } @@ -126,7 +137,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Const_Inferred) { GeneratorImpl& gen = Build(); 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;)"); }