Skip to content

Commit 4324eed

Browse files
committed
(chocolatey#1762) Add test for new enhanced exit code
Now, when you have useEnhancedExitCodes turned on, if you try to set a pin on a package, that is already set, the exit code will change to be a 2, giving a clear indication that no action was taken. This commit adds a Pester test to verify that this works as expected.
1 parent 5959d7e commit 4324eed

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/pester-tests/commands/choco-pin.Tests.ps1

+18
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ Describe "choco pin" -Tag Chocolatey, PinCommand {
112112
$Output.Lines | Should -Contain "Nothing to change. Pin already set or removed."
113113
$CurrentPins | Should -Contain "upgradepackage|1.0.0$listSuffix"
114114
}
115+
116+
Context "when using enhanced exit codes" {
117+
BeforeAll {
118+
$null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes"
119+
120+
$Output = Invoke-Choco pin add --name upgradepackage
121+
$CurrentPins = Invoke-Choco pin list --LimitOutput | ForEach-Object Lines
122+
}
123+
124+
It "Exits with ExitCode 2" {
125+
$Output.ExitCode | Should -Be 2 -Because $Output.String
126+
}
127+
128+
It "Changes Nothing" {
129+
$Output.Lines | Should -Contain "Nothing to change. Pin already set or removed."
130+
$CurrentPins | Should -Contain "upgradepackage|1.0.0$listSuffix"
131+
}
132+
}
115133
}
116134

117135
Context "Setting a Pin for a non-installed Package" {

0 commit comments

Comments
 (0)