This does the matching of the actual vs expected values.
item
is the actual value. matchState
can be supplied
and may be used to add details about the mismatch that are too
costly to determine in describeMismatch
.
Source
bool matches(item, Map matchState) { if (item is! Function && item is! Future) return false; if (item is Future) { Invoker.current.addOutstandingCallback(); // Queue up an asynchronous expectation that validates when the future // completes. item.then((value) { fail("Expected future to fail, but succeeded with '$value'."); }, onError: (error, trace) { if (_matcher == null) return; var reason; if (trace != null) { var chain = terseChain(trace, verbose: Invoker.current.liveTest.test.metadata.verboseTrace); reason = "Actual exception trace:\n" " ${chain.toString().replaceAll("\n", "\n ")}"; } // Re-run [expect] to get the proper formatting. expect(() => throw error, this, reason: reason); }).then((_) => Invoker.current.removeOutstandingCallback()); // It hasn't failed yet. return true; } try { item(); return false; } catch (e, s) { if (_matcher == null || _matcher.matches(e, matchState)) { return true; } else { addStateInfo(matchState, {'exception': e, 'stack': s}); return false; } } }