test(BCMathTest): add debug output and fix formatting issues #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test bcpowmod on Windows PHP 8.4 | |
| on: | |
| workflow_dispatch: | |
| push: | |
| pull_request: | |
| jobs: | |
| test-bcpowmod: | |
| runs-on: windows-latest | |
| strategy: | |
| matrix: | |
| php: ['8.4'] | |
| name: PHP ${{ matrix.php }} - ${{ matrix.arch }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| extensions: bcmath | |
| coverage: none | |
| - name: Display environment info | |
| run: | | |
| echo "=== System Information ===" | |
| echo "OS: $env:OS" | |
| echo "PROCESSOR_ARCHITECTURE: $env:PROCESSOR_ARCHITECTURE" | |
| echo "PROCESSOR_ARCHITEW6432: $env:PROCESSOR_ARCHITEW6432" | |
| echo "" | |
| echo "=== PHP Information ===" | |
| php -v | |
| php -r "echo 'PHP_INT_SIZE: ' . PHP_INT_SIZE . ' (bytes)' . PHP_EOL;" | |
| php -r "echo 'PHP_INT_MAX: ' . PHP_INT_MAX . PHP_EOL;" | |
| php -r "echo 'Architecture: ' . php_uname('m') . PHP_EOL;" | |
| php -r "echo 'bcmath extension: ' . (extension_loaded('bcmath') ? 'Loaded' : 'Not loaded') . PHP_EOL;" | |
| - name: Test bcpowmod with PHP | |
| run: | | |
| echo "=== Testing bcpowmod('-9', '1024', '123') ===" | |
| php -r "echo 'Result: ' . var_export(bcpowmod('-9', '1024', '123'), true) . PHP_EOL;" | |
| # More detailed test | |
| php -r "`$result = bcpowmod('-9', '1024', '123'); echo 'bcpowmod result type: ' . gettype(`$result) . PHP_EOL; echo 'bcpowmod result value: ' . `$result . PHP_EOL; echo 'Expected value: 42' . PHP_EOL; echo 'Test ' . (`$result === '42' ? 'PASSED' : 'FAILED') . PHP_EOL;" | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| architecture: ${{ matrix.arch }} | |
| - name: Test with Python for comparison | |
| run: | | |
| echo "=== Testing with Python ===" | |
| python -c "import platform; print(f'Python version: {platform.python_version()}'); print(f'Python architecture: {platform.machine()}'); print(f'Python platform: {platform.platform()}'); print(); result = pow(-9, 1024, 123); print(f'Python pow(-9, 1024, 123) = {result}'); print(f'Expected value: 42'); print(f'Test {\"PASSED\" if result == 42 else \"FAILED\"}')" | |
| - name: Compare results | |
| run: | | |
| echo "=== Summary ===" | |
| $phpResult = php -r "echo bcpowmod('-9', '1024', '123');" | |
| $pythonResult = python -c "print(pow(-9, 1024, 123))" | |
| echo "PHP bcpowmod result: $phpResult" | |
| echo "Python pow result: $pythonResult" | |
| echo "Expected result: 42" | |
| if ($phpResult -eq "42") { | |
| echo "✅ PHP result is correct" | |
| } else { | |
| echo "❌ PHP result is incorrect (got $phpResult, expected 42)" | |
| } | |
| if ($pythonResult -eq "42") { | |
| echo "✅ Python result is correct" | |
| } else { | |
| echo "❌ Python result is incorrect (got $pythonResult, expected 42)" | |
| } | |
| if ($phpResult -ne $pythonResult) { | |
| echo "⚠️ PHP and Python results differ!" | |
| echo "This suggests a platform-specific issue with PHP's bcmath extension" | |
| } | |
| - name: Additional debugging info | |
| if: always() | |
| run: | | |
| echo "=== Additional Debug Information ===" | |
| # Check if running on 32-bit or 64-bit | |
| php -r "echo 'Is 32-bit PHP: ' . (PHP_INT_SIZE === 4 ? 'Yes' : 'No') . PHP_EOL; echo 'Is 64-bit PHP: ' . (PHP_INT_SIZE === 8 ? 'Yes' : 'No') . PHP_EOL;" | |
| # Test a few more cases | |
| echo "" | |
| echo "=== Testing other bcpowmod cases ===" | |
| php -r "echo 'bcpowmod(\"9\", \"1024\", \"123\") = ' . bcpowmod('9', '1024', '123') . PHP_EOL; echo 'bcpowmod(\"-9\", \"2\", \"123\") = ' . bcpowmod('-9', '2', '123') . PHP_EOL; echo 'bcpowmod(\"-9\", \"4\", \"123\") = ' . bcpowmod('-9', '4', '123') . PHP_EOL;" |