mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Extract ANSI escape sequence to a function
This commit is contained in:
@ -194,3 +194,16 @@ if (! function_exists('afterAll')) {
|
||||
TestSuite::getInstance()->afterAll->set($closure);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('removeAnsiEscapeSequences')) {
|
||||
/**
|
||||
* Remove ANSI escape sequences from a given string.
|
||||
*
|
||||
* @param string $input The string containing ANSI escape sequences.
|
||||
* @return string|null A new string with all ANSI escape sequences removed.
|
||||
*/
|
||||
function removeAnsiEscapeSequences(string $input): ?string
|
||||
{
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $input);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ test('collision', function (array $arguments) {
|
||||
|
||||
$process->run();
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
$outputContent = explode("\n", $output());
|
||||
|
||||
@ -6,7 +6,7 @@ test('visual snapshot of help command output', function () {
|
||||
|
||||
$process->run();
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
expect($output())->toMatchSnapshot();
|
||||
|
||||
@ -11,7 +11,7 @@ $run = function () {
|
||||
|
||||
$process->run();
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
test('parallel', function () use ($run) {
|
||||
|
||||
@ -9,7 +9,7 @@ $run = function (string $target, $decorated = false) {
|
||||
|
||||
$process->run();
|
||||
|
||||
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return $decorated ? $process->getOutput() : removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
$snapshot = function ($name) {
|
||||
|
||||
@ -11,9 +11,7 @@ $run = function (string $target, bool $parallel) {
|
||||
|
||||
expect($process->getExitCode())->toBe(0);
|
||||
|
||||
$outputContent = preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
|
||||
return $outputContent;
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
$snapshot = function ($name) {
|
||||
|
||||
@ -6,7 +6,7 @@ test('visual snapshot of help command output', function () {
|
||||
|
||||
$process->run();
|
||||
|
||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
return removeAnsiEscapeSequences($process->getOutput());
|
||||
};
|
||||
|
||||
expect($output())->toMatchSnapshot();
|
||||
|
||||
Reference in New Issue
Block a user