From 2272c815e7fe9a9da49d6e4a1bdaa7b1945761c0 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:02:34 +0100 Subject: [PATCH 01/28] typo --- documentation/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/index.md b/documentation/index.md index a36b556..4e36d0b 100644 --- a/documentation/index.md +++ b/documentation/index.md @@ -8,7 +8,7 @@ hide: BlackBox is a [Property Based Testing](https://en.wikipedia.org/wiki/Software_testing#Property_testing) framework. -It leverages randomness ti prove the correctness of your code. +It leverages randomness to prove the correctness of your code. It's the main testing framework for the [Innmind ecosystem](https://innmind.github.io/documentation/). From 0bdae7ba94ab44eeb4916f168bb09dcf32ab1bb9 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:04:31 +0100 Subject: [PATCH 02/28] add failing test to iterate on the failing output in the github action --- proofs/application.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/proofs/application.php b/proofs/application.php index 3efac60..cd87ca7 100644 --- a/proofs/application.php +++ b/proofs/application.php @@ -12,6 +12,11 @@ }; return static function() { + yield test( + 'Failing on purpose', + static fn($assert) => $assert->true(false), + ); + yield proof( 'BlackBox can run with any of the random strategies', given(Set\Elements::of(...Random::cases())), From 3e37bd298f9964accac945ceaded3806086ff04d Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:04:57 +0100 Subject: [PATCH 03/28] print all the env variables available in the CI --- proofs/application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/proofs/application.php b/proofs/application.php index cd87ca7..195aeda 100644 --- a/proofs/application.php +++ b/proofs/application.php @@ -16,6 +16,7 @@ 'Failing on purpose', static fn($assert) => $assert->true(false), ); + var_dump(getenv()); yield proof( 'BlackBox can run with any of the random strategies', From 89b688bc966d7f556ae6d0c37b10a8c0e8ffddd3 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:07:04 +0100 Subject: [PATCH 04/28] Revert "print all the env variables available in the CI" This reverts commit 3e37bd298f9964accac945ceaded3806086ff04d. --- proofs/application.php | 1 - 1 file changed, 1 deletion(-) diff --git a/proofs/application.php b/proofs/application.php index 195aeda..cd87ca7 100644 --- a/proofs/application.php +++ b/proofs/application.php @@ -16,7 +16,6 @@ 'Failing on purpose', static fn($assert) => $assert->true(false), ); - var_dump(getenv()); yield proof( 'BlackBox can run with any of the random strategies', From 5cfef5e450c575771c16390eb8f78bf9be6fb723 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:11:41 +0100 Subject: [PATCH 05/28] add tag on failing test --- proofs/application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proofs/application.php b/proofs/application.php index cd87ca7..685747f 100644 --- a/proofs/application.php +++ b/proofs/application.php @@ -15,7 +15,7 @@ yield test( 'Failing on purpose', static fn($assert) => $assert->true(false), - ); + )->tag(Tag::ci); yield proof( 'BlackBox can run with any of the random strategies', From ae18986b80328ab40f70e4fb34c24f8972a54c8b Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:15:33 +0100 Subject: [PATCH 06/28] group each proof in github actions --- src/Runner/Printer/Proof/Standard.php | 26 +++++++++++++++++++++----- src/Runner/Printer/Standard.php | 22 ++++++++++++++++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index ce1cee1..8f766c1 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -25,25 +25,37 @@ final class Standard implements Proof private CliDumper $dumper; private VarCloner $cloner; private bool $addMarks; + private bool $addGroups; private int $scenarii = 0; - private function __construct(bool $withColors, bool $addMarks) - { + private function __construct( + bool $withColors, + bool $addMarks, + bool $addGroups, + ) { $this->dumper = new CliDumper; $this->cloner = new VarCloner; $this->addMarks = $addMarks; + $this->addGroups = $addGroups; $this->dumper->setColors($withColors); $this->cloner->setMinDepth(100); } - public static function new(bool $withColors, bool $addMarks): self - { - return new self($withColors, $addMarks); + public static function new( + bool $withColors, + bool $addMarks, + bool $addGroups, + ): self { + return new self($withColors, $addMarks, $addGroups); } public function emptySet(IO $output, IO $error): void { $error("No scenario found\n"); + + if ($this->addGroups) { + $output("::endgroup::\n"); + } } public function success(IO $output, IO $error): void @@ -126,6 +138,10 @@ public function failed(IO $output, IO $error, Failure $failure): void public function end(IO $output, IO $error): void { $output("\n\n"); + + if ($this->addGroups) { + $output("::endgroup::\n"); + } } private function newLine(IO $output): void diff --git a/src/Runner/Printer/Standard.php b/src/Runner/Printer/Standard.php index 591ccf7..3da3dba 100644 --- a/src/Runner/Printer/Standard.php +++ b/src/Runner/Printer/Standard.php @@ -19,12 +19,14 @@ final class Standard implements Printer private Timer $timer; private bool $withColors; private bool $addMarks; + private bool $addGroups; private function __construct(bool $withColors) { $this->timer = new Timer; $this->withColors = $withColors; $this->addMarks = \getenv('LC_TERMINAL') === 'iTerm2'; + $this->addGroups = \getenv('GITHUB_ACTIONS') === 'true'; } /** @@ -53,17 +55,29 @@ public function proof( Proof\Name $proof, array $tags, ): Printer\Proof { + $header = ''; + foreach ($tags as $tag) { - $output("[{$tag->name}]"); + $header .= "[{$tag->name}]"; } if (\count($tags) > 0) { - $output(' '); + $header .= ' '; } - $output($proof->toString().":\n"); + $header .= $proof->toString().":\n"; + + if ($this->addGroups) { + $header = '::group::'.$header; + } - return Printer\Proof\Standard::new($this->withColors, $this->addMarks); + $output($header); + + return Printer\Proof\Standard::new( + $this->withColors, + $this->addMarks, + $this->addGroups, + ); } public function end(IO $output, IO $error, Stats $stats): void From 120ab85da582e0a0e10e4ffce918cd17cd7b1f31 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:20:59 +0100 Subject: [PATCH 07/28] attempt to display error messages for failing proofs --- src/Runner/Printer/Proof/Standard.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 8f766c1..3531e4b 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -133,6 +133,10 @@ public function failed(IO $output, IO $error, Failure $failure): void $frame['line'], )); } + + if ($this->addGroups) { + $output("::error ::Failing proof"); + } } public function end(IO $output, IO $error): void From ca9378f4188da840d963d3606681fc0739c89a0f Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:27:13 +0100 Subject: [PATCH 08/28] display error message after the proof group --- src/Runner/Printer/Proof/Standard.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 3531e4b..765604f 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -27,6 +27,7 @@ final class Standard implements Proof private bool $addMarks; private bool $addGroups; private int $scenarii = 0; + private bool $failed = false; private function __construct( bool $withColors, @@ -134,9 +135,7 @@ public function failed(IO $output, IO $error, Failure $failure): void )); } - if ($this->addGroups) { - $output("::error ::Failing proof"); - } + $this->failed = true; } public function end(IO $output, IO $error): void @@ -145,6 +144,10 @@ public function end(IO $output, IO $error): void if ($this->addGroups) { $output("::endgroup::\n"); + + if ($this->failed) { + $output("::error ::Failing proof 👆"); + } } } From c5adb3830e9e10d46705ae736f52e5ecdd02621a Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:28:01 +0100 Subject: [PATCH 09/28] add missing line feed --- src/Runner/Printer/Proof/Standard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 765604f..7f41f10 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -146,7 +146,7 @@ public function end(IO $output, IO $error): void $output("::endgroup::\n"); if ($this->failed) { - $output("::error ::Failing proof 👆"); + $output("::error ::Failing proof 👆\n"); } } } From 9397a43723875fd54d85ce88c2415b50d902b4a6 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:34:50 +0100 Subject: [PATCH 10/28] add github action printer proofs --- proofs/runner/printer.php | 79 +++++++++++++++++++++++++++++++-- src/Runner/Printer/Standard.php | 24 +++++++--- 2 files changed, 95 insertions(+), 8 deletions(-) diff --git a/proofs/runner/printer.php b/proofs/runner/printer.php index fa61cd5..b1c3336 100644 --- a/proofs/runner/printer.php +++ b/proofs/runner/printer.php @@ -136,7 +136,7 @@ static function($assert, $proofs, $scenarii, $assertions, $failures) { Set\Sequence::of(Set\Elements::of(...Tag::cases())), ), static function($assert, $name, $tags) { - $printer = Standard::new(); + $printer = Standard::new()->disableGitHubOutput(); $io = Collect::new(); $printer->proof($io, $io, Name::of($name), $tags); @@ -154,8 +154,9 @@ static function($assert, $name, $tags) { ->contains($name); }, )->tag(Tag::ci, Tag::local); + yield proof( - 'Printer->proof()->emptySet()', + 'Printer->proof() in GitHub Action', given( Set\Strings::any(), Set\Sequence::of(Set\Elements::of(...Tag::cases())), @@ -164,6 +165,33 @@ static function($assert, $name, $tags) { $printer = Standard::new(); $io = Collect::new(); + $printer->proof($io, $io, Name::of($name), $tags); + + $written = $io->toString(); + + foreach ($tags as $tag) { + $assert + ->string($written) + ->contains($tag->name); + } + + $assert + ->string($written) + ->startsWith('::group::') + ->contains($name); + }, + )->tag(Tag::ci); + + yield proof( + 'Printer->proof()->emptySet()', + given( + Set\Strings::any(), + Set\Sequence::of(Set\Elements::of(...Tag::cases())), + ), + static function($assert, $name, $tags) { + $printer = Standard::new()->disableGitHubOutput(); + $io = Collect::new(); + $printer ->proof($io, $io, Name::of($name), $tags) ->emptySet($io, $io); @@ -175,6 +203,29 @@ static function($assert, $name, $tags) { ->same(\end($written)); }, )->tag(Tag::ci, Tag::local); + + yield proof( + 'Printer->proof()->emptySet() in GitHub Action', + given( + Set\Strings::any(), + Set\Sequence::of(Set\Elements::of(...Tag::cases())), + ), + static function($assert, $name, $tags) { + $printer = Standard::new(); + $io = Collect::new(); + + $printer + ->proof($io, $io, Name::of($name), $tags) + ->emptySet($io, $io); + + $written = $io->written(); + + $assert + ->expected("No scenario found\n::endgroup::\n") + ->same(\end($written)); + }, + )->tag(Tag::ci); + yield proof( 'Printer->proof()->success()', given( @@ -397,7 +448,7 @@ static function($assert, $name, $message) { Set\Sequence::of(Set\Elements::of(...Tag::cases())), ), static function($assert, $name, $tags) { - $printer = Standard::new(); + $printer = Standard::new()->disableGitHubOutput(); $io = Collect::new(); $printer @@ -411,4 +462,26 @@ static function($assert, $name, $tags) { ->same(\end($written)); }, )->tag(Tag::ci, Tag::local); + + yield proof( + 'Printer->proof()->end() in GitHub Action', + given( + Set\Strings::any(), + Set\Sequence::of(Set\Elements::of(...Tag::cases())), + ), + static function($assert, $name, $tags) { + $printer = Standard::new(); + $io = Collect::new(); + + $printer + ->proof($io, $io, Name::of($name), $tags) + ->end($io, $io); + + $written = $io->written(); + + $assert + ->expected("\n\n::endgroup::\n") + ->same(\end($written)); + }, + )->tag(Tag::ci, Tag::local); }; diff --git a/src/Runner/Printer/Standard.php b/src/Runner/Printer/Standard.php index 3da3dba..6ce535e 100644 --- a/src/Runner/Printer/Standard.php +++ b/src/Runner/Printer/Standard.php @@ -21,12 +21,16 @@ final class Standard implements Printer private bool $addMarks; private bool $addGroups; - private function __construct(bool $withColors) - { - $this->timer = new Timer; + private function __construct( + bool $withColors, + ?Timer $timer = null, + ?bool $addMarks = null, + ?bool $addGroups = null, + ) { + $this->timer = $timer ?? new Timer; $this->withColors = $withColors; - $this->addMarks = \getenv('LC_TERMINAL') === 'iTerm2'; - $this->addGroups = \getenv('GITHUB_ACTIONS') === 'true'; + $this->addMarks = $addMarks ?? \getenv('LC_TERMINAL') === 'iTerm2'; + $this->addGroups = $addGroups ?? \getenv('GITHUB_ACTIONS') === 'true'; } /** @@ -42,6 +46,16 @@ public static function withoutColors(): self return new self(false); } + public function disableGitHubGrouping(): self + { + return new self( + $this->withColors, + $this->timer, + $this->addMarks, + false, + ); + } + public function start(IO $output, IO $error): void { $this->timer->start(); From 82dcf4f02a2d5f3e9a4d9d2cb4b63ba0bf5fecbd Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:38:38 +0100 Subject: [PATCH 11/28] fix method name --- proofs/runner/printer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proofs/runner/printer.php b/proofs/runner/printer.php index b1c3336..16e4936 100644 --- a/proofs/runner/printer.php +++ b/proofs/runner/printer.php @@ -136,7 +136,7 @@ static function($assert, $proofs, $scenarii, $assertions, $failures) { Set\Sequence::of(Set\Elements::of(...Tag::cases())), ), static function($assert, $name, $tags) { - $printer = Standard::new()->disableGitHubOutput(); + $printer = Standard::new()->disableGitHubGrouping(); $io = Collect::new(); $printer->proof($io, $io, Name::of($name), $tags); @@ -189,7 +189,7 @@ static function($assert, $name, $tags) { Set\Sequence::of(Set\Elements::of(...Tag::cases())), ), static function($assert, $name, $tags) { - $printer = Standard::new()->disableGitHubOutput(); + $printer = Standard::new()->disableGitHubGrouping(); $io = Collect::new(); $printer @@ -448,7 +448,7 @@ static function($assert, $name, $message) { Set\Sequence::of(Set\Elements::of(...Tag::cases())), ), static function($assert, $name, $tags) { - $printer = Standard::new()->disableGitHubOutput(); + $printer = Standard::new()->disableGitHubGrouping(); $io = Collect::new(); $printer From 44565b1cf508f6ac59c350554c2c2e8feeaefd99 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:42:35 +0100 Subject: [PATCH 12/28] remove unwanted tag --- proofs/runner/printer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proofs/runner/printer.php b/proofs/runner/printer.php index 16e4936..102f1ae 100644 --- a/proofs/runner/printer.php +++ b/proofs/runner/printer.php @@ -483,5 +483,5 @@ static function($assert, $name, $tags) { ->expected("\n\n::endgroup::\n") ->same(\end($written)); }, - )->tag(Tag::ci, Tag::local); + )->tag(Tag::ci); }; From 19368319fe0a67e293e104b8672669fdbcf4a45a Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:46:00 +0100 Subject: [PATCH 13/28] fix github action output proofs --- proofs/runner/printer.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/proofs/runner/printer.php b/proofs/runner/printer.php index 102f1ae..d9db395 100644 --- a/proofs/runner/printer.php +++ b/proofs/runner/printer.php @@ -218,11 +218,11 @@ static function($assert, $name, $tags) { ->proof($io, $io, Name::of($name), $tags) ->emptySet($io, $io); - $written = $io->written(); + $written = \implode('', $io->written()); $assert - ->expected("No scenario found\n::endgroup::\n") - ->same(\end($written)); + ->string($written) + ->endsWith("No scenario found\n::endgroup::\n"); }, )->tag(Tag::ci); @@ -477,11 +477,11 @@ static function($assert, $name, $tags) { ->proof($io, $io, Name::of($name), $tags) ->end($io, $io); - $written = $io->written(); + $written = \implode('', $io->written()); $assert - ->expected("\n\n::endgroup::\n") - ->same(\end($written)); + ->string($written) + ->endsWith("\n\n::endgroup::\n"); }, )->tag(Tag::ci); }; From b5d111f5647b455bcefa3368929621bac5160808 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:50:34 +0100 Subject: [PATCH 14/28] experiment with custome error title --- src/Runner/Printer/Proof/Standard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 7f41f10..0d45cd6 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -146,7 +146,7 @@ public function end(IO $output, IO $error): void $output("::endgroup::\n"); if ($this->failed) { - $output("::error ::Failing proof 👆\n"); + $output("::error title=Error title::Failing proof 👆\n"); } } } From cdd156cf7a34428eaa37b233d1be750d0c454d22 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:56:31 +0100 Subject: [PATCH 15/28] Revert "experiment with custome error title" This reverts commit b5d111f5647b455bcefa3368929621bac5160808. --- src/Runner/Printer/Proof/Standard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 0d45cd6..7f41f10 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -146,7 +146,7 @@ public function end(IO $output, IO $error): void $output("::endgroup::\n"); if ($this->failed) { - $output("::error title=Error title::Failing proof 👆\n"); + $output("::error ::Failing proof 👆\n"); } } } From ee8aaa3fe6483f598790ef17c4cc9ed24b92aeb3 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 18:58:46 +0100 Subject: [PATCH 16/28] display the proof name in the github error message for better navigation --- src/Runner/Printer/Proof/Standard.php | 7 +++++-- src/Runner/Printer/Standard.php | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 7f41f10..c4bafaa 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -24,12 +24,14 @@ final class Standard implements Proof { private CliDumper $dumper; private VarCloner $cloner; + private string $proof; private bool $addMarks; private bool $addGroups; private int $scenarii = 0; private bool $failed = false; private function __construct( + string $proof, bool $withColors, bool $addMarks, bool $addGroups, @@ -43,11 +45,12 @@ private function __construct( } public static function new( + string $proof, bool $withColors, bool $addMarks, bool $addGroups, ): self { - return new self($withColors, $addMarks, $addGroups); + return new self($proof, $withColors, $addMarks, $addGroups); } public function emptySet(IO $output, IO $error): void @@ -146,7 +149,7 @@ public function end(IO $output, IO $error): void $output("::endgroup::\n"); if ($this->failed) { - $output("::error ::Failing proof 👆\n"); + $output("::error ::{$this->proof} failed 👆\n"); } } } diff --git a/src/Runner/Printer/Standard.php b/src/Runner/Printer/Standard.php index 6ce535e..7201c42 100644 --- a/src/Runner/Printer/Standard.php +++ b/src/Runner/Printer/Standard.php @@ -88,6 +88,7 @@ public function proof( $output($header); return Printer\Proof\Standard::new( + $proof->toString(), $this->withColors, $this->addMarks, $this->addGroups, From 65b2e9b28296114dc8283267fba60796d44c4e43 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:01:20 +0100 Subject: [PATCH 17/28] fix unassigned property --- src/Runner/Printer/Proof/Standard.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index c4bafaa..0f03b5c 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -38,6 +38,7 @@ private function __construct( ) { $this->dumper = new CliDumper; $this->cloner = new VarCloner; + $this->proof = $proof; $this->addMarks = $addMarks; $this->addGroups = $addGroups; $this->dumper->setColors($withColors); From 4384fb6d8d3bc0d404a6b5fdf60037b0293a7eb3 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:05:39 +0100 Subject: [PATCH 18/28] add emojis to better see the error message in long outputs --- src/Runner/Printer/Proof/Standard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 0f03b5c..527fe3a 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -150,7 +150,7 @@ public function end(IO $output, IO $error): void $output("::endgroup::\n"); if ($this->failed) { - $output("::error ::{$this->proof} failed 👆\n"); + $output("::error ::🚨 {$this->proof} failed 🚨\n"); } } } From af81d68533453143ffd2a926a066e696b3413f90 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:11:58 +0100 Subject: [PATCH 19/28] render the github error inside the group in order to open the group when the annotation is clicked --- src/Runner/Printer/Proof/Standard.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 527fe3a..986a44e 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -28,7 +28,6 @@ final class Standard implements Proof private bool $addMarks; private bool $addGroups; private int $scenarii = 0; - private bool $failed = false; private function __construct( string $proof, @@ -103,6 +102,8 @@ public function failed(IO $output, IO $error, Failure $failure): void $output("\x1b]1337;SetMark\x07"); } + $githubErrorRendered = false; + foreach ($trace as $frame) { if (!\array_key_exists('file', $frame)) { continue; @@ -132,14 +133,22 @@ public function failed(IO $output, IO $error, Failure $failure): void continue; } + if ($this->addGroups && !$githubErrorRendered) { + $output(\sprintf( + '::error file=%s,line=%s,title=%s::', + $frame['file'], + $frame['line'], + $this->proof, + )); + $githubErrorRendered = true; + } + $output(\sprintf( "%s:%s\n", $frame['file'], $frame['line'], )); } - - $this->failed = true; } public function end(IO $output, IO $error): void @@ -148,10 +157,6 @@ public function end(IO $output, IO $error): void if ($this->addGroups) { $output("::endgroup::\n"); - - if ($this->failed) { - $output("::error ::🚨 {$this->proof} failed 🚨\n"); - } } } From 9011059b99624ea21ec13417d21f8e3af865c608 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:15:22 +0100 Subject: [PATCH 20/28] remove file and line from the error as it redirects to the commit --- src/Runner/Printer/Proof/Standard.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 986a44e..b9c50f4 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -135,9 +135,7 @@ public function failed(IO $output, IO $error, Failure $failure): void if ($this->addGroups && !$githubErrorRendered) { $output(\sprintf( - '::error file=%s,line=%s,title=%s::', - $frame['file'], - $frame['line'], + '::error title=%s::', $this->proof, )); $githubErrorRendered = true; From 59fa6e65e9fb6b019c98a05bf5ef9f4f2c8935ce Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:20:02 +0100 Subject: [PATCH 21/28] render the error on the failure message --- src/Runner/Printer/Proof/Standard.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index b9c50f4..88d314b 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -85,7 +85,11 @@ public function failed(IO $output, IO $error, Failure $failure): void $this->renderFailure($output, $failure->assertion()->kind()); $output(\sprintf( - "\n%s\n", + "\n%s%s\n", + match ($this->addGroups) { + true => '::error ::', + false => '', + }, $failure->assertion()->kind()->message(), )); @@ -102,8 +106,6 @@ public function failed(IO $output, IO $error, Failure $failure): void $output("\x1b]1337;SetMark\x07"); } - $githubErrorRendered = false; - foreach ($trace as $frame) { if (!\array_key_exists('file', $frame)) { continue; @@ -133,14 +135,6 @@ public function failed(IO $output, IO $error, Failure $failure): void continue; } - if ($this->addGroups && !$githubErrorRendered) { - $output(\sprintf( - '::error title=%s::', - $this->proof, - )); - $githubErrorRendered = true; - } - $output(\sprintf( "%s:%s\n", $frame['file'], From 8142c835e54627b449bd944926ad8f742eb80470 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:27:29 +0100 Subject: [PATCH 22/28] remove unused property --- src/Runner/Printer/Proof/Standard.php | 6 +----- src/Runner/Printer/Standard.php | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Runner/Printer/Proof/Standard.php b/src/Runner/Printer/Proof/Standard.php index 88d314b..89e4067 100644 --- a/src/Runner/Printer/Proof/Standard.php +++ b/src/Runner/Printer/Proof/Standard.php @@ -24,20 +24,17 @@ final class Standard implements Proof { private CliDumper $dumper; private VarCloner $cloner; - private string $proof; private bool $addMarks; private bool $addGroups; private int $scenarii = 0; private function __construct( - string $proof, bool $withColors, bool $addMarks, bool $addGroups, ) { $this->dumper = new CliDumper; $this->cloner = new VarCloner; - $this->proof = $proof; $this->addMarks = $addMarks; $this->addGroups = $addGroups; $this->dumper->setColors($withColors); @@ -45,12 +42,11 @@ private function __construct( } public static function new( - string $proof, bool $withColors, bool $addMarks, bool $addGroups, ): self { - return new self($proof, $withColors, $addMarks, $addGroups); + return new self($withColors, $addMarks, $addGroups); } public function emptySet(IO $output, IO $error): void diff --git a/src/Runner/Printer/Standard.php b/src/Runner/Printer/Standard.php index 7201c42..6ce535e 100644 --- a/src/Runner/Printer/Standard.php +++ b/src/Runner/Printer/Standard.php @@ -88,7 +88,6 @@ public function proof( $output($header); return Printer\Proof\Standard::new( - $proof->toString(), $this->withColors, $this->addMarks, $this->addGroups, From bd15c9a36844da7bdeda0629f58cc02cbb282278 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:30:27 +0100 Subject: [PATCH 23/28] add proofs for github ouput on failing proofs --- proofs/runner/printer.php | 124 +++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 3 deletions(-) diff --git a/proofs/runner/printer.php b/proofs/runner/printer.php index d9db395..b5e42cf 100644 --- a/proofs/runner/printer.php +++ b/proofs/runner/printer.php @@ -276,7 +276,7 @@ static function($assert, $name, $tags) { Set\Strings::any(), ), static function($assert, $name, $val, $truth) { - $printer = Standard::new(); + $printer = Standard::new()->disableGitHubGrouping(); $io = Collect::new(); $printer @@ -299,6 +299,40 @@ static function($assert, $name, $val, $truth) { ->contains($truth); }, )->tag(Tag::ci, Tag::local); + + yield proof( + 'Printer->proof()->failure() for Failure\Truth in GitHub Action', + given( + Set\Strings::any(), + Set\Strings::madeOf(Set\Chars::alphanumerical()), + Set\Strings::any(), + ), + static function($assert, $name, $val, $truth) { + $printer = Standard::new(); + $io = Collect::new(); + + $printer + ->proof($io, $io, Name::of($name), []) + ->failed($io, $io, Failure::of( + Assert\Failure::of(Truth::of($truth)), + Value::immutable(Scenario\Inline::of( + [$val], + static fn($assert, $foo) => null, + )), + )); + + $written = $io->toString(); + + $assert + ->string($written) + ->contains("F\n\n") + ->contains('$foo = ') + ->contains($val) + ->contains('::error ::') + ->contains($truth); + }, + )->tag(Tag::ci); + yield proof( 'Printer->proof()->failure() for Failure\Property', given( @@ -308,7 +342,7 @@ static function($assert, $name, $val, $truth) { Set\Strings::any(), ), static function($assert, $name, $property, $val, $message) { - $printer = Standard::new(); + $printer = Standard::new()->disableGitHubGrouping(); $io = Collect::new(); $printer @@ -336,6 +370,46 @@ static function($assert, $name, $property, $val, $message) { ->contains($message); }, )->tag(Tag::ci, Tag::local); + + yield proof( + 'Printer->proof()->failure() for Failure\Property in GitHub Action', + given( + Set\Strings::any(), + Set\Strings::madeOf(Set\Chars::alphanumerical()), + Set\Strings::madeOf(Set\Chars::alphanumerical()), + Set\Strings::any(), + ), + static function($assert, $name, $property, $val, $message) { + $printer = Standard::new(); + $io = Collect::new(); + + $printer + ->proof($io, $io, Name::of($name), []) + ->failed($io, $io, Failure::of( + Assert\Failure::of(Property::of( + $property, + $message, + )), + Value::immutable(Scenario\Inline::of( + [$val], + static fn($assert, $foo) => null, + )), + )); + + $written = $io->toString(); + + $assert + ->string($written) + ->contains("F\n\n") + ->contains('$variable = ') + ->contains($property) + ->contains('$foo = ') + ->contains($val) + ->contains('::error ::') + ->contains($message); + }, + )->tag(Tag::ci); + yield proof( 'Printer->proof()->failure() for Failure\Comparison', given( @@ -346,7 +420,7 @@ static function($assert, $name, $property, $val, $message) { Set\Strings::any(), ), static function($assert, $name, $expected, $actual, $val, $message) { - $printer = Standard::new(); + $printer = Standard::new()->disableGitHubGrouping(); $io = Collect::new(); $printer @@ -377,6 +451,50 @@ static function($assert, $name, $expected, $actual, $val, $message) { ->contains($message); }, )->tag(Tag::ci, Tag::local); + + yield proof( + 'Printer->proof()->failure() for Failure\Comparison in GitHub Action', + given( + Set\Strings::any(), + Set\Strings::madeOf(Set\Chars::alphanumerical()), + Set\Strings::madeOf(Set\Chars::alphanumerical()), + Set\Strings::madeOf(Set\Chars::alphanumerical()), + Set\Strings::any(), + ), + static function($assert, $name, $expected, $actual, $val, $message) { + $printer = Standard::new(); + $io = Collect::new(); + + $printer + ->proof($io, $io, Name::of($name), []) + ->failed($io, $io, Failure::of( + Assert\Failure::of(Comparison::of( + $expected, + $actual, + $message, + )), + Value::immutable(Scenario\Inline::of( + [$val], + static fn($assert, $foo) => null, + )), + )); + + $written = $io->toString(); + + $assert + ->string($written) + ->contains("F\n\n") + ->contains('$expected = ') + ->contains($expected) + ->contains('$actual = ') + ->contains($actual) + ->contains('$foo = ') + ->contains($val) + ->contains('::error ::') + ->contains($message); + }, + )->tag(Tag::ci); + yield proof( 'Printer->proof()->failure() for Scenario\Property', given( From a79be3f64e1a7375630d704c2c9943537b1c1ac3 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:31:36 +0100 Subject: [PATCH 24/28] rename disableGitHubGrouping to disableGitHubOutput --- proofs/runner/printer.php | 12 ++++++------ src/Runner/Printer/Standard.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/proofs/runner/printer.php b/proofs/runner/printer.php index b5e42cf..8d12fcd 100644 --- a/proofs/runner/printer.php +++ b/proofs/runner/printer.php @@ -136,7 +136,7 @@ static function($assert, $proofs, $scenarii, $assertions, $failures) { Set\Sequence::of(Set\Elements::of(...Tag::cases())), ), static function($assert, $name, $tags) { - $printer = Standard::new()->disableGitHubGrouping(); + $printer = Standard::new()->disableGitHubOutput(); $io = Collect::new(); $printer->proof($io, $io, Name::of($name), $tags); @@ -189,7 +189,7 @@ static function($assert, $name, $tags) { Set\Sequence::of(Set\Elements::of(...Tag::cases())), ), static function($assert, $name, $tags) { - $printer = Standard::new()->disableGitHubGrouping(); + $printer = Standard::new()->disableGitHubOutput(); $io = Collect::new(); $printer @@ -276,7 +276,7 @@ static function($assert, $name, $tags) { Set\Strings::any(), ), static function($assert, $name, $val, $truth) { - $printer = Standard::new()->disableGitHubGrouping(); + $printer = Standard::new()->disableGitHubOutput(); $io = Collect::new(); $printer @@ -342,7 +342,7 @@ static function($assert, $name, $val, $truth) { Set\Strings::any(), ), static function($assert, $name, $property, $val, $message) { - $printer = Standard::new()->disableGitHubGrouping(); + $printer = Standard::new()->disableGitHubOutput(); $io = Collect::new(); $printer @@ -420,7 +420,7 @@ static function($assert, $name, $property, $val, $message) { Set\Strings::any(), ), static function($assert, $name, $expected, $actual, $val, $message) { - $printer = Standard::new()->disableGitHubGrouping(); + $printer = Standard::new()->disableGitHubOutput(); $io = Collect::new(); $printer @@ -566,7 +566,7 @@ static function($assert, $name, $message) { Set\Sequence::of(Set\Elements::of(...Tag::cases())), ), static function($assert, $name, $tags) { - $printer = Standard::new()->disableGitHubGrouping(); + $printer = Standard::new()->disableGitHubOutput(); $io = Collect::new(); $printer diff --git a/src/Runner/Printer/Standard.php b/src/Runner/Printer/Standard.php index 6ce535e..5a0ed8f 100644 --- a/src/Runner/Printer/Standard.php +++ b/src/Runner/Printer/Standard.php @@ -46,7 +46,7 @@ public static function withoutColors(): self return new self(false); } - public function disableGitHubGrouping(): self + public function disableGitHubOutput(): self { return new self( $this->withColors, From 21e5068dbbbd2a122b32f7dbff37bb3616c10cae Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:32:49 +0100 Subject: [PATCH 25/28] update changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a574d4..cf29d35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [Unreleased] + +### Added + +- By default the printer groups the proofs output in a GitHub Action +- `Innmind\BlackBox\Runner\Printer\Standard::disableGitHubOutput()` + ## 5.8.0 - 2024-11-09 ### Added From 1652d6de510431a45cdc4597f6122bf48a3e26d4 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:37:36 +0100 Subject: [PATCH 26/28] add documentation on how to disable github output --- documentation/config.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/documentation/config.md b/documentation/config.md index 9dc6132..42b867d 100644 --- a/documentation/config.md +++ b/documentation/config.md @@ -92,3 +92,22 @@ Application::new([]) ->tryToProve(Load::everythingIn('proofs/')) ->exit(); ``` + +## Disable GitHub Action output + +When it detects it's run inside a GitHub Action the framework groups each proof output to make the output more compact for large suites. It also adds annotations to quickly jump to each failing proof. + +You can disable such behaviour like this: + +```php hl_lines="4 8" +use Innmind\BlackBox\{ + Application, + Runner\Load, + Runner\Printer\Standard, +}; + +Application::new([]) + ->usePrinter(Standard::new()->disableGitHubOutput()) + ->tryToProve(Load::everythingIn('proofs/')) + ->exit(); +``` From c4b7f440955f0650d60c980bbf8821d031fde2cd Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:37:54 +0100 Subject: [PATCH 27/28] remove failing test --- proofs/application.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/proofs/application.php b/proofs/application.php index 685747f..3efac60 100644 --- a/proofs/application.php +++ b/proofs/application.php @@ -12,11 +12,6 @@ }; return static function() { - yield test( - 'Failing on purpose', - static fn($assert) => $assert->true(false), - )->tag(Tag::ci); - yield proof( 'BlackBox can run with any of the random strategies', given(Set\Elements::of(...Random::cases())), From d61bbb4b9cf7eb00fb68db41559e6127fc727a51 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Fri, 29 Nov 2024 19:52:31 +0100 Subject: [PATCH 28/28] specify next release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf29d35..1092307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [Unreleased] +## 5.9.0 - 2024-11-29 ### Added