Remove ProgramBuilder from constant tests.
The constant tests where built based off the ProgramBuilder, but the
only part they used was to get the constant::Manager. Just create the
manager directly in the tests to simplify the testing setup.
Change-Id: Ifc74c5970b120a19162a1a3d53c7c7257909220f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/234394
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/core/constant/BUILD.bazel b/src/tint/lang/core/constant/BUILD.bazel
index fca438a..395e8a1 100644
--- a/src/tint/lang/core/constant/BUILD.bazel
+++ b/src/tint/lang/core/constant/BUILD.bazel
@@ -92,7 +92,6 @@
"eval_runtime_semantics_test.cc",
"eval_test.h",
"eval_unary_op_test.cc",
- "helper_test.h",
"invalid_test.cc",
"manager_test.cc",
"scalar_test.cc",
diff --git a/src/tint/lang/core/constant/BUILD.cmake b/src/tint/lang/core/constant/BUILD.cmake
index 2e8ceca..bdea081 100644
--- a/src/tint/lang/core/constant/BUILD.cmake
+++ b/src/tint/lang/core/constant/BUILD.cmake
@@ -93,7 +93,6 @@
lang/core/constant/eval_runtime_semantics_test.cc
lang/core/constant/eval_test.h
lang/core/constant/eval_unary_op_test.cc
- lang/core/constant/helper_test.h
lang/core/constant/invalid_test.cc
lang/core/constant/manager_test.cc
lang/core/constant/scalar_test.cc
diff --git a/src/tint/lang/core/constant/BUILD.gn b/src/tint/lang/core/constant/BUILD.gn
index f6a8a1f..95ae3b0 100644
--- a/src/tint/lang/core/constant/BUILD.gn
+++ b/src/tint/lang/core/constant/BUILD.gn
@@ -93,7 +93,6 @@
"eval_runtime_semantics_test.cc",
"eval_test.h",
"eval_unary_op_test.cc",
- "helper_test.h",
"invalid_test.cc",
"manager_test.cc",
"scalar_test.cc",
diff --git a/src/tint/lang/core/constant/composite_test.cc b/src/tint/lang/core/constant/composite_test.cc
index f03f323..33cc3c9 100644
--- a/src/tint/lang/core/constant/composite_test.cc
+++ b/src/tint/lang/core/constant/composite_test.cc
@@ -27,9 +27,11 @@
#include "src/tint/lang/core/constant/composite.h"
-#include "src/tint/lang/core/constant/helper_test.h"
+#include "gtest/gtest.h"
#include "src/tint/lang/core/constant/scalar.h"
#include "src/tint/lang/core/fluent_types.h"
+#include "src/tint/lang/core/type/f32.h"
+#include "src/tint/lang/core/type/vector.h"
using namespace tint::core::number_suffixes; // NOLINT
using namespace tint::core::fluent_types; // NOLINT
@@ -37,10 +39,11 @@
namespace tint::core::constant {
namespace {
-using ConstantTest_Composite = TestHelper;
+using ConstantTest_Composite = testing::Test;
TEST_F(ConstantTest_Composite, AllZero) {
- auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
+ Manager constants;
+ auto* vec3f = constants.types.vec(constants.types.f32(), 3u);
auto* fPos0 = constants.Get(0_f);
auto* fNeg0 = constants.Get(-0_f);
@@ -59,7 +62,8 @@
}
TEST_F(ConstantTest_Composite, AnyZero) {
- auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
+ Manager constants;
+ auto* vec3f = constants.types.vec(constants.types.f32(), 3u);
auto* fPos0 = constants.Get(0_f);
auto* fNeg0 = constants.Get(-0_f);
@@ -78,7 +82,8 @@
}
TEST_F(ConstantTest_Composite, Index) {
- auto* vec2f = create<core::type::Vector>(create<core::type::F32>(), 2u);
+ Manager constants;
+ auto* vec2f = constants.types.vec(constants.types.f32(), 2u);
auto* fPos0 = constants.Get(0_f);
auto* fPos1 = constants.Get(1_f);
@@ -96,7 +101,8 @@
}
TEST_F(ConstantTest_Composite, Clone) {
- auto* vec2f = create<core::type::Vector>(create<core::type::F32>(), 2u);
+ Manager constants;
+ auto* vec2f = constants.types.vec(constants.types.f32(), 2u);
auto* fPos0 = constants.Get(0_f);
auto* fPos1 = constants.Get(1_f);
diff --git a/src/tint/lang/core/constant/helper_test.h b/src/tint/lang/core/constant/helper_test.h
deleted file mode 100644
index 40873d6..0000000
--- a/src/tint/lang/core/constant/helper_test.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2023 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_LANG_CORE_CONSTANT_HELPER_TEST_H_
-#define SRC_TINT_LANG_CORE_CONSTANT_HELPER_TEST_H_
-
-#include "gtest/gtest.h"
-#include "src/tint/lang/wgsl/program/program_builder.h"
-
-namespace tint::core::constant {
-
-/// Helper base class for testing
-template <typename BASE>
-class TestHelperBase : public BASE, public ProgramBuilder {};
-
-/// Helper class for testing that derives from testing::Test.
-using TestHelper = TestHelperBase<testing::Test>;
-
-/// Helper class for testing that derives from `T`.
-template <typename T>
-using TestParamHelper = TestHelperBase<testing::TestWithParam<T>>;
-
-} // namespace tint::core::constant
-
-#endif // SRC_TINT_LANG_CORE_CONSTANT_HELPER_TEST_H_
diff --git a/src/tint/lang/core/constant/invalid_test.cc b/src/tint/lang/core/constant/invalid_test.cc
index b4f29f2..b3886c6 100644
--- a/src/tint/lang/core/constant/invalid_test.cc
+++ b/src/tint/lang/core/constant/invalid_test.cc
@@ -27,7 +27,7 @@
#include "src/tint/lang/core/constant/invalid.h"
-#include "src/tint/lang/core/constant/helper_test.h"
+#include "gtest/gtest.h"
#include "src/tint/lang/core/constant/scalar.h"
#include "src/tint/lang/core/fluent_types.h"
#include "src/tint/lang/core/type/clone_context.h"
@@ -38,19 +38,22 @@
namespace tint::core::constant {
namespace {
-using ConstantTest_Invalid = TestHelper;
+using ConstantTest_Invalid = testing::Test;
TEST_F(ConstantTest_Invalid, AllZero) {
+ Manager constants;
auto* invalid = constants.Invalid();
EXPECT_FALSE(invalid->AllZero());
}
TEST_F(ConstantTest_Invalid, AnyZero) {
+ Manager constants;
auto* invalid = constants.Invalid();
EXPECT_FALSE(invalid->AnyZero());
}
TEST_F(ConstantTest_Invalid, Index) {
+ Manager constants;
auto* invalid = constants.Invalid();
EXPECT_EQ(invalid->Index(0), nullptr);
EXPECT_EQ(invalid->Index(1), nullptr);
@@ -58,6 +61,7 @@
}
TEST_F(ConstantTest_Invalid, Clone) {
+ Manager constants;
auto* invalid = constants.Invalid();
constant::Manager mgr;
diff --git a/src/tint/lang/core/constant/scalar_test.cc b/src/tint/lang/core/constant/scalar_test.cc
index 581c94f..da0eb3a 100644
--- a/src/tint/lang/core/constant/scalar_test.cc
+++ b/src/tint/lang/core/constant/scalar_test.cc
@@ -27,16 +27,18 @@
#include "src/tint/lang/core/constant/scalar.h"
-#include "src/tint/lang/core/constant/helper_test.h"
+#include "gtest/gtest.h"
+#include "src/tint/lang/core/type/i32.h"
namespace tint::core::constant {
namespace {
using namespace tint::core::number_suffixes; // NOLINT
-using ConstantTest_Scalar = TestHelper;
+using ConstantTest_Scalar = testing::Test;
TEST_F(ConstantTest_Scalar, AllZero) {
+ Manager constants;
auto* i0 = constants.Get(0_i);
auto* iPos1 = constants.Get(1_i);
auto* iNeg1 = constants.Get(-1_i);
@@ -97,6 +99,7 @@
}
TEST_F(ConstantTest_Scalar, AnyZero) {
+ Manager constants;
auto* i0 = constants.Get(0_i);
auto* iPos1 = constants.Get(1_i);
auto* iNeg1 = constants.Get(-1_i);
@@ -157,6 +160,7 @@
}
TEST_F(ConstantTest_Scalar, ValueOf) {
+ Manager constants;
auto* i1 = constants.Get(1_i);
auto* u1 = constants.Get(1_u);
auto* f1 = constants.Get(1_f);
@@ -177,10 +181,11 @@
}
TEST_F(ConstantTest_Scalar, Clone) {
+ Manager constants;
auto* val = constants.Get(12_i);
- constant::Manager mgr;
- constant::CloneContext ctx{core::type::CloneContext{{nullptr}, {nullptr, &mgr.types}}, mgr};
+ Manager mgr;
+ CloneContext ctx{core::type::CloneContext{{nullptr}, {nullptr, &mgr.types}}, mgr};
auto* r = val->Clone(ctx);
ASSERT_NE(r, nullptr);
diff --git a/src/tint/lang/core/constant/splat_test.cc b/src/tint/lang/core/constant/splat_test.cc
index 10c67f2..6a6a3d3 100644
--- a/src/tint/lang/core/constant/splat_test.cc
+++ b/src/tint/lang/core/constant/splat_test.cc
@@ -27,9 +27,12 @@
#include "src/tint/lang/core/constant/splat.h"
-#include "src/tint/lang/core/constant/helper_test.h"
+#include "gtest/gtest.h"
#include "src/tint/lang/core/constant/scalar.h"
#include "src/tint/lang/core/fluent_types.h"
+#include "src/tint/lang/core/type/f32.h"
+#include "src/tint/lang/core/type/i32.h"
+#include "src/tint/lang/core/type/vector.h"
using namespace tint::core::number_suffixes; // NOLINT
using namespace tint::core::fluent_types; // NOLINT
@@ -37,10 +40,11 @@
namespace tint::core::constant {
namespace {
-using ConstantTest_Splat = TestHelper;
+using ConstantTest_Splat = testing::Test;
TEST_F(ConstantTest_Splat, AllZero) {
- auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
+ Manager constants;
+ auto* vec3f = constants.types.vec(constants.types.f32(), 3u);
auto* fPos0 = constants.Get(0_f);
auto* fNeg0 = constants.Get(-0_f);
@@ -56,7 +60,8 @@
}
TEST_F(ConstantTest_Splat, AnyZero) {
- auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
+ Manager constants;
+ auto* vec3f = constants.types.vec(constants.types.f32(), 3u);
auto* fPos0 = constants.Get(0_f);
auto* fNeg0 = constants.Get(-0_f);
@@ -72,7 +77,8 @@
}
TEST_F(ConstantTest_Splat, Index) {
- auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
+ Manager constants;
+ auto* vec3f = constants.types.vec(constants.types.f32(), 3u);
auto* f1 = constants.Get(1_f);
auto* sp = constants.Splat(vec3f, f1);
@@ -88,7 +94,8 @@
}
TEST_F(ConstantTest_Splat, Clone) {
- auto* vec2i = create<core::type::Vector>(create<core::type::I32>(), 2u);
+ Manager constants;
+ auto* vec2i = constants.types.vec(constants.types.i32(), 2u);
auto* val = constants.Get(12_i);
auto* sp = constants.Splat(vec2i, val);
diff --git a/src/tint/lang/core/constant/value_test.cc b/src/tint/lang/core/constant/value_test.cc
index 6bb31fd..e93fc8a 100644
--- a/src/tint/lang/core/constant/value_test.cc
+++ b/src/tint/lang/core/constant/value_test.cc
@@ -27,17 +27,20 @@
#include "src/tint/lang/core/constant/splat.h"
-#include "src/tint/lang/core/constant/helper_test.h"
+#include "gtest/gtest.h"
#include "src/tint/lang/core/constant/scalar.h"
+#include "src/tint/lang/core/type/f32.h"
+#include "src/tint/lang/core/type/vector.h"
namespace tint::core::constant {
namespace {
using namespace tint::core::number_suffixes; // NOLINT
-using ConstantTest_Value = TestHelper;
+using ConstantTest_Value = testing::Test;
TEST_F(ConstantTest_Value, Equal_Scalar_Scalar) {
+ Manager constants;
EXPECT_TRUE(constants.Get(10_i)->Equal(constants.Get(10_i)));
EXPECT_FALSE(constants.Get(10_i)->Equal(constants.Get(20_i)));
EXPECT_FALSE(constants.Get(20_i)->Equal(constants.Get(10_i)));
@@ -52,7 +55,8 @@
}
TEST_F(ConstantTest_Value, Equal_Splat_Splat) {
- auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
+ Manager constants;
+ auto* vec3f = constants.types.vec(constants.types.f32(), 3u);
auto* vec3f_1_1_1 = constants.Splat(vec3f, constants.Get(1_f));
auto* vec3f_2_2_2 = constants.Splat(vec3f, constants.Get(2_f));
@@ -63,7 +67,8 @@
}
TEST_F(ConstantTest_Value, Equal_Composite_Composite) {
- auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
+ Manager constants;
+ auto* vec3f = constants.types.vec(constants.types.f32(), 3u);
auto* vec3f_1_1_2 = constants.Composite(
vec3f, Vector{constants.Get(1_f), constants.Get(1_f), constants.Get(2_f)});
@@ -76,7 +81,8 @@
}
TEST_F(ConstantTest_Value, Equal_Splat_Composite) {
- auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
+ Manager constants;
+ auto* vec3f = constants.types.vec(constants.types.f32(), 3u);
auto* vec3f_1_1_1 = constants.Splat(vec3f, constants.Get(1_f));
auto* vec3f_1_2_1 = constants.Composite(