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>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56fa8d3..b3ae095 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt
@@ -522,8 +522,6 @@ utils/tmpfile_test.cc utils/tmpfile.h utils/unique_vector_test.cc - validator/validator_function_test.cc - validator/validator_test.cc validator/validator_test_helper.cc validator/validator_test_helper.h writer/append_vector_test.cc
diff --git a/src/resolver/function_validation_test.cc b/src/resolver/function_validation_test.cc index 018e6bb..562dc4c 100644 --- a/src/resolver/function_validation_test.cc +++ b/src/resolver/function_validation_test.cc
@@ -45,6 +45,24 @@ "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; } @@ -63,6 +81,20 @@ } 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 @@ "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
diff --git a/src/resolver/type_validation_test.cc b/src/resolver/type_validation_test.cc index ee4144c..4ea6567 100644 --- a/src/resolver/type_validation_test.cc +++ b/src/resolver/type_validation_test.cc
@@ -26,6 +26,28 @@ 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);
diff --git a/src/validator/validator_function_test.cc b/src/validator/validator_function_test.cc deleted file mode 100644 index 00c7401..0000000 --- a/src/validator/validator_function_test.cc +++ /dev/null
@@ -1,104 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/ast/stage_decoration.h" -#include "src/validator/validator_test_helper.h" - -namespace tint { -namespace { - -class ValidateFunctionTest : public ValidatorTestHelper, - public testing::Test {}; - -TEST_F(ValidateFunctionTest, 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), - }); - - ValidatorImpl& v = Build(); - - EXPECT_TRUE(v.Validate()); -} - -TEST_F(ValidateFunctionTest, - 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), - }); - - ValidatorImpl& v = Build(); - - EXPECT_TRUE(v.Validate()); -} - -TEST_F(ValidateFunctionTest, NoPipelineEntryPoints) { - Func("vtx_func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create<ast::ReturnStatement>(), - }, - ast::DecorationList{}); - - ValidatorImpl& v = Build(); - - EXPECT_TRUE(v.Validate()) << v.error(); -} - -TEST_F(ValidateFunctionTest, 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{}); - - ValidatorImpl& v = Build(); - - EXPECT_TRUE(v.Validate()) << v.error(); -} - -TEST_F(ValidateFunctionTest, 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{}); - - ValidatorImpl& v = Build(); - - EXPECT_TRUE(v.Validate()) << v.error(); -} - -} // namespace -} // namespace tint
diff --git a/src/validator/validator_test.cc b/src/validator/validator_test.cc deleted file mode 100644 index c13a8f7..0000000 --- a/src/validator/validator_test.cc +++ /dev/null
@@ -1,50 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/ast/if_statement.h" -#include "src/ast/stage_decoration.h" -#include "src/validator/validator_test_helper.h" - -namespace tint { -namespace { - -class ValidatorTest : public ValidatorTestHelper, public testing::Test {}; - -TEST_F(ValidatorTest, 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); - - ValidatorImpl& v = Build(); - - ASSERT_NE(TypeOf(lhs), nullptr); - ASSERT_NE(TypeOf(rhs), nullptr); - - EXPECT_TRUE(v.ValidateStatements(body)) << v.error(); -} - -} // namespace -} // namespace tint
diff --git a/test/BUILD.gn b/test/BUILD.gn index cb6546a..64dcf38 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn
@@ -225,8 +225,6 @@ "../src/utils/tmpfile.h", "../src/utils/tmpfile_test.cc", "../src/utils/unique_vector_test.cc", - "../src/validator/validator_function_test.cc", - "../src/validator/validator_test.cc", "../src/validator/validator_test_helper.cc", "../src/validator/validator_test_helper.h", "../src/writer/append_vector_test.cc",