Skip to content

Commit

Permalink
(maint) Abort testing if test packages don't pack
Browse files Browse the repository at this point in the history
This adds logic to the Invoke-Tests file to abort testing if packages
fail to pack. This is to improve the developer experience by not
allowing tests to run without the full set of test packages.
  • Loading branch information
corbob committed Sep 20, 2024
1 parent 3418ffb commit 880c890
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Invoke-Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,28 @@ if (-not (Test-Path "$TestPath/packages") -or -not $SkipPackaging) {
$nuspecs = Get-ChildItem -Path $PSScriptRoot/src/chocolatey.tests.integration, $PSScriptRoot/tests/packages -Recurse -Include *.nuspec | Where-Object FullName -NotMatch 'bin'
Get-ChildItem -Path $PSScriptRoot/tests/packages -Recurse -Include *.nupkg | Copy-Item -Destination "$TestPath/packages"

foreach ($file in $nuspecs) {
Write-Host "Packaging $file"
$packFailures = foreach ($file in $nuspecs) {
# Include allow-unofficial in case an unofficial Chocolatey has been installed globally for testing
$null = choco pack $file.FullName --out "$TestPath/packages" --allow-unofficial
$packOutput = choco pack $file.FullName --out "$TestPath/packages" --allow-unofficial
if ($LASTEXITCODE -ne 0) {
[pscustomobject]@{
Package = $file.FullName
ExitCode = $LASTEXITCODE
Output = $packOutput
}
Write-Warning "Failed to pack $file"
}
else {
Write-Host "Packaged $file"
}
}

if ($null -ne $packFailures) {
foreach ($failure in $packFailures) {
Write-Warning "$($failure.Package) failed to pack with exit code: $($failure.ExitCode)"
$failure.Output | Write-Warning
}
throw "$($packFailures.Count) packages failed to pack."
}
}

Expand Down

0 comments on commit 880c890

Please sign in to comment.