diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-03-22 08:57:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-22 08:57:04 -0700 |
commit | 0ad4e27eb563947ec981757370eaccdab8102cb4 (patch) | |
tree | c5bdf97d27534247964bc0c016afc11f859bfa99 | |
parent | 321e40c246800d80845a0ed77d50b41ffb54286a (diff) | |
download | binaryen-0ad4e27eb563947ec981757370eaccdab8102cb4.tar.gz binaryen-0ad4e27eb563947ec981757370eaccdab8102cb4.tar.bz2 binaryen-0ad4e27eb563947ec981757370eaccdab8102cb4.zip |
[NFC] Move type system test fixture to its own header (#4539)
Allow the fixture to be shared with other test .cpp files we might add in the
future.
-rw-r--r-- | test/gtest/type-builder.cpp | 32 | ||||
-rw-r--r-- | test/gtest/type-test.h | 40 |
2 files changed, 41 insertions, 31 deletions
diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp index 99bec48bf..c81a4ac19 100644 --- a/test/gtest/type-builder.cpp +++ b/test/gtest/type-builder.cpp @@ -1,40 +1,10 @@ +#include "type-test.h" #include "wasm-type-printing.h" #include "wasm-type.h" #include "gtest/gtest.h" using namespace wasm; -// Helper test fixture for managing the global type system state. -template<TypeSystem system> class TypeSystemTest : public ::testing::Test { - TypeSystem originalSystem; - -protected: - void SetUp() override { - originalSystem = getTypeSystem(); - setTypeSystem(system); - } - void TearDown() override { - destroyAllTypesForTestingPurposesOnly(); - setTypeSystem(originalSystem); - } - - // Utilities - Struct makeStruct(TypeBuilder& builder, - std::initializer_list<size_t> indices) { - FieldList fields; - for (auto index : indices) { - Type ref = builder.getTempRefType(builder[index], Nullable); - fields.emplace_back(ref, Mutable); - } - return Struct(std::move(fields)); - } -}; - -using TypeTest = TypeSystemTest<TypeSystem::Equirecursive>; -using EquirecursiveTest = TypeSystemTest<TypeSystem::Equirecursive>; -using NominalTest = TypeSystemTest<TypeSystem::Nominal>; -using IsorecursiveTest = TypeSystemTest<TypeSystem::Isorecursive>; - TEST_F(TypeTest, TypeBuilderGrowth) { TypeBuilder builder; EXPECT_EQ(builder.size(), 0u); diff --git a/test/gtest/type-test.h b/test/gtest/type-test.h new file mode 100644 index 000000000..1860efeab --- /dev/null +++ b/test/gtest/type-test.h @@ -0,0 +1,40 @@ +#include "wasm-type.h" +#include "gtest/gtest.h" + +#ifndef wasm_test_gtest_type_test_h +#define wasm_test_gtest_type_test_h + +// Helper test fixture for managing the global type system state. +template<wasm::TypeSystem system> +class TypeSystemTest : public ::testing::Test { + wasm::TypeSystem originalSystem; + +protected: + void SetUp() override { + originalSystem = wasm::getTypeSystem(); + wasm::setTypeSystem(system); + } + void TearDown() override { + wasm::destroyAllTypesForTestingPurposesOnly(); + wasm::setTypeSystem(originalSystem); + } + + // Utilities + wasm::Struct makeStruct(wasm::TypeBuilder& builder, + std::initializer_list<size_t> indices) { + using namespace wasm; + FieldList fields; + for (auto index : indices) { + Type ref = builder.getTempRefType(builder[index], Nullable); + fields.emplace_back(ref, Mutable); + } + return Struct(std::move(fields)); + } +}; + +using TypeTest = TypeSystemTest<wasm::TypeSystem::Equirecursive>; +using EquirecursiveTest = TypeSystemTest<wasm::TypeSystem::Equirecursive>; +using NominalTest = TypeSystemTest<wasm::TypeSystem::Nominal>; +using IsorecursiveTest = TypeSystemTest<wasm::TypeSystem::Isorecursive>; + +#endif // wasm_test_gtest_type_test_h |