Skip to content

Commit

Permalink
Add support for custom test runner for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Apr 4, 2024
1 parent 22e7ccb commit 0e0e7e0
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
description: 'Run tests after building the extension'
required: false
default: 'false'
test-runner:
description: 'Test runner to use'
required: false
default: 'run-tests.php'
artifact-naming-scheme:
description: 'Naming schema for the artifacts, pie or pecl'
required: false
Expand Down Expand Up @@ -51,6 +55,7 @@ jobs:
arch: ${{ matrix.arch }}
ts: ${{ matrix.ts }}
run-tests: ${{ inputs.run-tests }}
test-runner: ${{ inputs.test-runner }}

artifacts:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion extension/BuildPhpExtension/BuildPhpExtension.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Invoke-PhpBuildExtension', 'Add-BuildRequirements', 'Add-Path', 'Get-PhpSdk', 'Add-Dependencies', 'Add-PhpDependencies', 'Get-VsVersion', 'Add-Extension', 'Get-Extension', 'Get-ExtensionSource', 'Add-ExtensionDependencies', 'Get-ExtensionConfig', 'Add-Extensions', 'Get-PhpBuild', 'Invoke-Build', 'Add-Package', 'Get-PhpDevelBuild'
FunctionsToExport = 'Invoke-PhpBuildExtension', 'Add-BuildRequirements', 'Add-Path', 'Get-PhpSdk', 'Add-Dependencies', 'Add-PhpDependencies', 'Get-VsVersion', 'Add-Extension', 'Get-Extension', 'Get-ExtensionSource', 'Add-ExtensionDependencies', 'Get-ExtensionConfig', 'Add-Extensions', 'Get-PhpBuild', 'Invoke-Build', 'Invoke-Tests', 'Add-Package', 'Get-PhpDevelBuild'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*'
Expand Down
5 changes: 0 additions & 5 deletions extension/BuildPhpExtension/private/Invoke-Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ Function Invoke-Build {
$bat_content += "call phpize 2>&1"
$bat_content += "call configure --with-php-build=`"..\deps`" $($Config.options) --with-mp=`"disable`" --enable-debug-pack 2>&1"
$bat_content += "nmake /nologo 2>&1"
if($env:RUN_TESTS -eq "true") {
$php_dir = Join-Path (Get-Location).Path php-bin
New-Item -ItemType SymbolicLink -Path C:\php -Target $php_dir -Force > $null 2>&1
$bat_content += "nmake /nologo test 2>&1"
}
$bat_content += "exit %errorlevel%"
Set-Content -Encoding "ASCII" -Path task.bat -Value $bat_content

Expand Down
57 changes: 57 additions & 0 deletions extension/BuildPhpExtension/private/Invoke-Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Function Invoke-Tests {
<#
.SYNOPSIS
Build the extension
.PARAMETER Config
Extension Configuration
#>
[OutputType()]
param(
[Parameter(Mandatory = $true, Position=0, HelpMessage='Extension Configuration')]
[PSCustomObject] $Config
)
begin {
}
process {
$currentDirectory = (Get-Location).Path
$php_dir = Join-Path $currentDirectory php-bin
$env:TEST_PHP_EXECUTABLE = "$php_dir\php.exe"
$env:REPORT_EXIT_STATUS = 1
$env:XDEBUG_MODE = ""
$env:TEMP=$((Get-Item -LiteralPath $Env:TEMP).FullName)
$env:TMP=$((Get-Item -LiteralPath $Env:TMP).FullName)
$php_args = @(
'-n'
)
if ((Select-String -Path 'config.w32' -Pattern 'ZEND_EXTENSION\(' -Quiet) -eq $true) {
$php_args += @(
"-d zend_extension=$currentDirectory\$($Config.build_directory)\php_$($Config.name).dll"
)
}
$env:TEST_PHP_ARGS = $php_args -join ' '
if ($null -eq $env:TEST_RUNNER) {
$env:TEST_RUNNER = 'run-tests.php'
} elseif(-not(Test-Path $env:TEST_RUNNER)) {
throw "Test runner $env:TEST_RUNNER does not exist."
}
$test_runner_args = @(
'-j8',
'-q',
'--offline',
'--show-diff',
'--show-slow 1000',
'--set-timeout 120',
'-g FAIL,XFAIL,BORK,WARN,LEAK,SKIP',
'--temp-source ' + $env:TEMP,
'--temp-target ' + $env:TEMP
)
$phpExpression = "php $env:TEST_RUNNER " + ($test_runner_args -join ' ')
chcp 65001
Write-Output "Running tests... $phpExpression"
Write-Output "TEST_PHP_ARGS $env:TEST_PHP_ARGS"
Write-Output "TEST_PHP_EXECUTABLE $env:TEST_PHP_EXECUTABLE"
Invoke-Expression $phpExpression
}
end {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function Invoke-PhpBuildExtension {

Invoke-Build -Config $config

if($env:RUN_TESTS -eq 'true') {
Invoke-Tests -Config $config
}

Add-Package -Config $config

Set-Location $currentDirectory
Expand Down
5 changes: 5 additions & 0 deletions extension/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ inputs:
description: Run tests after building the extension
required: false
default: 'false'
test-runner:
description: Test runner to use
required: false
default: 'run-tests.php'
artifact-naming-scheme:
description: Naming schema for the artifacts, pie or pecl
deprecationMessage: "This will be removed once pie is released"
Expand All @@ -51,6 +55,7 @@ runs:
LIBRARIES: ${{inputs.libs}}
ARTIFACT_NAMING_SCHEME: ${{inputs.artifact-naming-scheme}}
RUN_TESTS: ${{inputs.run-tests}}
TEST_RUNNER: ${{inputs.test-runner}}
run: |
Import-Module ${{ github.action_path }}\BuildPhpExtension -Force
Invoke-PhpBuildExtension -ExtensionUrl "${{inputs.extension-url}}" `
Expand Down

0 comments on commit 0e0e7e0

Please sign in to comment.