Skip to content

Commit 794bf67

Browse files
committed
(chocolatey#1185) Be explicit with expected exit codes
With the upgrade package used in the tests, it currently exits with -1 even though it is successful. Instead of blindly accepting 0 and -1 for all the tests, be explicit about which one we expect so we can catch changes to this exit code.
1 parent 8cb1f23 commit 794bf67

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tests/chocolatey-tests/features/Hooks.Tests.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
Import-Module helpers/common-helpers
22

3-
Describe "hooks tests" -Tag Chocolatey, Hooks {
3+
Describe "choco hooks tests" -Tag Chocolatey, HooksFeature {
44
BeforeDiscovery {
55
$Flags = @(
6-
@{ Flag = '' ; RunsHooks = $true ; Command = 'install' }
7-
@{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'install' }
8-
@{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'install' }
6+
@{ Flag = '' ; RunsHooks = $true ; Command = 'install' ; ExitCode = 0 }
7+
@{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'install' ; ExitCode = 0 }
8+
@{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'install' ; ExitCode = 0 }
99

10-
@{ Flag = '' ; RunsHooks = $true ; Command = 'uninstall' }
11-
@{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'uninstall' }
12-
@{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'uninstall' }
10+
@{ Flag = '' ; RunsHooks = $true ; Command = 'uninstall' ; ExitCode = 0 }
11+
@{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'uninstall' ; ExitCode = 0 }
12+
@{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'uninstall' ; ExitCode = 0 }
1313

14-
@{ Flag = '' ; RunsHooks = $true ; Command = 'upgrade' }
15-
@{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'upgrade' }
16-
@{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'upgrade' }
14+
@{ Flag = '' ; RunsHooks = $true ; Command = 'upgrade' ; ExitCode = -1 }
15+
@{ Flag = '--skip-powershell' ; RunsHooks = $false ; Command = 'upgrade' ; ExitCode = 0 }
16+
@{ Flag = '--skip-hooks' ; RunsHooks = $false ; Command = 'upgrade' ; ExitCode = -1 }
1717

1818
)
1919
}
@@ -47,8 +47,8 @@ Describe "hooks tests" -Tag Chocolatey, Hooks {
4747
}
4848

4949
# Uninstall/Upgrade exit -1: https://github.com/chocolatey/choco/issues/2822
50-
It "Exits with Success (0,-1)" {
51-
$Output.ExitCode | Should -BeIn @(0, -1) -Because $Output.String
50+
It "Exits with expected value (<ExitCode>)" {
51+
$Output.ExitCode | Should -Be $ExitCode -Because $Output.String
5252
}
5353

5454
It "Should execute hooks (<RunsHooks>)" {

0 commit comments

Comments
 (0)