diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3462b17..1822c11 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,10 @@ on: description: "Build and include QuantLib test suite" type: boolean default: true + run_tests: + description: "Run the QuantLib test suite after building" + type: boolean + default: false create_release: description: "Create a GitHub Release with the zip asset" type: boolean @@ -43,7 +47,10 @@ jobs: - name: Build QuantLib DLL shell: pwsh run: | - $buildTestsFlag = if ("${{ inputs.build_tests }}" -eq "true") { "-BuildTests" } else { "" } + $buildTests = "${{ inputs.build_tests }}" -ne "false" + $runTests = "${{ inputs.run_tests }}" -eq "true" + $buildTestsFlag = if ($buildTests) { "-BuildTests" } else { "" } + $runTestsFlag = if ($runTests) { "-RunTests" } else { "" } $cmd = "scripts/Build-QuantLibDLL.ps1" + " -QuantLibVersion $env:QL_VERSION" + " -BoostVersion $env:BOOST_VERSION" + @@ -51,7 +58,7 @@ jobs: " -TempDir ${{ runner.temp }}\quantlib-build" + " -PackageZip" + " -ZipOutputDir ${{ github.workspace }}" + - " $buildTestsFlag" + " $buildTestsFlag $runTestsFlag" Write-Host "Running: $cmd" Invoke-Expression $cmd diff --git a/scripts/Build-QuantLibDLL.ps1 b/scripts/Build-QuantLibDLL.ps1 index 77b9b79..c6247da 100644 --- a/scripts/Build-QuantLibDLL.ps1 +++ b/scripts/Build-QuantLibDLL.ps1 @@ -38,6 +38,9 @@ .PARAMETER BuildTests Also build the QuantLib test suite. +.PARAMETER RunTests + Run the QuantLib test suite after building. Implies -BuildTests. + .PARAMETER PackageZip Create a distributable zip containing QuantLib DLL + headers + Boost headers. @@ -59,12 +62,16 @@ param( [string]$TempDir = (Join-Path (Split-Path $PSScriptRoot) "build"), [int]$Jobs = 0, [switch]$BuildTests, + [switch]$RunTests, [switch]$PackageZip, [string]$ZipOutputDir = "." ) $ErrorActionPreference = "Stop" +# -RunTests implies -BuildTests +if ($RunTests) { $BuildTests = [switch]::new($true) } + $BoostVersionU = $BoostVersion -replace '\.', '_' if ($Jobs -eq 0) { $Jobs = (Get-CimInstance Win32_Processor).NumberOfLogicalProcessors @@ -215,9 +222,13 @@ $ppContent = Get-Content $ppHeader -Raw if (-not $ppContent.Contains('qldefines.hpp')) { $ppContent = $ppContent -replace '(#define\s+primitivepolynomials_hpp)', "`$1`n`n#include " } -$ppContent = $ppContent.Replace( - 'extern const long *const PrimitivePolynomials', - 'extern QL_EXPORT const long *const PrimitivePolynomials') +if (-not $ppContent.Contains('QL_EXPORT')) { + # NOTE: The declaration uses multi-line "extern ... 'C' ... const long *const" + # so we must match just "const long *const PrimitivePolynomials" (not "extern const ..."). + $ppContent = $ppContent.Replace( + 'const long *const PrimitivePolynomials', + 'QL_EXPORT const long *const PrimitivePolynomials') +} [System.IO.File]::WriteAllText($ppHeader, $ppContent) # ========================================================================== @@ -236,7 +247,7 @@ $cmakeArgs = @( "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON" '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$:Debug>DLL' "-DBoost_INCLUDE_DIR=$BoostIncludeDir" - "-DQL_BUILD_BENCHMARK=OFF" + "-DQL_INSTALL_BENCHMARK=OFF" "-DQL_BUILD_EXAMPLES=OFF" "-DQL_BUILD_TEST_SUITE=$( if ($BuildTests) { 'ON' } else { 'OFF' } )" "-Wno-dev" @@ -300,7 +311,38 @@ if (Test-Path "$InstallDir\bin") { } # ========================================================================== -# 6. Package zip (optional) +# 6. Run test suite (optional) +# ========================================================================== +if ($RunTests) { + Write-Host "==> Running QuantLib test suite" + $TestExePath = Get-ChildItem -Recurse "$QLBuildDir\test-suite" -Filter "quantlib-test-suite.exe" | + Where-Object { $_.Directory.Name -eq "Release" } | Select-Object -First 1 + if (-not $TestExePath) { + throw "quantlib-test-suite.exe not found under $QLBuildDir\test-suite" + } + Write-Host " Executable: $($TestExePath.FullName)" + + # Add the DLL directory to PATH so the test can find the QuantLib DLL + $DllDir = (Get-ChildItem -Recurse $QLBuildDir -Filter "QuantLib*.dll" | + Where-Object { $_.Directory.Name -eq "Release" } | Select-Object -First 1).DirectoryName + $env:PATH = "$DllDir;$env:PATH" + Write-Host " DLL directory added to PATH: $DllDir" + + $testOutput = & $TestExePath.FullName 2>&1 | Out-String + $testExitCode = $LASTEXITCODE + Write-Host $testOutput + + if ($testExitCode -ne 0) { + throw "quantlib-test-suite.exe exited with code $testExitCode (expected 0)" + } + if ($testOutput -notmatch '\*\*\* No errors detected') { + throw "Test suite output did not contain '*** No errors detected'" + } + Write-Host "==> Test suite PASSED (exit code 0, no errors detected)" +} + +# ========================================================================== +# 7. Package zip (optional) # ========================================================================== if ($PackageZip) { Write-Host "==> Packaging distribution zip"