Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure the debug flag is not forwarded #43

Merged
merged 4 commits into from
Oct 6, 2023
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
26 changes: 26 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ jobs:
- name: "Run tests"
run: "make phpunit"

debug-test:
runs-on: "ubuntu-latest"
name: "Tests with PHP ${{ matrix.php }} and the make `--debug` flag"
strategy:
fail-fast: true
matrix:
php:
- "8.1"

steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"

- name: "Setup PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
tools: "composer"

- name: "Install Composer dependencies"
uses: "ramsey/composer-install@v2"

- name: "Run tests"
run: "make phpunit --debug"

infection:
runs-on: "ubuntu-latest"
name: "Infection with PHP ${{ matrix.php }}"
Expand Down Expand Up @@ -70,6 +95,7 @@ jobs:
runs-on: ubuntu-latest
needs:
- tests
- debug-test
- infection
if: always()
steps:
Expand Down
10 changes: 10 additions & 0 deletions infection.json.dist → infection.json5.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@
"mutators": {
"@default": true,
"MBString": false,
"global-ignore": [
"Fidry\\Makefile\\Test\\BaseMakefileTestCase::getNonDebugMakeFlags"
],

"CastString": {
"ignore": [
// Testing that getenv() does not return a string is difficult there.
"Fidry\\Makefile\\Test\\BaseMakefileTestCase::getNonDebugMakeFlags"
]
},
"FunctionCallRemoval": {
"ignore": [
"Fidry\\Makefile\\Test\\BaseMakefileTestCase::executeCommand",
"Fidry\\Makefile\\Test\\BaseMakefileTestCase::executeInDirectory"
]
},
Expand Down
22 changes: 22 additions & 0 deletions src/Test/BaseMakefileTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@
use Fidry\Makefile\Rule;
use PHPUnit\Framework\TestCase;
use Safe\Exceptions\ExecException;
use function array_filter;
use function dirname;
use function error_clear_last;
use function explode;
use function function_exists;
use function getenv;
use function implode;
use function Safe\chdir;
use function Safe\file_get_contents;
use function Safe\getcwd;
Expand Down Expand Up @@ -129,6 +133,12 @@ final protected static function executeMakeCommand(string $commandName): string
// TODO: remove this as we remove support for PHP 7.4 and Safe v1
final protected static function executeCommand(string $command): string
{
$command = sprintf(
'MAKEFLAGS="%s" %s',
self::getNonDebugMakeFlags(),
$command,
);

if (function_exists('Safe\shell_exec')) {
return shell_exec($command);
}
Expand All @@ -144,6 +154,18 @@ final protected static function executeCommand(string $command): string
return $safeResult;
}

final protected static function getNonDebugMakeFlags(): string
{
$makeFlags = (string) getenv('MAKEFLAGS');

$nonDebugFlags = array_filter(
explode(' ', $makeFlags),
static fn (string $flag) => !str_starts_with($flag, '--debug='),
);

return implode(' ', $nonDebugFlags);
}

private static function getTimeout(): string
{
try {
Expand Down