softCheck<T> function

CheckFailure? softCheck<T>(
  1. T value,
  2. Condition<T> condition
)

Checks whether value satisfies all expectations invoked in condition, without throwing an exception.

Returns null if all expectations are satisfied, otherwise returns the CheckFailure for the first expectation that fails.

Asynchronous expectations are not allowed in condition and will cause a runtime error if they are used.

Implementation

CheckFailure? softCheck<T>(T value, Condition<T> condition) {
  CheckFailure? failure;
  final subject = Subject<T>._(_TestContext._root(
    value: _Present(value),
    fail: (f) {
      failure ??= f;
    },
    allowAsync: false,
    allowUnawaited: false,
  ));
  condition(subject);
  return failure;
}