This is an archive of the discontinued LLVM Phabricator instance.

[Testing/Support]: Better matching of Error failure states
ClosedPublic

Authored by labath on Mar 27 2018, 6:24 AM.

Details

Summary

The existing Failed() matcher only allowed asserting that the operation
failed, but it was not possible to verify any details of the returned
error.

This patch adds two new matchers, which make this possible:

  • Failed<InfoT>() verifies that the operation failed with a single error of a given type.
  • Failed<InfoT>(M) additionally check that the contained error info object is matched by the nested matcher M.

To make these work, I've changed the implementation of the ErrorHolder
class. Now, instead of just storing the string representation of the
Error, it fetches the ErrorInfo objects and stores then as a list of
shared pointers. This way, ErrorHolder remains copyable, while still
retaining the full information contained in the Error object.

In case the Error object contains two or more errors, the new matchers
will fail to match, instead of trying to match all (or any) of the
individual ErrorInfo objects. This seemed to be the most sensible
behavior for when one wants to match exact error details, but I could be
convinced otherwise...

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Mar 27 2018, 6:24 AM
zturner accepted this revision.Apr 4 2018, 11:30 AM
This revision is now accepted and ready to land.Apr 4 2018, 11:30 AM
This revision was automatically updated to reflect the committed changes.