diff --git a/src/validator_function_test.cc b/src/validator_function_test.cc index 601bc2c643..864d9cb275 100644 --- a/src/validator_function_test.cc +++ b/src/validator_function_test.cc @@ -83,6 +83,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) { body->append(std::make_unique()); func->set_body(std::move(body)); mod()->AddFunction(std::move(func)); + AddFakeEntryPoint(); EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(v()->Validate(mod())) << v()->error(); diff --git a/src/validator_test.cc b/src/validator_test.cc index 6dc58c269d..32bf88349a 100644 --- a/src/validator_test.cc +++ b/src/validator_test.cc @@ -263,9 +263,10 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) { auto global_var = std::make_unique( Source{12, 34}, "global_var", ast::StorageClass::kInput, &f32); mod()->AddGlobalVariable(std::move(global_var)); + AddFakeEntryPoint(); + EXPECT_TRUE(td()->Determine()) << td()->error(); - tint::ValidatorImpl v; - EXPECT_TRUE(v.Validate(mod())) << v.error(); + EXPECT_TRUE(v()->Validate(mod())) << v()->error(); } TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) { @@ -275,9 +276,8 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) { Source{12, 34}, "global_var", ast::StorageClass::kNone, &f32); mod()->AddGlobalVariable(std::move(global_var)); EXPECT_TRUE(td()->Determine()) << td()->error(); - tint::ValidatorImpl v; - EXPECT_FALSE(v.Validate(mod())); - EXPECT_EQ(v.error(), + EXPECT_FALSE(v()->Validate(mod())); + EXPECT_EQ(v()->error(), "12:34: v-0022: global variables must have a storage class"); } @@ -346,6 +346,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) { func->set_body(std::move(body)); auto* func_ptr = func.get(); mod()->AddFunction(std::move(func)); + AddFakeEntryPoint(); EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->DetermineFunction(func_ptr)) << td()->error(); @@ -440,6 +441,7 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) { var1->set_constructor(std::make_unique( std::make_unique(&i32, 0))); mod()->AddGlobalVariable(std::move(var1)); + AddFakeEntryPoint(); EXPECT_TRUE(v()->Validate(mod())) << v()->error(); } @@ -674,6 +676,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) { mod()->AddFunction(std::move(func0)); mod()->AddFunction(std::move(func1)); + AddFakeEntryPoint(); EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(v()->Validate(mod())) << v()->error(); diff --git a/src/validator_test_helper.cc b/src/validator_test_helper.cc index 349ad8a6e5..75151c05d5 100644 --- a/src/validator_test_helper.cc +++ b/src/validator_test_helper.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/validator_test_helper.h" +#include "src/type_manager.h" namespace tint { @@ -23,4 +24,22 @@ ValidatorTestHelper::ValidatorTestHelper() { ValidatorTestHelper::~ValidatorTestHelper() = default; +void ValidatorTestHelper::AddFakeEntryPoint() { + // entry_point vertex as "fake_entry_point" = fake_func + // fn fake_func() -> void {} + auto ep = std::make_unique(ast::PipelineStage::kVertex, + "fake_entry_point", "fake_func"); + ast::VariableList fake_params; + auto fake_func = std::make_unique( + "fake_func", std::move(fake_params), + ctx_.type_mgr().Get(std::make_unique())); + auto fake_body = std::make_unique(); + auto return_stmt = std::make_unique(); + fake_body->append(std::move(return_stmt)); + fake_func->set_body(std::move(fake_body)); + mod()->AddFunction(std::move(fake_func)); + mod()->AddEntryPoint(std::move(ep)); + return; +} + } // namespace tint diff --git a/src/validator_test_helper.h b/src/validator_test_helper.h index 9dbde6cc84..990e2abbed 100644 --- a/src/validator_test_helper.h +++ b/src/validator_test_helper.h @@ -15,6 +15,7 @@ #ifndef SRC_VALIDATOR_TEST_HELPER_H_ #define SRC_VALIDATOR_TEST_HELPER_H_ +#include "src/ast/type/void_type.h" #include "src/type_determiner.h" #include "src/validator_impl.h" @@ -36,6 +37,8 @@ class ValidatorTestHelper { /// A handle to the created module /// @return a pointer to the test module ast::Module* mod() { return &mod_; } + /// Create a function and add an entry point to it + void AddFakeEntryPoint(); private: std::unique_ptr v_;