You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
package:checks: Add prints expectation for checking captured output #2742
In package:matcher, prints(...) captures print statements during callback execution via ZoneSpecification(print: ...) and validates the printed output against a string or matcher:
expect(() =>print("hello"), prints("hello\n"));
In package:checks, there is currently no direct replacement for prints. The migration document (pkgs/checks/doc/migrating_from_matcher.md) lists:
- prints: TODO add missing expectation? Is this one worth replacing?
Migrating tests that assert on console or logging output requires either maintaining a dependency on package:matcher / package:test/expect.dart or writing custom runZoned capture boilerplate.
Proposed Solution
Add a prints expectation extension on Subject<void Function()> (and async callback subjects) that executes the callback in a Zone intercepting print(), collects the output, and provides a Subject<String> or accepts a condition on the captured output.
Example usage:
check(() {
print("hello");
}).prints(it()..equals("hello\n"));
// Or with string containment / pattern matching:check(() {
print("foo");
print("bar");
}).prints(it()..contains("foo"));
Acceptance Criteria
Provide a prints expectation on synchronous and asynchronous callback Subjects.
Capture all print invocations executed within the callback body using a ZoneSpecification.
Provide a nested Subject<String> for the concatenated printed output to allow chaining standard String checks (equals, contains, matchesPattern, etc.).
Support both synchronous (void Function()) and asynchronous (FutureOr<void> Function()) callbacks.
Update pkgs/checks/doc/migrating_from_matcher.md to document the replacement.
Activity
feat(checks): add prints expectations (dart-lang#2742) (dart-lang#2743)