Skip to content

Commit

Permalink
Refactor matchers.
Browse files Browse the repository at this point in the history
Many matchers define convenience wrappers for both string-like types and for `::testing::Matcher<string>`, where the wrappers for string-like types instantiates our own internal `NameMatcher` that gives nice messages specific to IR names. Because string-like types are also convertible to `::testing::Matcher<string>`, this often led to cases where the overload was ambiguous. This change defines wrappers using the following pattern:

```
template <typename T>
inline ::testing::Matcher<Node*> Wrapper(..., T name, ...) requires(std::is_convertible_v<T, std::string_view>) {
  return WrappedMatcher(..., internal::NameMatcher(std::string_view{T}), ...);
}
```

resolving the ambiguous overload to prefer using the `NameMatcher`. Also, we remove many cases where an argument had `std::optional<T> arg = std::nullopt` and instead make an overload with `T` and another overload without the argument to aid template deduction.

For `FunctionBase` matchers we tweak how `MatchAndExplain()` are defined for bare pointers (don't need to be templated) vs. `std::unique_ptr<>` (template them on `std::is_base_of<FunctionBase, T>`).

PiperOrigin-RevId: 611554596
  • Loading branch information
grebe authored and copybara-github committed Feb 29, 2024
1 parent e1ab8b6 commit 4190b35
Showing 1 changed file with 189 additions and 119 deletions.
Loading

0 comments on commit 4190b35

Please sign in to comment.