[llvm] [NFC][ADT] Introduce a test harness for StringRefTest (PR #105500)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 07:03:43 PDT 2024


jurahul wrote:

> @jurahul could you explain why reverse iterator tests will need this test class?
> 
> Even if they do, we could make them use their test harness and leave the existing tests use test functions.

I want to use a helper template function in the test harness to help test all 4 flavors of iterators:

```
 template <bool Const, bool Forward>
 void TestIteration(void) {
   using StringRefTy = std::conditional_t<Const, const StringRef, StringRef>;
   StringRefTy S("Hello");

   auto [Begin, End] = [S]() {
     if constexpr (Forward)
       return std::make_pair(S.begin(), S.end());
     else
       return std::make_pair(S.rbegin(), S.rend());
   }();
   const char *Reference = Forward ? "Hello" : "olleH";
   for (auto II = Begin; II != End; ++II, ++Reference)
     EXPECT_EQ(*II, *Reference);
 };
```

I could add a harness just for this subtest, but then I am assuming it will be something like StringRefIteratorTest. and then the test name will be "StringRefIteratorTest.Forward" etc. I was attempting to keep the names uniform, but in hindsight that may not be important. OTOH, I do see other tests that use test harness, and when they do, it seems to be used uniformly throughout the test, irrespective of whether the subtest actually uses anything from the harness. For example, StringSetTest has an empty harness, and SmallStringTest has a harness and some tests that do not use anything from the harness.

I guess having a single harness helps keep the test name same throughout the test, but that's not a requirement. I am assuming if there is atest harness, you cannot use TEST(SameNameAsHarness).

https://github.com/llvm/llvm-project/pull/105500


More information about the llvm-commits mailing list