diff options
author | Schrodinger ZHU Yifan <yifanzhu@rochester.edu> | 2024-01-23 10:43:24 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-23 10:43:24 -0500 |
commit | 2cff46f8c0aa88222aba776de094c650aa09a33d (patch) | |
tree | 71cb09193b0f8893890f6d2adbc251b9c5dbc081 | |
parent | dffa8039b10823f67347453a0ef445ee785ed4aa (diff) | |
download | llvm-2cff46f8c0aa88222aba776de094c650aa09a33d.zip llvm-2cff46f8c0aa88222aba776de094c650aa09a33d.tar.gz llvm-2cff46f8c0aa88222aba776de094c650aa09a33d.tar.bz2 |
[libc][NFC] use builder pattern for ErrnoSetterMatcher (#79153)
ErrnoSetterMatcher::returns can be misleading as it does not initialize
the errno. This is made worse as later on there is a switch statement on
the errno comparator using __builtin_unreachable(). This patch make
ErrnoSetterMatcher::returns give back a builder that is nomially
different from ErrnoSetterMatcher.
-rw-r--r-- | libc/test/UnitTest/ErrnoSetterMatcher.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/libc/test/UnitTest/ErrnoSetterMatcher.h b/libc/test/UnitTest/ErrnoSetterMatcher.h index b748c29..6b15bd4 100644 --- a/libc/test/UnitTest/ErrnoSetterMatcher.h +++ b/libc/test/UnitTest/ErrnoSetterMatcher.h @@ -161,10 +161,22 @@ static internal::ErrnoSetterMatcher<RetT> Fails(int ExpectedErrno, EQ(ExpectedErrno)); } +template <typename RetT = int> class ErrnoSetterMatcherBuilder { +public: + template <typename T> using Cmp = internal::Comparator<T>; + ErrnoSetterMatcherBuilder(Cmp<RetT> cmp) : return_cmp(cmp) {} + + internal::ErrnoSetterMatcher<RetT> with_errno(Cmp<int> cmp) { + return internal::ErrnoSetterMatcher<RetT>(return_cmp, cmp); + } + +private: + Cmp<RetT> return_cmp; +}; + template <typename RetT> -static internal::ErrnoSetterMatcher<RetT> -returns(internal::Comparator<RetT> cmp) { - return internal::ErrnoSetterMatcher<RetT>(cmp); +static ErrnoSetterMatcherBuilder<RetT> returns(internal::Comparator<RetT> cmp) { + return ErrnoSetterMatcherBuilder<RetT>(cmp); } } // namespace ErrnoSetterMatcher |