From d3a5080c7bf8be17fce355a5f60223ab8271ece4 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 26 Apr 2022 22:19:22 +0000 Subject: [PATCH] Fixup validator tests added during split from resolver. This PR adds the validator_is_storable test into the CMakeList file correctly and removes the helper files. The resolver helper is used instead and a test helper to return the validator added into the resolver. Change-Id: I5b18bcc6373e3b39807af05cf5c058fab61ed4ca Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88041 Auto-Submit: Dan Sinclair Reviewed-by: Ben Clayton Kokoro: Kokoro Commit-Queue: Dan Sinclair --- src/tint/CMakeLists.txt | 1 + src/tint/resolver/resolver.h | 3 ++ src/tint/resolver/resolver_test_helper.h | 3 ++ .../resolver/validator_is_storeable_test.cc | 4 +- src/tint/resolver/validator_test_helper.cc | 27 ----------- src/tint/resolver/validator_test_helper.h | 46 ------------------- test/tint/BUILD.gn | 1 + 7 files changed, 10 insertions(+), 75 deletions(-) delete mode 100644 src/tint/resolver/validator_test_helper.cc delete mode 100644 src/tint/resolver/validator_test_helper.h diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 172edf8be4..20c8579746 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -772,6 +772,7 @@ if(TINT_BUILD_TESTS) resolver/type_constructor_validation_test.cc resolver/type_validation_test.cc resolver/validation_test.cc + resolver/validator_is_storeable_test.cc resolver/var_let_test.cc resolver/var_let_validation_test.cc scope_stack_test.cc diff --git a/src/tint/resolver/resolver.h b/src/tint/resolver/resolver.h index 6487d35a84..22e5d5efc8 100644 --- a/src/tint/resolver/resolver.h +++ b/src/tint/resolver/resolver.h @@ -108,6 +108,9 @@ class Resolver { return validator_.IsHostShareable(type); } + /// @returns the validator for testing + const Validator* GetValidatorForTesting() const { return &validator_; } + private: /// Describes the context in which a variable is declared enum class VariableKind { kParameter, kLocal, kGlobal }; diff --git a/src/tint/resolver/resolver_test_helper.h b/src/tint/resolver/resolver_test_helper.h index 236b854b79..bd036aed94 100644 --- a/src/tint/resolver/resolver_test_helper.h +++ b/src/tint/resolver/resolver_test_helper.h @@ -40,6 +40,9 @@ class TestHelper : public ProgramBuilder { /// @return a pointer to the Resolver Resolver* r() const { return resolver_.get(); } + /// @return a pointer to the validator + const Validator* v() const { return resolver_->GetValidatorForTesting(); } + /// Returns the statement that holds the given expression. /// @param expr the ast::Expression /// @return the ast::Statement of the ast::Expression, or nullptr if the diff --git a/src/tint/resolver/validator_is_storeable_test.cc b/src/tint/resolver/validator_is_storeable_test.cc index f180936e87..b3d6954f40 100644 --- a/src/tint/resolver/validator_is_storeable_test.cc +++ b/src/tint/resolver/validator_is_storeable_test.cc @@ -15,13 +15,13 @@ #include "src/tint/resolver/validator.h" #include "gmock/gmock.h" -#include "src/tint/resolver/validator_test_helper.h" +#include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/sem/atomic_type.h" namespace tint::resolver { namespace { -using ValidatorIsStorableTest = ValidatorTest; +using ValidatorIsStorableTest = ResolverTest; TEST_F(ValidatorIsStorableTest, Void) { EXPECT_FALSE(v()->IsStorable(create())); diff --git a/src/tint/resolver/validator_test_helper.cc b/src/tint/resolver/validator_test_helper.cc deleted file mode 100644 index 123d5c7c53..0000000000 --- a/src/tint/resolver/validator_test_helper.cc +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2022 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/tint/resolver/validator_test_helper.h" - -#include - -namespace tint::resolver { - -TestHelper::TestHelper() - : validator_( - std::make_unique(this->Symbols(), this->Diagnostics())) {} - -TestHelper::~TestHelper() = default; - -} // namespace tint::resolver diff --git a/src/tint/resolver/validator_test_helper.h b/src/tint/resolver/validator_test_helper.h deleted file mode 100644 index 3dd3ea2a05..0000000000 --- a/src/tint/resolver/validator_test_helper.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2022 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. - -#ifndef SRC_TINT_RESOLVER_VALIDATOR_TEST_HELPER_H_ -#define SRC_TINT_RESOLVER_VALIDATOR_TEST_HELPER_H_ - -#include - -#include "gtest/gtest.h" -#include "src/tint/program_builder.h" -#include "src/tint/resolver/validator.h" - -namespace tint::resolver { - -/// Helper class for testing -class TestHelper : public ProgramBuilder { - public: - /// Constructor - TestHelper(); - - /// Destructor - ~TestHelper() override; - - /// @return a pointer to the Validator - Validator* v() const { return validator_.get(); } - - private: - std::unique_ptr validator_; -}; - -class ValidatorTest : public TestHelper, public testing::Test {}; - -} // namespace tint::resolver - -#endif // SRC_TINT_RESOLVER_VALIDATOR_TEST_HELPER_H_ diff --git a/test/tint/BUILD.gn b/test/tint/BUILD.gn index ae12115644..913ad0fdba 100644 --- a/test/tint/BUILD.gn +++ b/test/tint/BUILD.gn @@ -274,6 +274,7 @@ tint_unittests_source_set("tint_unittests_resolver_src") { "../../src/tint/resolver/type_constructor_validation_test.cc", "../../src/tint/resolver/type_validation_test.cc", "../../src/tint/resolver/validation_test.cc", + "../../src/tint/resolver/validator_is_storeable_test.cc", "../../src/tint/resolver/var_let_test.cc", "../../src/tint/resolver/var_let_validation_test.cc", ]