Skip to content

Commit

Permalink
Beautify tests generation and fix list test
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrech committed Apr 5, 2024
1 parent 93c4568 commit 4227b51
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
43 changes: 35 additions & 8 deletions bin/generate-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
$fs->remove(__DIR__ . '/../tests/Examples/Generated');
$fs->mkdir(__DIR__ . '/../tests/Examples/Generated');

displayTitle('Retrieving example tasks');

$application = ApplicationFactory::create();
$application->setAutoExit(false);
$application
Expand All @@ -36,6 +38,10 @@
throw new RuntimeException('Could not get the list of commands. You probably break something:' . $json, previous: $e);
}

echo "\nDone.\n";

displayTitle('Generating tests for example tasks');

$taskFilterList = [
'_complete',
'completion',
Expand Down Expand Up @@ -89,6 +95,7 @@
'pyrech:foobar',
];
$optionFilterList = array_flip(['help', 'quiet', 'verbose', 'version', 'ansi', 'no-ansi', 'no-interaction', 'context', 'no-remote', 'update-remotes']);

foreach ($applicationDescription['commands'] as $task) {
if (in_array($task['name'], $taskFilterList, true)) {
continue;
Expand Down Expand Up @@ -123,15 +130,28 @@
add_test($args, $class);
}

$dirs = (new Finder())
->in($basePath = __DIR__ . '/../tests/Examples/fixtures/broken')
->depth(1)
;
foreach ($dirs as $dir) {
$class = u($dir->getRelativePath())->camel()->title()->toString();
add_test([], $class, '{{ base }}/tests/Examples/fixtures/broken/' . $dir->getRelativePath(), true);
echo "\nDone.\n";

displayTitle('Generating tests for fixtures');

foreach (['broken', 'valid'] as $type) {
$dirs = (new Finder())
->in($basePath = __DIR__ . '/../tests/Examples/fixtures/' . $type)
->depth(1)
;

foreach ($dirs as $dir) {
echo "Generating test for {$type} fixture " . basename(dirname($dir)) . "\n";

$class = u($dir->getRelativePath())->camel()->title()->toString();
add_test([], $class, '{{ base }}/tests/Examples/fixtures/' . $type . '/' . $dir->getRelativePath(), true);
}
}

echo "\nDone.\n";

displayTitle('Generating additional tests');

add_test(['args:passthru', 'a', 'b', '--no', '--foo', 'bar', '-x'], 'ArgPassthruExpanded');
add_test(['context:context', '--context', 'dynamic'], 'ContextContextDynamic');
add_test(['context:context', '--context', 'my_default', '-v'], 'ContextContextMyDefault');
Expand All @@ -140,7 +160,7 @@
add_test(['context:context', '--context', 'production'], 'ContextContextProduction');
add_test(['context:context', '--context', 'run'], 'ContextContextRun');
add_test(['enabled:hello', '--context', 'production'], 'EnabledInProduction');
add_test(['list', '--raw', '--format', 'txt', '--short'], 'List', skipOnBinary: true);
add_test(['list', '--raw', '--format', 'txt', '--short'], 'List', needRemote: true, skipOnBinary: true);
// Transient test, disabled for now
// add_test(['parallel:sleep', '--sleep5', '0', '--sleep7', '0', '--sleep10', '0'], 'ParallelSleep');
add_test(['symfony:greet', 'World', '--french', 'COUCOU', '--punctuation', '!'], 'SymfonyGreet', skipOnBinary: true);
Expand All @@ -154,6 +174,8 @@
add_test(['list'], 'LayoutWithFolder', '{{ base }}/tests/Examples/fixtures/layout/with-folder');
add_test(['list'], 'LayoutWithOldFolder', '{{ base }}/tests/Examples/fixtures/layout/with-old-folder');

echo "\nDone.\n";

function add_test(array $args, string $class, ?string $cwd = null, bool $needRemote = false, bool $skipOnBinary = false)
{
$class .= 'Test';
Expand Down Expand Up @@ -209,6 +231,11 @@ function add_test(array $args, string $class, ?string $cwd = null, bool $needRem
}
}

function displayTitle(string $title)
{
echo "\n-- {$title} --\n\n";
}

__halt_compiler();
<?php

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

use function Castor\import;

import('composer://pyrech/castor-example');
import('composer://pyrech/castor-example', file: 'castor.php');

0 comments on commit 4227b51

Please sign in to comment.