Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop: (28 commits)
  specify next release
  remove failing test
  add documentation on how to disable github output
  update changelog
  rename disableGitHubGrouping to disableGitHubOutput
  add proofs for github ouput on failing proofs
  remove unused property
  render the error on the failure message
  remove file and line from the error as it redirects to the commit
  render the github error inside the group in order to open the group when the annotation is clicked
  add emojis to better see the error message in long outputs
  fix unassigned property
  display the proof name in the github error message for better navigation
  Revert "experiment with custome error title"
  experiment with custome error title
  fix github action output proofs
  remove unwanted tag
  fix method name
  add github action printer proofs
  add missing line feed
  ...
  • Loading branch information
Baptouuuu committed Nov 29, 2024
2 parents f184bd8 + d61bbb4 commit d36e707
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 21 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 5.9.0 - 2024-11-29

### 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
Expand Down
19 changes: 19 additions & 0 deletions documentation/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```
2 changes: 1 addition & 1 deletion documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).

Expand Down
203 changes: 197 additions & 6 deletions proofs/runner/printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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())),
Expand All @@ -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);
Expand All @@ -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 = \implode('', $io->written());

$assert
->string($written)
->endsWith("No scenario found\n::endgroup::\n");
},
)->tag(Tag::ci);

yield proof(
'Printer->proof()->success()',
given(
Expand Down Expand Up @@ -225,7 +276,7 @@ static function($assert, $name, $tags) {
Set\Strings::any(),
),
static function($assert, $name, $val, $truth) {
$printer = Standard::new();
$printer = Standard::new()->disableGitHubOutput();
$io = Collect::new();

$printer
Expand All @@ -248,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(
Expand All @@ -257,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()->disableGitHubOutput();
$io = Collect::new();

$printer
Expand Down Expand Up @@ -285,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(
Expand All @@ -295,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()->disableGitHubOutput();
$io = Collect::new();

$printer
Expand Down Expand Up @@ -326,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(
Expand Down Expand Up @@ -397,7 +566,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
Expand All @@ -411,4 +580,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 = \implode('', $io->written());

$assert
->string($written)
->endsWith("\n\n::endgroup::\n");
},
)->tag(Tag::ci);
};
32 changes: 26 additions & 6 deletions src/Runner/Printer/Proof/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,7 +81,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(),
));

Expand Down Expand Up @@ -126,6 +142,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
Expand Down
Loading

0 comments on commit d36e707

Please sign in to comment.