mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
Move remaining Validator tests to Resolver
Bug: tint:642 Change-Id: I0f983d8c0391f4e500562faadf0a621c4edb46ab Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46942 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
bfc97945f3
commit
e93d46fcbc
@@ -45,6 +45,24 @@ TEST_F(ResolverFunctionValidationTest, FunctionNamesMustBeUnique_fail) {
|
||||
"12:34 error v-0016: function names must be unique 'func'");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
VoidFunctionEndWithoutReturnStatement_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn func -> void { var a:i32 = 2; }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||
// fn func -> int { var a:i32 = 2; }
|
||||
|
||||
@@ -62,6 +80,20 @@ TEST_F(ResolverFunctionValidationTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||
"12:34 error v-0002: non-void function must end with a return statement");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
VoidFunctionEndWithoutReturnStatementEmptyBody_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn func -> void {}
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
FunctionEndWithoutReturnStatementEmptyBody_Fail) {
|
||||
// fn func -> int {}
|
||||
@@ -201,5 +233,43 @@ TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
|
||||
"point");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, NoPipelineEntryPoints) {
|
||||
Func("vtx_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, FunctionVarInitWithParam) {
|
||||
// fn foo(bar : f32) -> void{
|
||||
// var baz : f32 = bar;
|
||||
// }
|
||||
|
||||
auto* bar = Var("bar", ty.f32(), ast::StorageClass::kFunction);
|
||||
auto* baz = Var("baz", ty.f32(), ast::StorageClass::kFunction, Expr("bar"));
|
||||
|
||||
Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, FunctionConstInitWithParam) {
|
||||
// fn foo(bar : f32) -> void{
|
||||
// const baz : f32 = bar;
|
||||
// }
|
||||
|
||||
auto* bar = Var("bar", ty.f32(), ast::StorageClass::kFunction);
|
||||
auto* baz = Const("baz", ty.f32(), Expr("bar"));
|
||||
|
||||
Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
||||
|
||||
@@ -26,6 +26,28 @@ namespace {
|
||||
class ResolverTypeValidationTest : public resolver::TestHelper,
|
||||
public testing::Test {};
|
||||
|
||||
TEST_F(ResolverTypeValidationTest, VariableDeclNoConstructor_Pass) {
|
||||
// {
|
||||
// var a :i32;
|
||||
// a = 2;
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, nullptr);
|
||||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
|
||||
rhs),
|
||||
});
|
||||
|
||||
WrapInFunction(body);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(ResolverTypeValidationTest, GlobalVariableWithStorageClass_Pass) {
|
||||
// var<in> global_var: f32;
|
||||
Global(Source{{12, 34}}, "global_var", ty.f32(), ast::StorageClass::kInput);
|
||||
|
||||
Reference in New Issue
Block a user