[llvm] r256518 - [ADT] Don't use a fixture just to get a nonce type for this unittest.

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 28 12:03:16 PST 2015


Author: chandlerc
Date: Mon Dec 28 14:03:16 2015
New Revision: 256518

URL: http://llvm.org/viewvc/llvm-project?rev=256518&view=rev
Log:
[ADT] Don't use a fixture just to get a nonce type for this unittest.

Instead, actually produce a nonce type in the test and use that. This
makes the test, IMO, both simpler and more clear.

Modified:
    llvm/trunk/unittests/ADT/PointerIntPairTest.cpp

Modified: llvm/trunk/unittests/ADT/PointerIntPairTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/PointerIntPairTest.cpp?rev=256518&r1=256517&r2=256518&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/PointerIntPairTest.cpp (original)
+++ llvm/trunk/unittests/ADT/PointerIntPairTest.cpp Mon Dec 28 14:03:16 2015
@@ -14,35 +14,35 @@ using namespace llvm;
 
 namespace {
 
-// Test fixture
-class PointerIntPairTest : public testing::Test {
-};
-
-TEST_F(PointerIntPairTest, GetSet) {
-  PointerIntPair<PointerIntPairTest *, 2> Pair(this, 1U);
-  EXPECT_EQ(this, Pair.getPointer());
+TEST(PointerIntPairTest, GetSet) {
+  struct S {
+  };
+  S s;
+
+  PointerIntPair<S *, 2> Pair(&s, 1U);
+  EXPECT_EQ(&s, Pair.getPointer());
   EXPECT_EQ(1U, Pair.getInt());
 
   Pair.setInt(2);
-  EXPECT_EQ(this, Pair.getPointer());
+  EXPECT_EQ(&s, Pair.getPointer());
   EXPECT_EQ(2U, Pair.getInt());
 
   Pair.setPointer(nullptr);
   EXPECT_EQ(nullptr, Pair.getPointer());
   EXPECT_EQ(2U, Pair.getInt());
 
-  Pair.setPointerAndInt(this, 3U);
-  EXPECT_EQ(this, Pair.getPointer());
+  Pair.setPointerAndInt(&s, 3U);
+  EXPECT_EQ(&s, Pair.getPointer());
   EXPECT_EQ(3U, Pair.getInt());
 }
 
-TEST_F(PointerIntPairTest, DefaultInitialize) {
-  PointerIntPair<PointerIntPairTest *, 2> Pair;
+TEST(PointerIntPairTest, DefaultInitialize) {
+  PointerIntPair<float *, 2> Pair;
   EXPECT_EQ(nullptr, Pair.getPointer());
   EXPECT_EQ(0U, Pair.getInt());
 }
 
-TEST_F(PointerIntPairTest, ManyUnusedBits) {
+TEST(PointerIntPairTest, ManyUnusedBits) {
   // In real code this would be a word-sized integer limited to 31 bits.
   struct Fixnum31 {
     uintptr_t Value;




More information about the llvm-commits mailing list