[validation] Add a validator test helper class
Change-Id: I12d225dbbda3ceffda6f0f0dbf264a6a6b249fb2 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27284 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
63a5aa7d58
commit
3fad211a8f
2
BUILD.gn
2
BUILD.gn
|
@ -378,6 +378,8 @@ source_set("libtint_core_src") {
|
|||
"src/validator.h",
|
||||
"src/validator_impl.cc",
|
||||
"src/validator_impl.h",
|
||||
"src/validator_test_helper.cc",
|
||||
"src/validator_test_helper.h",
|
||||
"src/writer/text.cc",
|
||||
"src/writer/text.h",
|
||||
"src/writer/text_generator.cc",
|
||||
|
|
|
@ -200,6 +200,8 @@ set(TINT_LIB_SRCS
|
|||
validator.h
|
||||
validator_impl.cc
|
||||
validator_impl.h
|
||||
validator_test_helper.cc
|
||||
validator_test_helper.h
|
||||
writer/text.cc
|
||||
writer/text.h
|
||||
writer/text_generator.cc
|
||||
|
|
|
@ -27,27 +27,12 @@
|
|||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/validator_test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace {
|
||||
|
||||
class TypeDeterminerHelper {
|
||||
// TODO(sarahM0): move this form this test file, type_determiner_test.cc and
|
||||
// validator_test.cc to its own file.
|
||||
public:
|
||||
TypeDeterminerHelper()
|
||||
: td_(std::make_unique<TypeDeterminer>(&ctx_, &mod_)) {}
|
||||
|
||||
TypeDeterminer* td() const { return td_.get(); }
|
||||
ast::Module* mod() { return &mod_; }
|
||||
|
||||
private:
|
||||
Context ctx_;
|
||||
ast::Module mod_;
|
||||
std::unique_ptr<TypeDeterminer> td_;
|
||||
};
|
||||
|
||||
class ValidateFunctionTest : public TypeDeterminerHelper,
|
||||
class ValidateFunctionTest : public ValidatorTestHelper,
|
||||
public testing::Test {};
|
||||
|
||||
TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||
|
|
|
@ -54,25 +54,12 @@
|
|||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/validator_test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace {
|
||||
|
||||
class TypeDeterminerHelper {
|
||||
public:
|
||||
TypeDeterminerHelper()
|
||||
: td_(std::make_unique<TypeDeterminer>(&ctx_, &mod_)) {}
|
||||
|
||||
TypeDeterminer* td() const { return td_.get(); }
|
||||
ast::Module* mod() { return &mod_; }
|
||||
|
||||
private:
|
||||
Context ctx_;
|
||||
ast::Module mod_;
|
||||
std::unique_ptr<TypeDeterminer> td_;
|
||||
};
|
||||
|
||||
class ValidatorTest : public TypeDeterminerHelper, public testing::Test {};
|
||||
class ValidatorTest : public ValidatorTestHelper, public testing::Test {};
|
||||
|
||||
TEST_F(ValidatorTest, Import) {
|
||||
ast::Module m;
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
// 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/validator_test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
ValidatorTestHelper::ValidatorTestHelper() {
|
||||
td_ = std::make_unique<TypeDeterminer>(&ctx_, &mod_);
|
||||
v_ = std::make_unique<ValidatorImpl>();
|
||||
}
|
||||
|
||||
ValidatorTestHelper::~ValidatorTestHelper() = default;
|
||||
|
||||
} // namespace tint
|
|
@ -0,0 +1,49 @@
|
|||
// 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.
|
||||
|
||||
#ifndef SRC_VALIDATOR_TEST_HELPER_H_
|
||||
#define SRC_VALIDATOR_TEST_HELPER_H_
|
||||
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/validator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
/// A helper for testing validation
|
||||
class ValidatorTestHelper {
|
||||
public:
|
||||
/// Constructor
|
||||
ValidatorTestHelper();
|
||||
~ValidatorTestHelper();
|
||||
|
||||
/// A handle to validator
|
||||
/// @returns a pointer to the validator
|
||||
ValidatorImpl* v() const { return v_.get(); }
|
||||
/// A handle to type_determiner
|
||||
/// @returns a pointer to the type_determiner object
|
||||
TypeDeterminer* td() const { return td_.get(); }
|
||||
/// A handle to the created module
|
||||
/// @return a pointer to the test module
|
||||
ast::Module* mod() { return &mod_; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<ValidatorImpl> v_;
|
||||
Context ctx_;
|
||||
ast::Module mod_;
|
||||
std::unique_ptr<TypeDeterminer> td_;
|
||||
};
|
||||
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_VALIDATOR_TEST_HELPER_H_
|
Loading…
Reference in New Issue