Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Added

- `Innmind\BlackBox\Application::filterOnTags()`

## 6.11.0 - 2026-03-18

### Added
Expand Down
2 changes: 2 additions & 0 deletions blackbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Runner\Load,
Runner\CodeCoverage,
Runner\IO\Collect,
Tag,
};
use function Innmind\BlackBox\Runner\test;

Expand Down Expand Up @@ -54,6 +55,7 @@
->enableWhen(true),
),
'extensive' => $app->scenariiPerProof(1000),
'lab_station' => $app->filterOnTags(Tag::local),
default => $app,
})
->tryToProve(Load::everythingIn(__DIR__.'/proofs/'))
Expand Down
29 changes: 29 additions & 0 deletions proofs/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,33 @@ static function($assert, $i) {
->contains('$i = 0');
},
)->tag(Tag::ci, Tag::local);

yield test(
'Application::filterOnTags()',
static function($assert) {
$io = Collect::new();

$result = Application::new([])
->displayOutputVia($io)
->displayErrorVia($io)
->usePrinter(Standard::withoutColors())
->filterOnTags(Tag::local)
->tryToProve(static function() {
yield test(
'example',
static fn($assert) => $assert->true(true),
)->tag(Tag::local);

yield test(
'example',
static fn($assert) => $assert->true(true),
)->tag(Tag::ci);
});

$assert->true($result->successful());
$assert
->string($io->toString())
->contains('Proofs: 1, Scenarii: 1');
},
)->tag(Tag::ci, Tag::local);
};
53 changes: 51 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ final class Application
private bool $disableMemoryLimit;
private bool $stopOnFailure;
private bool $failWhenNoAssertions;
/** @var ?list<\UnitEnum> */
private ?array $tags;

/**
* @param \Closure(string): ?\UnitEnum $parseTag
* @param list<string> $args
* @param int<1, max> $scenariiPerProof
* @param ?list<\UnitEnum> $tags
*/
private function __construct(
Random $random,
Expand All @@ -55,6 +58,7 @@ private function __construct(
bool $disableMemoryLimit,
bool $stopOnFailure,
bool $failWhenNoAssertions,
?array $tags,
) {
$this->random = $random;
$this->printer = $printer;
Expand All @@ -69,6 +73,7 @@ private function __construct(
$this->disableMemoryLimit = $disableMemoryLimit;
$this->stopOnFailure = $stopOnFailure;
$this->failWhenNoAssertions = $failWhenNoAssertions;
$this->tags = $tags;
}

/**
Expand All @@ -91,6 +96,7 @@ public static function new(array $args): self
false,
false,
true,
null,
);
}

Expand All @@ -114,6 +120,7 @@ public function useRandom(Random $random): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -137,6 +144,7 @@ public function usePrinter(Printer $printer): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -160,6 +168,7 @@ public function displayOutputVia(IO $output): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -183,6 +192,7 @@ public function displayErrorVia(IO $error): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -206,6 +216,7 @@ public function disableShrinking(): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -231,6 +242,7 @@ public function useExhaustiveShrinking(): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -256,6 +268,7 @@ public function parseTagWith(callable $parser): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -281,6 +294,7 @@ public function scenariiPerProof(int $count): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -304,6 +318,7 @@ public function codeCoverage(CodeCoverage $codeCoverage): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -327,6 +342,7 @@ public function disableGlobalFunctions(): self
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -350,6 +366,7 @@ public function disableMemoryLimit(): self
true,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -373,6 +390,7 @@ public function stopOnFailure(): self
$this->disableMemoryLimit,
true,
$this->failWhenNoAssertions,
$this->tags,
);
}

Expand All @@ -396,6 +414,32 @@ public function allowProofsToNotMakeAnyAssertions(): self
$this->disableMemoryLimit,
$this->stopOnFailure,
false,
$this->tags,
);
}

/**
* @psalm-mutation-free
* @no-named-arguments
*/
#[\NoDiscard]
public function filterOnTags(\UnitEnum ...$tags): self
{
return new self(
$this->random,
$this->printer,
$this->output,
$this->error,
$this->runner,
$this->parseTag,
$this->codeCoverage,
$this->args,
$this->scenariiPerProof,
$this->useGlobalFunctions,
$this->disableMemoryLimit,
$this->stopOnFailure,
$this->failWhenNoAssertions,
$tags,
);
}

Expand Down Expand Up @@ -435,8 +479,13 @@ public function tryToProve(callable $proofs): Result
require_once __DIR__.'/Runner/global.php';
}

$tags = \array_map($this->parseTag, $this->args);
$tags = \array_filter($tags, static fn($tag) => $tag instanceof \UnitEnum);
if (\is_null($this->tags)) {
$tags = \array_map($this->parseTag, $this->args);
$tags = \array_filter($tags, static fn($tag) => $tag instanceof \UnitEnum);
} else {
$tags = $this->tags;
}

$filter = Filter::new()->onTags(...$tags);

$run = Runner::of(
Expand Down
Loading