[hlsl-writer] Move test helper to a template.

This CL updates TestHelper to be a templated class and converts the test
suites into using statements based off that template.

Bug: tint:7
Change-Id: I747434e7c6a8ecae353df448f06153e982dcec44
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27500
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-08-26 20:02:26 +00:00 committed by Commit Bot service account
parent 663be30b55
commit 63b007d34f
32 changed files with 50 additions and 100 deletions

View File

@ -1088,7 +1088,6 @@ source_set("tint_unittests_hlsl_writer_src") {
"src/writer/hlsl/generator_impl_unary_op_test.cc",
"src/writer/hlsl/generator_impl_variable_decl_statement_test.cc",
"src/writer/hlsl/namer_test.cc",
"src/writer/hlsl/test_helper.cc",
"src/writer/hlsl/test_helper.h",
]

View File

@ -599,7 +599,6 @@ if (${TINT_BUILD_HLSL_WRITER})
writer/hlsl/generator_impl_unary_op_test.cc
writer/hlsl/generator_impl_variable_decl_statement_test.cc
writer/hlsl/namer_test.cc
writer/hlsl/test_helper.cc
writer/hlsl/test_helper.h
)
endif()

View File

@ -27,8 +27,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_AliasType : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_AliasType = TestHelper;
TEST_F(HlslGeneratorImplTest_AliasType, EmitAliasType_F32) {
ast::type::F32Type f32;

View File

@ -27,8 +27,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Expression : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_Expression = TestHelper;
TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
ast::type::I32Type i32;

View File

@ -27,7 +27,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_As : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_As = TestHelper;
TEST_F(HlslGeneratorImplTest_As, EmitExpression_As_Float) {
ast::type::F32Type f32;

View File

@ -25,7 +25,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Assign : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Assign = TestHelper;
TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs");

View File

@ -33,8 +33,7 @@ inline std::ostream& operator<<(std::ostream& out, BinaryData data) {
return out;
}
class HlslBinaryTest : public TestHelper,
public testing::TestWithParam<BinaryData> {};
using HlslBinaryTest = TestHelperBase<testing::TestWithParam<BinaryData>>;
TEST_P(HlslBinaryTest, Emit) {
auto params = GetParam();

View File

@ -23,7 +23,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Block : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Block = TestHelper;
TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
ast::BlockStatement b;

View File

@ -24,7 +24,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Break : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Break = TestHelper;
TEST_F(HlslGeneratorImplTest_Break, Emit_Break) {
ast::BreakStatement b;

View File

@ -27,7 +27,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Call : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Call = TestHelper;
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
ast::type::VoidType void_type;

View File

@ -28,7 +28,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Case : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Case = TestHelper;
TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
ast::type::I32Type i32;

View File

@ -26,7 +26,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Cast : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Cast = TestHelper;
TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) {
ast::type::F32Type f32;

View File

@ -33,8 +33,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Constructor : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_Constructor = TestHelper;
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
ast::type::BoolType bool_type;

View File

@ -24,8 +24,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Continue : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_Continue = TestHelper;
TEST_F(HlslGeneratorImplTest_Continue, Emit_Continue) {
ast::ContinueStatement c;

View File

@ -21,8 +21,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Discard : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_Discard = TestHelper;
TEST_F(HlslGeneratorImplTest_Discard, Emit_Discard) {
ast::DiscardStatement stmt;

View File

@ -34,8 +34,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_EntryPoint : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_EntryPoint = TestHelper;
TEST_F(HlslGeneratorImplTest_EntryPoint, EmitEntryPointData_Vertex_Input) {
// [[location 0]] var<in> foo : f32;

View File

@ -48,8 +48,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Function : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_Function = TestHelper;
TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
ast::type::VoidType void_type;

View File

@ -21,8 +21,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Identifier : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_Identifier = TestHelper;
TEST_F(HlslGeneratorImplTest_Identifier, DISABLED_EmitExpression_Identifier) {
ast::IdentifierExpression i(std::vector<std::string>{"std", "glsl"});

View File

@ -24,7 +24,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_If : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_If = TestHelper;
TEST_F(HlslGeneratorImplTest_If, Emit_If) {
auto cond = std::make_unique<ast::IdentifierExpression>("cond");

View File

@ -36,7 +36,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Import : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Import = TestHelper;
struct HlslImportData {
const char* name;
@ -47,9 +47,8 @@ inline std::ostream& operator<<(std::ostream& out, HlslImportData data) {
return out;
}
class HlslImportData_SingleParamTest
: public TestHelper,
public testing::TestWithParam<HlslImportData> {};
using HlslImportData_SingleParamTest =
TestHelperBase<testing::TestWithParam<HlslImportData>>;
TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
auto param = GetParam();
@ -113,9 +112,8 @@ TEST_F(HlslGeneratorImplTest_Import, DISABLED_HlslImportData_ATanh) {
FAIL();
}
class HlslImportData_SingleIntParamTest
: public TestHelper,
public testing::TestWithParam<HlslImportData> {};
using HlslImportData_SingleIntParamTest =
TestHelperBase<testing::TestWithParam<HlslImportData>>;
TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
auto param = GetParam();
@ -140,9 +138,8 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
testing::Values(HlslImportData{"sabs", "abs"},
HlslImportData{"ssign", "sign"}));
class HlslImportData_DualParamTest
: public TestHelper,
public testing::TestWithParam<HlslImportData> {};
using HlslImportData_DualParamTest =
TestHelperBase<testing::TestWithParam<HlslImportData>>;
TEST_P(HlslImportData_DualParamTest, FloatScalar) {
auto param = GetParam();
@ -177,9 +174,8 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
HlslImportData{"reflect", "reflect"},
HlslImportData{"step", "step"}));
class HlslImportData_DualParam_VectorTest
: public TestHelper,
public testing::TestWithParam<HlslImportData> {};
using HlslImportData_DualParam_VectorTest =
TestHelperBase<testing::TestWithParam<HlslImportData>>;
TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
auto param = GetParam();
@ -224,9 +220,8 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
HlslImportData_DualParam_VectorTest,
testing::Values(HlslImportData{"cross", "cross"}));
class HlslImportData_DualParam_Int_Test
: public TestHelper,
public testing::TestWithParam<HlslImportData> {};
using HlslImportData_DualParam_Int_Test =
TestHelperBase<testing::TestWithParam<HlslImportData>>;
TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
auto param = GetParam();
@ -255,9 +250,8 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
HlslImportData{"umax", "max"},
HlslImportData{"umin", "min"}));
class HlslImportData_TripleParamTest
: public TestHelper,
public testing::TestWithParam<HlslImportData> {};
using HlslImportData_TripleParamTest =
TestHelperBase<testing::TestWithParam<HlslImportData>>;
TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
auto param = GetParam();
@ -295,9 +289,8 @@ TEST_F(HlslGeneratorImplTest_Import, DISABLED_HlslImportData_FMix) {
FAIL();
}
class HlslImportData_TripleParam_Int_Test
: public TestHelper,
public testing::TestWithParam<HlslImportData> {};
using HlslImportData_TripleParam_Int_Test =
TestHelperBase<testing::TestWithParam<HlslImportData>>;
TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
auto param = GetParam();

View File

@ -26,8 +26,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Intrinsic : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_Intrinsic = TestHelper;
struct IntrinsicData {
const char* name;
@ -37,8 +36,7 @@ inline std::ostream& operator<<(std::ostream& out, IntrinsicData data) {
out << data.name;
return out;
}
class HlslIntrinsicTest : public TestHelper,
public testing::TestWithParam<IntrinsicData> {};
using HlslIntrinsicTest = TestHelperBase<testing::TestWithParam<IntrinsicData>>;
TEST_P(HlslIntrinsicTest, Emit) {
auto param = GetParam();
EXPECT_EQ(gen().generate_intrinsic_name(param.name), param.hlsl_name);

View File

@ -31,7 +31,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Loop : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Loop = TestHelper;
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
auto body = std::make_unique<ast::BlockStatement>();

View File

@ -43,8 +43,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_MemberAccessor : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_MemberAccessor = TestHelper;
TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
ast::type::F32Type f32;

View File

@ -29,8 +29,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_ModuleConstant : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_ModuleConstant = TestHelper;
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
ast::type::F32Type f32;

View File

@ -25,7 +25,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Return : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Return = TestHelper;
TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
ast::ReturnStatement r;

View File

@ -28,7 +28,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Switch : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Switch = TestHelper;
TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
auto def = std::make_unique<ast::CaseStatement>();

View File

@ -26,7 +26,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest = TestHelper;
TEST_F(HlslGeneratorImplTest, DISABLED_Generate) {
ast::type::VoidType void_type;
@ -71,9 +71,8 @@ inline std::ostream& operator<<(std::ostream& out, HlslBuiltinData data) {
out << data.builtin;
return out;
}
class HlslBuiltinConversionTest
: public TestHelper,
public testing::TestWithParam<HlslBuiltinData> {};
using HlslBuiltinConversionTest =
TestHelperBase<testing::TestWithParam<HlslBuiltinData>>;
TEST_P(HlslBuiltinConversionTest, Emit) {
auto params = GetParam();
EXPECT_EQ(gen().builtin_to_attribute(params.builtin),

View File

@ -35,7 +35,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_Type : public TestHelper, public testing::Test {};
using HlslGeneratorImplTest_Type = TestHelper;
TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias) {
ast::type::F32Type f32;

View File

@ -33,8 +33,7 @@ inline std::ostream& operator<<(std::ostream& out, UnaryOpData data) {
out << data.op;
return out;
}
class HlslUnaryOpTest : public TestHelper,
public testing::TestWithParam<UnaryOpData> {};
using HlslUnaryOpTest = TestHelperBase<testing::TestWithParam<UnaryOpData>>;
TEST_P(HlslUnaryOpTest, Emit) {
auto params = GetParam();

View File

@ -30,8 +30,7 @@ namespace writer {
namespace hlsl {
namespace {
class HlslGeneratorImplTest_VariableDecl : public TestHelper,
public testing::Test {};
using HlslGeneratorImplTest_VariableDecl = TestHelper;
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
ast::type::F32Type f32;

View File

@ -1,27 +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/writer/hlsl/test_helper.h"
namespace tint {
namespace writer {
namespace hlsl {
TestHelper::TestHelper() : td_(&ctx_, &mod_), impl_(&mod_) {}
TestHelper::~TestHelper() = default;
} // namespace hlsl
} // namespace writer
} // namespace tint

View File

@ -28,10 +28,11 @@ namespace writer {
namespace hlsl {
/// Helper class for testing
class TestHelper {
template <typename T>
class TestHelperBase : public T {
public:
TestHelper();
~TestHelper();
TestHelperBase() : td_(&ctx_, &mod_), impl_(&mod_) {}
~TestHelperBase() = default;
/// @returns the generator implementation
GeneratorImpl& gen() { return impl_; }
@ -55,6 +56,7 @@ class TestHelper {
GeneratorImpl impl_;
std::ostringstream out_;
};
using TestHelper = TestHelperBase<testing::Test>;
} // namespace hlsl
} // namespace writer