diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-01-20 16:39:27 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 16:39:27 -0800 |
commit | 060442225165d0423d06ea33ab865e850b54f61b (patch) | |
tree | b18e210cef9b1106caf8cbdaea186ce232cb0721 /test | |
parent | 93f69e5805a5476a60d2b593c24e80c5fce779e7 (diff) | |
download | binaryen-060442225165d0423d06ea33ab865e850b54f61b.tar.gz binaryen-060442225165d0423d06ea33ab865e850b54f61b.tar.bz2 binaryen-060442225165d0423d06ea33ab865e850b54f61b.zip |
Reset global type state between tests (#4468)
Add a `destroyAllTypes` function to clear the global state of the type system
and use it in a custom gtest test fixture to ensure that each test starts and
ends with a fresh state.
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest/type-builder.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp index 37e47c148..49221f667 100644 --- a/test/gtest/type-builder.cpp +++ b/test/gtest/type-builder.cpp @@ -3,6 +3,24 @@ 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); + } +}; +using EquirecursiveTest = TypeSystemTest<TypeSystem::Equirecursive>; +using NominalTest = TypeSystemTest<TypeSystem::Nominal>; +using IsorecursiveTest = TypeSystemTest<TypeSystem::Isorecursive>; + TEST(TypeBuilder, Growth) { TypeBuilder builder; EXPECT_EQ(builder.size(), size_t{0}); @@ -10,11 +28,10 @@ TEST(TypeBuilder, Growth) { EXPECT_EQ(builder.size(), size_t{3}); } -TEST(TypeBuilder, Basics) { +TEST_F(EquirecursiveTest, Basics) { // (type $sig (func (param (ref $struct)) (result (ref $array) i32))) // (type $struct (struct (field (ref null $array) (mut rtt 0 $array)))) // (type $array (array (mut externref))) - TypeBuilder builder(3); ASSERT_EQ(builder.size(), size_t{3}); |