mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Remove all Source{} smell from tests
Switch all remaining AST stack allocations in tests to using create<T>() which will automatically inject the current Source as the first parameter.
Most remaining uses of Source{} in the codebase are places where we need to fix.
Bug: tint:396
Change-Id: I24655800b50d6ad52e682a7339022972e9b354d9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36380
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
9a644c7903
commit
e6e704145b
@@ -21,6 +21,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/builder.h"
|
||||
#include "src/reader/wgsl/parser_impl.h"
|
||||
|
||||
namespace tint {
|
||||
@@ -28,7 +29,7 @@ namespace reader {
|
||||
namespace wgsl {
|
||||
|
||||
/// WGSL Parser test class
|
||||
class ParserImplTest : public testing::Test {
|
||||
class ParserImplTest : public testing::Test, public ast::BuilderWithModule {
|
||||
public:
|
||||
/// Constructor
|
||||
ParserImplTest();
|
||||
@@ -50,7 +51,8 @@ class ParserImplTest : public testing::Test {
|
||||
|
||||
/// WGSL Parser test class with param
|
||||
template <typename T>
|
||||
class ParserImplTestWithParam : public testing::TestWithParam<T> {
|
||||
class ParserImplTestWithParam : public testing::TestWithParam<T>,
|
||||
public ast::BuilderWithModule {
|
||||
public:
|
||||
/// Constructor
|
||||
ParserImplTestWithParam() = default;
|
||||
|
||||
@@ -83,23 +83,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_InvalidType) {
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[access(read)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
@@ -111,23 +108,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[access(read_write)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
@@ -139,23 +133,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[access(read), access(read_write)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_TRUE(p->has_error());
|
||||
@@ -164,23 +155,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDeco_MultiBlock_Fail) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[access(read)]][[access(read_write)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_TRUE(p->has_error());
|
||||
@@ -205,23 +193,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_AccessDecoIllegalValue) {
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_NonAccessDecoFail) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[stride(1)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_TRUE(p->has_error());
|
||||
|
||||
Reference in New Issue
Block a user