diff --git a/CHANGELOG.md b/CHANGELOG.md index 92f9f2c..4d274ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ ### Changed - Requires `phpunit/php-code-coverage` `~14.2` to avoid using deprecated code +- +### Fixed + +- `$assert->debug()` was leaking the last successful shrunk values ## 7.0.0 - 2026-05-14 diff --git a/proofs/application.php b/proofs/application.php index 32632e3..8a51161 100644 --- a/proofs/application.php +++ b/proofs/application.php @@ -5,8 +5,10 @@ Application, Random, Set, + Runner\Assert, Runner\Load, Runner\IO\Collect, + Prove, Tag, }; use Fixtures\Innmind\BlackBox\{ @@ -20,7 +22,7 @@ UpperBoundAtHundred, }; -return static function($prove) { +return static function(Prove $prove) { yield $prove ->proof('BlackBox can run with any of the random strategies') ->given(Set::of(...Random::cases())) @@ -607,4 +609,36 @@ static function($assert) { }, ) ->tag(Tag::ci, Tag::local); + + yield $prove + ->test( + '$assert->debug() does not leak the last successful shrunk value', + static function($assert) { + $io = Collect::new(); + + $result = Application::new([]) + ->displayVia($io) + ->mapPrinter(static fn($printer) => $printer->withoutColors()) + ->tryToProve(static function(Prove $prove) { + yield $prove + ->proof('debug') + ->given(Set::integers()->above(0)) + ->test(static function(Assert $assert, $i) { + $assert->debug('shrunk', $i); + + if ($i > 0) { + $assert->true(false); + } + + $assert->true(true); + }); + }); + + $assert->false($result->successful()); + $assert + ->string($io->toString()) + ->contains('$shrunk = 1'); + }, + ) + ->tag(Tag::ci, Tag::local); }; diff --git a/src/Runner/Assert/Debug.php b/src/Runner/Assert/Debug.php index 015613a..432efd2 100644 --- a/src/Runner/Assert/Debug.php +++ b/src/Runner/Assert/Debug.php @@ -29,6 +29,16 @@ public function reset(): void $this->data = []; } + /** + * @internal + */ + public function snapshot(): self + { + $snapshot = new self($this->data); + + return $snapshot; + } + /** * @internal * diff --git a/src/Runner/Runner/Strategy.php b/src/Runner/Runner/Strategy.php index 7124022..ffcf076 100644 --- a/src/Runner/Runner/Strategy.php +++ b/src/Runner/Runner/Strategy.php @@ -62,6 +62,7 @@ private function shrink( ): void { $identity = $this->hash($previousFailure); $previousStrategy = $scenario; + $previousDebug = $debug; $dichotomy = $scenario->shrink(); do { @@ -69,7 +70,7 @@ private function shrink( throw Scenario\Failure::of( $previousFailure, $previousStrategy, - $debug, + $previousDebug, ); } @@ -114,6 +115,7 @@ private function shrink( $dichotomy = null; } catch (Assert\Failure $e) { $dichotomy = $currentStrategy->shrink(); + $previousDebug = $debug->snapshot(); $previousFailure = $e; $previousStrategy = $currentStrategy;