[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>
diff --git a/BUILD.gn b/BUILD.gn
index 34dcabb..460221e 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -378,6 +378,8 @@
     "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",
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 68707f4..825b1fc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -200,6 +200,8 @@
   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
diff --git a/src/validator_function_test.cc b/src/validator_function_test.cc
index e8e4eee..4079daa 100644
--- a/src/validator_function_test.cc
+++ b/src/validator_function_test.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) {
diff --git a/src/validator_test.cc b/src/validator_test.cc
index 1df7170..dcd96b2 100644
--- a/src/validator_test.cc
+++ b/src/validator_test.cc
@@ -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;
diff --git a/src/validator_test_helper.cc b/src/validator_test_helper.cc
new file mode 100644
index 0000000..349ad8a
--- /dev/null
+++ b/src/validator_test_helper.cc
@@ -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
diff --git a/src/validator_test_helper.h b/src/validator_test_helper.h
new file mode 100644
index 0000000..9dbde6c
--- /dev/null
+++ b/src/validator_test_helper.h
@@ -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_