Skip to content

Commit

Permalink
Fix false positives in error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbergstrom committed Jun 16, 2021
1 parent a93836e commit 577c8be
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.3] - 2021-06-16
#### Fixed
* False positives in error handling during package installation for packages that emitted output including the string 'fail'

## [0.0.3] - 2021-03-28
#### Changed
* To mirror broader PowerShell Crescendo support, restrict module to run at a minimum of PowerShell 5.1
Expand Down
2 changes: 1 addition & 1 deletion src/Foil.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ $Commands = @(
Handler = {
param ($output)
if ($output) {
$failures = ($output -match 'fail')
$failures = ($output -match 'Chocolatey installed \d+\/\d+ packages. \d+ packages failed\.')
if ($failures) {
Write-Error ($output -join "`r`n")
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Foil.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'Foil.psm1'
ModuleVersion = '0.0.3'
ModuleVersion = '0.0.4'
GUID = '38430603-9954-45fd-949a-5f79492ffaf7'
Author = 'Ethan Bergstrom'
Copyright = '2021'
Expand Down
28 changes: 28 additions & 0 deletions test/Foil.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,31 @@ Describe "version filters" {
}
}
}

Describe "error handling on Chocolatey failures" {
$package = 'googlechrome'
# Keep at least one version back, to test the 'latest' feature
$version = '87.0.4280.141'

AfterAll {
Uninstall-ChocoPackage -Name $package -ErrorAction SilentlyContinue
}

It 'searches for and fails to silently install a broken package version' {
Get-ChocoPackage -Name $package -Version $version -Exact | Install-ChocoPackage -Force | Should -Throw
}
}

Describe "avoid false positives in error handling" {
$package = 'Office365Business'
# Keep at least one version back, to test the 'latest' feature
$version = '13901.20336'

AfterAll {
Uninstall-ChocoPackage -Name $package -ErrorAction SilentlyContinue
}

It 'searches for and silently installs a specific package version that contains "fail" the output' {
Get-ChocoPackage -Name $package -Version $version -Exact | Install-ChocoPackage -Force | Should -Throw
}
}

0 comments on commit 577c8be

Please sign in to comment.