diff --git a/GenerateDocs.ps1 b/GenerateDocs.ps1 index 36b7197d9a..8bde26b1cc 100644 --- a/GenerateDocs.ps1 +++ b/GenerateDocs.ps1 @@ -25,6 +25,9 @@ $psModuleLocation = [System.IO.Path]::GetFullPath("$thisDirectory\src\chocolatey $docsFolder = [System.IO.Path]::GetFullPath("$thisDirectory\docs\generated") $mergedDirectory = [System.IO.Path]::GetFullPath("$thisDirectory\code_drop\temp\_PublishedApps\choco_merged") $chocoExe = "$mergedDirectory\choco.exe" + +Write-Host "Running choco.exe from $chocoExe" + $lineFeed = "`r`n" $sourceLocation = 'https://github.com/chocolatey/choco/blob/master/' $sourceCommands = $sourceLocation + 'src/chocolatey/infrastructure.app/commands' @@ -599,6 +602,7 @@ The following are experimental or use not recommended: Generate-CommandReference 'Optimize' '90' Generate-CommandReference 'Outdated' '100' Generate-CommandReference 'Pin' '110' + Generate-CommandReference 'Rule' '115' Generate-CommandReference 'Search' '120' Generate-CommandReference 'SetApiKey' '130' Generate-CommandReference 'Source' '140' diff --git a/nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1 b/nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1 index 76ad358090..0034cbe82f 100644 --- a/nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1 +++ b/nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1 @@ -858,7 +858,7 @@ function Invoke-Chocolatey-Initial { try { $chocoInstallationFolder = Get-ChocolateyInstallFolder $chocoExe = Join-Path -Path $chocoInstallationFolder -ChildPath "choco.exe" - $runResult = & $chocoExe -v *>&1 + $runResult = & $chocoExe -v 2>&1 if ($LASTEXITCODE -eq 0) { Write-Debug "Chocolatey CLI execution completed successfully." } @@ -876,8 +876,8 @@ Export-ModuleMember -Function Initialize-Chocolatey # SIG # Begin signature block # MIInKwYJKoZIhvcNAQcCoIInHDCCJxgCAQExDzANBglghkgBZQMEAgEFADB5Bgor # BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG -# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCC8Wmtrs9N0S3FW -# cp2ebCXvAwP1tJVxI2dlqSwsrccSpKCCIK4wggWNMIIEdaADAgECAhAOmxiO+dAt +# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCArPR/MaAFOnPhm +# wTraOHhBiut3LMThkjxzi7DsT2up/qCCIK4wggWNMIIEdaADAgECAhAOmxiO+dAt # 5+/bUOIIQBhaMA0GCSqGSIb3DQEBDAUAMGUxCzAJBgNVBAYTAlVTMRUwEwYDVQQK # EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xJDAiBgNV # BAMTG0RpZ2lDZXJ0IEFzc3VyZWQgSUQgUm9vdCBDQTAeFw0yMjA4MDEwMDAwMDBa @@ -1057,30 +1057,30 @@ Export-ModuleMember -Function Initialize-Chocolatey # IFNIQTM4NCAyMDIxIENBMQIQBNI793flHTneCMtwLiiYFTANBglghkgBZQMEAgEF # AKCBhDAYBgorBgEEAYI3AgEMMQowCKACgAChAoAAMBkGCSqGSIb3DQEJAzEMBgor # BgEEAYI3AgEEMBwGCisGAQQBgjcCAQsxDjAMBgorBgEEAYI3AgEVMC8GCSqGSIb3 -# DQEJBDEiBCDMHmRGjDIKOEla+IaM/zMWLkvV/rMxHg45my3wmHLVfDANBgkqhkiG -# 9w0BAQEFAASCAYB3TE6Lis+z/D5XQ11XK2+4We7m53DgAY7C0+CWG/yiJ7ImRdNF -# iJQV4TXHtT1fT3ke/ZXkZE95r+W6KPg1bsm8SBBEPm/8n4lgfcP00uw/rAcejuXD -# bVXrlrygICzuG+iocYgGcLL1+UxMr5mnNIye4mLMQkrluPSXf6+3jPZrIMCS8d7G -# V6zHEyiK1BVqfl0708/LHFQ3aPwI5z9xIZqTZFDjnDgFw5z2D1bq+wZY/tB04v1F -# pLIDxgLI7l++TJZS5yj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ghmn0esLtQVM6MncyEwDQYJ +# KoZIhvcNAQEBBQAEggIAQ4Jwo+bD++jtMq9OaaNQ+lRdtb7eS2QKvSqGparxFDw1 +# Y7H4Kd53LIfKJvibvOaPCU4o8J2Qml6MSLLdSTqR2Sndq52c1eBsqYFOx3Zhbee0 +# l/73uf8R47KmUUva2n2rkohfNtwMkMiMn9pYUxvGLqz5YtJthJBPJ+3FDCmMlbwC +# e1/tPvxM3cB1S9N3kQTk0/Br8wNbgg8bV11cDckQhtXR7+cq3NJrLoDcgZUJGUHJ +# sZj45sEwCJavR4LEQauMXdoMlhWDTxATXdf8VcLR6c/D4UVhnNOxtKBevJTCowXC +# 5C8nQRZib0jKZ4aVTPO6M/voFIn3GArb4sEK9Hv7kd0+5LK9xzB3jJ7k3Qp0Lyf2 +# s9w3wgUF3APEZuCFOONHFHZraPyBixjALJDppZveWvOkPyWodYHnMdWnIRxJW6PX +# jL9QbXLO+kpZds0PcDt9ebAP9meuarZIUEl7BSthP4N5KF/BNQbpetVgWRCFuZJ3 +# fSO9qrmQCtGm6S7ldYUgChUR2pHU+N3y1kPhmsr2bu/WDtIFojZxrickwHajrX83 +# 24axIasm3XjdMUWmhZLAZo48QN1c8hUwtiwTLo+8ZGUwmjbLEp4v7WDBI/ZcD0WW +# 67XftIHKVDi4gJJyR9uKQdFrmIIqOHeJbgffxhwuEIlDQ3X45Umw+rymBiKOGxA= # SIG # End signature block diff --git a/recipe.cake b/recipe.cake index 90b0dd3b1e..9bdbb6dc49 100644 --- a/recipe.cake +++ b/recipe.cake @@ -329,14 +329,14 @@ Task("Prepare-NuGet-Packages") .IsDependeeOf("Sign-Assemblies") .Does(() => { - CleanDirectory(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib"); - EnsureDirectoryExists(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib/net48"); + CleanDirectory(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib"); + EnsureDirectoryExists(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib/net48"); // Copy legal documents - CopyFile(BuildParameters.RootDirectoryPath + "/docs/legal/CREDITS.md", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib/CREDITS.txt"); + CopyFile(BuildParameters.RootDirectoryPath + "/docs/legal/CREDITS.md", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib/CREDITS.txt"); - CopyFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey_merged/*", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib/net48"); - CopyFile(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/chocolatey.xml", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib/net48/chocolatey.xml"); + CopyFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey_merged/*", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib/net48"); + CopyFile(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/chocolatey.xml", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib/net48/chocolatey.xml"); }); Task("Prepare-MSI") diff --git a/src/Chocolatey.PowerShell/Helpers/EnvironmentHelper.cs b/src/Chocolatey.PowerShell/Helpers/EnvironmentHelper.cs index 468c7bb3b7..fedc3d86e2 100644 --- a/src/Chocolatey.PowerShell/Helpers/EnvironmentHelper.cs +++ b/src/Chocolatey.PowerShell/Helpers/EnvironmentHelper.cs @@ -166,7 +166,14 @@ public static void SetVariable(PSCmdlet cmdlet, string name, EnvironmentVariable cmdlet.WriteDebug($"Registry type for {name} is/will be {registryType}"); - registryKey.SetValue(name, value, registryType); + if (string.IsNullOrEmpty(value)) + { + registryKey.DeleteValue(name, throwOnMissingValue: false); + } + else + { + registryKey.SetValue(name, value, registryType); + } } try @@ -219,7 +226,10 @@ public static void UpdateSession(PSCmdlet cmdlet) foreach (var name in GetVariableNames(scope)) { var value = GetVariable(cmdlet, name, scope); - SetVariable(cmdlet, name, EnvironmentVariableTarget.Process, value); + if (!string.IsNullOrEmpty(value)) + { + SetVariable(cmdlet, name, EnvironmentVariableTarget.Process, value); + } } } diff --git a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 index 5ccb1ce13c..d71dfe2ed1 100644 --- a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 +++ b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 @@ -102,7 +102,11 @@ if (Test-Path $extensionsPath) { if ($licensedAssembly) { # Import-Module -Assembly doesn't work if the parent module is reimported, so force the import by path. - Import-Module $licensedAssembly.Location -Force + if ($licensedAssembly.Location) { + Import-Module $licensedAssembly.Location -Force + } else { + Import-Module $licensedAssembly + } } else { # Fallback: load the extension DLL from the path directly. @@ -149,26 +153,31 @@ if (Test-Path $extensionsPath) { # In effect we ensure that any command calls that match the name of one of our commands # will resolve to _our_ commands (preferring licensed cmdlets in the case of a name collision), # preventing packages from overriding them with their own commands and potentially breaking things. -$ExecutionContext.InvokeCommand.PreCommandLookupAction = { - param($command, $eventArgs) +# +# This functionality is only available in v3 and later, so using this in v2 will not +# work; check for the property before trying to set it. +if ($ExecutionContext.InvokeCommand.PreCommandLookupAction) { + $ExecutionContext.InvokeCommand.PreCommandLookupAction = { + param($command, $eventArgs) - # Don't run this handler for stuff PowerShell is looking up internally - if ($eventArgs.CommandOrigin -eq 'Runspace') { - $resolvedCommand = if ($command -in $chocolateyCmdlets.Licensed) { - Get-Command "$command*" -Module 'chocolatey.licensed' -CommandType Cmdlet -ErrorAction Ignore | - Where-Object { $_.Name -match "^$command(Cmdlet)?$" } | - Select-Object -First 1 - } - elseif ($command -in $chocolateyCmdlets.Default) { - Get-Command $command -Module "Chocolatey.PowerShell" -CommandType Cmdlet -ErrorAction Ignore - } + # Don't run this handler for stuff PowerShell is looking up internally + if ($eventArgs.CommandOrigin -eq 'Runspace') { + $resolvedCommand = if ($chocolateyCmdlets.Licensed -contains $command) { + Get-Command "$command*" -Module 'chocolatey.licensed' -CommandType Cmdlet -ErrorAction SilentlyContinue | + Where-Object { @($command, "$($command)Cmdlet") -contains $_.Name } | + Select-Object -First 1 + } + elseif ($chocolateyCmdlets.Default -contains $command) { + Get-Command $command -Module "Chocolatey.PowerShell" -CommandType Cmdlet -ErrorAction SilentlyContinue + } - if ($resolvedCommand) { - $eventArgs.Command = $resolvedCommand - $eventArgs.StopSearch = $true + if ($resolvedCommand) { + $eventArgs.Command = $resolvedCommand + $eventArgs.StopSearch = $true + } } - } -}.GetNewClosure() + }.GetNewClosure() +} # todo: explore removing this for a future version Export-ModuleMember -Function * -Alias * -Cmdlet * @@ -176,8 +185,8 @@ Export-ModuleMember -Function * -Alias * -Cmdlet * # SIG # Begin signature block # MIInKwYJKoZIhvcNAQcCoIInHDCCJxgCAQExDzANBglghkgBZQMEAgEFADB5Bgor # BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG -# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCCwc5bNHW/kpfcZ -# 7+n0pl1aI7nawLR48Dvt/t2uNlf8MqCCIK4wggWNMIIEdaADAgECAhAOmxiO+dAt +# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCDNL/wxXxTwoao9 +# +niutFOSQWJKM7QvRr2vKMT3E6T+AKCCIK4wggWNMIIEdaADAgECAhAOmxiO+dAt # 5+/bUOIIQBhaMA0GCSqGSIb3DQEBDAUAMGUxCzAJBgNVBAYTAlVTMRUwEwYDVQQK # EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xJDAiBgNV # BAMTG0RpZ2lDZXJ0IEFzc3VyZWQgSUQgUm9vdCBDQTAeFw0yMjA4MDEwMDAwMDBa @@ -357,30 +366,30 @@ Export-ModuleMember -Function * -Alias * -Cmdlet * # I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uicbxhcvpIMdqtzbxiKIIsUda +# 1oUOmQr2+3ehuGKftW+EGk83ZKObNF98RMSA/4YFO9e42FtB7P9+FSbJ1mXRUnFC +# sftewOZA7haYCPiZV6Tt/kBJaG9Y2ROrq4rDrbMmKWl3WOWui/tyEwm12GcNLgpc +# cRY1FUXMfOL1kM9fgLlUCKORaN9sB1kEKOGXGFGkpKyWQNGlpQn/EuKKqHEhwl4= # SIG # End signature block diff --git a/src/chocolatey.resources/helpers/chocolateyProfile.psm1 b/src/chocolatey.resources/helpers/chocolateyProfile.psm1 index a9968117d4..aeed368810 100644 --- a/src/chocolatey.resources/helpers/chocolateyProfile.psm1 +++ b/src/chocolatey.resources/helpers/chocolateyProfile.psm1 @@ -25,13 +25,15 @@ Import-Module "$thisDirectory\Chocolatey.PowerShell.dll" -Cmdlet "Get-Environmen . $thisDirectory\functions\Write-FunctionCallLogMessage.ps1 . $thisDirectory\ChocolateyTabExpansion.ps1 -Export-ModuleMember -Alias refreshenv -Function 'Update-SessionEnvironment', 'TabExpansion' +Set-Alias refreshenv Update-SessionEnvironment + +Export-ModuleMember -Alias refreshenv -Cmdlet 'Update-SessionEnvironment' -Function 'TabExpansion' # SIG # Begin signature block # MIInKwYJKoZIhvcNAQcCoIInHDCCJxgCAQExDzANBglghkgBZQMEAgEFADB5Bgor # BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG -# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCDVITi5ehNxewn2 -# brDS2sE656mB6k07eSxGAfbiBaY0PKCCIK4wggWNMIIEdaADAgECAhAOmxiO+dAt +# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCC7eXGNrikxA4wn +# J9PdpPo/8IvwVFuZPVPleXxyzmxMLaCCIK4wggWNMIIEdaADAgECAhAOmxiO+dAt # 5+/bUOIIQBhaMA0GCSqGSIb3DQEBDAUAMGUxCzAJBgNVBAYTAlVTMRUwEwYDVQQK # EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xJDAiBgNV # BAMTG0RpZ2lDZXJ0IEFzc3VyZWQgSUQgUm9vdCBDQTAeFw0yMjA4MDEwMDAwMDBa @@ -211,30 +213,30 @@ Export-ModuleMember -Alias refreshenv -Function 'Update-SessionEnvironment', 'Ta # IFNIQTM4NCAyMDIxIENBMQIQBNI793flHTneCMtwLiiYFTANBglghkgBZQMEAgEF # AKCBhDAYBgorBgEEAYI3AgEMMQowCKACgAChAoAAMBkGCSqGSIb3DQEJAzEMBgor # BgEEAYI3AgEEMBwGCisGAQQBgjcCAQsxDjAMBgorBgEEAYI3AgEVMC8GCSqGSIb3 -# DQEJBDEiBCAq3pBrLVvjp3b/NR42b+Azn+un2R42vwQvCAMjkoABCTANBgkqhkiG -# 9w0BAQEFAASCAYBb3hzofqnjQVyQd/ouNG7FFKpmYB7l63QPb58gcWcnm9Bom2yD -# FPtPmHGUlIA5ZOYoC5rRIAY2t9xOLOTcnKsDdIq65SPHBfG4oI3oBtCELvF6FGZF -# AEuFKQYBzO+xxxrAG83TNwJmv/evgEWV8iII+458Bk/1PgNHC1/nW7h0KBabF9lB -# iXrXSxGq8Fz4jjQSuVf16atDjPnwPnKl5KnMe3/gBTdx+ZpKHlp3wuBS2Kow5plr -# 5MY1HubjCGQNUgPaaqd8hXIV137M5ZCWb6bqqfbmaLZobaKIHUlE7pjr13INoK48 -# KANwzlDczWMwHyVVxNMl2kdAViWciHR5pjIAtow38eBJr/chpqKTT8b0CTyLIWll -# 9LiSLrEHC8NSHdK1jk4dq9+hLiB0bllBCPYQQfIWhj9fWzDiR/DBRFLM85qLCN0X -# UsMGrFFOqCEJT+qjped0nzXQ0t3VaZq57QgMJC+gfB89/yT5KtDz/mTKnnk5E8QL -# LUthy5LjV2Bdz7uhggMgMIIDHAYJKoZIhvcNAQkGMYIDDTCCAwkCAQEwdzBjMQsw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TS1alI/RezVkBnWaFqTVYeh8YOUDmxEqcq6XVVqF+cP8Ulh +# 0X9hgPFwJ/8pMILt+gwTiRiGBE3hv+IsipRmgz22LjbtcmYKbMjN5zp2tJTTJ1bM +# 5RFZlg4CRC4keFVa/R4uWsx7KDcS1twsZWAm/OyU4i+3DH28XpfV3iMOy/okXWHg +# hMGUbwdXr4bk5+KbuVMgfFw4WEh6NN8jtJyLHCzoFA0Tc/p3cnwKn9IFxnvLQlS9 +# ez3648Bp+LCEWNneZ8j9F6nowqBr9woGww86XEQuHOgc3GGJfqiRLZ7V+NG2X6OT +# yUyo1Zdb3++Bd2QOi2AnU4V0O+zIoDzcU6b7Qi569P2tVE0l62vqfp4lmp9wdJcd +# hwxODFnTQjo3751hZVmjAioeud86X6019CBFjk9o59tcB2oDDjhBqxiAr18CEp0= # SIG # End signature block diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index e4caec93cd..3d7be60ae5 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -340,7 +340,7 @@ private static void SetAllFeatureFlags(ChocolateyConfiguration config, ConfigFil config.Features.UsePackageRepositoryOptimizations = SetFeatureFlag(ApplicationParameters.Features.UsePackageRepositoryOptimizations, configFileSettings, defaultEnabled: true, description: "Use Package Repository Optimizations - Turn on optimizations for reducing bandwidth with repository queries during package install/upgrade/outdated operations. Should generally be left enabled, unless a repository needs to support older methods of query. When disabled, this makes queries similar to the way they were done in earlier versions of Chocolatey."); config.Features.UsePackageHashValidation = SetFeatureFlag(ApplicationParameters.Features.UsePackageHashValidation, configFileSettings, defaultEnabled: false, description: "Use Package Hash Validation - Check the hash of the downloaded package file against the source provided hash. Only supports sources that provide SHA512 hashes. Disabled by default. Available in 2.3.0+"); config.PromptForConfirmation = !SetFeatureFlag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass."); - config.DisableCompatibilityChecks = SetFeatureFlag(ApplicationParameters.Features.DisableCompatibilityChecks, configFileSettings, defaultEnabled: false, description: "Disable Compatibility Checks - Disable showing a warning when there is an incompatibility between Chocolatey CLI and Chocolatey Licensed Extension. Available in 1.1.0+"); + config.DisableCompatibilityChecks = SetFeatureFlag(ApplicationParameters.Features.DisableCompatibilityChecks, configFileSettings, defaultEnabled: false, description: "Disable Compatibility Checks - Disable showing a warning when there is an incompatibility between Chocolatey CLI and Chocolatey Licensed Extension."); } private static bool SetFeatureFlag(string featureName, ConfigFileSettings configFileSettings, bool defaultEnabled, string description) @@ -456,7 +456,7 @@ private static void SetGlobalOptions(IList args, ChocolateyConfiguration "Log File to output to in addition to regular loggers.", option => config.AdditionalLogFileLocation = option.UnquoteSafe()) .Add("skipcompatibilitychecks|skip-compatibility-checks", - "SkipCompatibilityChecks - Prevent warnings being shown before and after command execution when a runtime compatibility problem is found between the version of Chocolatey and the Chocolatey Licensed Extension. Available in 1.1.0+", + "SkipCompatibilityChecks - Prevent warnings being shown before and after command execution when a runtime compatibility problem is found between the version of Chocolatey and the Chocolatey Licensed Extension.", option => config.DisableCompatibilityChecks = option != null) .Add("ignore-http-cache", "IgnoreHttpCache - Ignore any HTTP caches that have previously been created when querying sources, and create new caches. Available in 2.1.0+", diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs index 7364a59fd4..45bf7cf207 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs @@ -279,10 +279,6 @@ Installs a package or a list of packages (sometimes specified as a "chocolatey".Log().Info(@" choco install [ ] [] -NOTE: `all` is a special package keyword that will allow you to install - all packages from a custom feed. Will not work with Chocolatey default - feed. THIS IS NOT YET REIMPLEMENTED. - NOTE: Any package name ending with .config is considered a 'packages.config' file. Please see https://ch0.co/packages_config diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateySearchCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateySearchCommand.cs index af4766f71e..2bf9d85959 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateySearchCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateySearchCommand.cs @@ -212,7 +212,6 @@ file a ticket so we can document it at choco {0}: https://raw.githubusercontent.com/wiki/chocolatey/choco/images/gifs/choco_search.gif ".FormatWith(configuration.CommandName)); - "chocolatey".Log().Info(ChocolateyLoggers.Important, "Alternative Sources"); "chocolatey".Log().Info(ChocolateyLoggers.Important, "Options and Switches"); } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs index 874d4471e3..12c3981bd0 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs @@ -70,10 +70,10 @@ public virtual void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfi "Bypass Proxy - Should this source explicitly bypass any explicitly or system configured proxies? Defaults to false.", option => configuration.SourceCommand.BypassProxy = option != null) .Add("allowselfservice|allow-self-service", - "Allow Self-Service - Should this source be allowed to be used with self-service? Requires business edition (v1.10.0+) with feature 'useBackgroundServiceWithSelfServiceSourcesOnly' turned on. Defaults to false.", + "Allow Self-Service - Should this source be allowed to be used with self-service? Requires business edition with feature 'useBackgroundServiceWithSelfServiceSourcesOnly' turned on. Defaults to false.", option => configuration.SourceCommand.AllowSelfService = option != null) .Add("adminonly|admin-only", - "Visible to Administrators Only - Should this source be visible to non-administrators? Requires business edition (v1.12.2+). Defaults to false.", + "Visible to Administrators Only - Should this source be visible to non-administrators? Requires business edition. Defaults to false.", option => configuration.SourceCommand.VisibleToAdminsOnly = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index 0111f65015..6048a023fa 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -248,7 +248,7 @@ private async static Task> SearchPackagesAsyn } else { - var exactPackage = FindPackage(searchTermLower, configuration, nugetLogger, cacheContext, packageRepositoryResources, version); + var exactPackage = FindPackage(searchTermLower, configuration, nugetLogger, (SourceCacheContext)cacheContext, packageRepositoryResources, version); if (exactPackage == null) { @@ -342,6 +342,28 @@ public static ISet FindAllPackageVersions(string package return metadataList; } + /// + /// Searches for packages that are available based on name and other options + /// + /// Name of package to search for + /// Chocolatey configuration used to help supply the search parameters + /// The nuget logger + /// The resources that should be queried + /// Version to search for + /// Settings for caching of results from sources + /// One result or nothing + [Obsolete("Use the overload that uses the base source cache context instead.")] + public static IPackageSearchMetadata FindPackage( + string packageName, + ChocolateyConfiguration config, + ILogger nugetLogger, + ChocolateySourceCacheContext cacheContext, + IEnumerable resources, + NuGetVersion version) + { + return FindPackage(packageName, config, nugetLogger, (SourceCacheContext)cacheContext, resources, version); + } + /// /// Searches for packages that are available based on name and other options /// diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index e91910412c..15cbbe8c6a 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -196,7 +196,6 @@ it is possible that incomplete package lists are returned from a command ChocolateyPackageMetadata packageLocalMetadata; string packageInstallLocation = null; - string deploymentLocation = null; if (package.PackagePath != null && !string.IsNullOrWhiteSpace(package.PackagePath)) { packageLocalMetadata = new ChocolateyPackageMetadata(package.PackagePath, _fileSystem); @@ -218,7 +217,6 @@ it is possible that incomplete package lists are returned from a command } } - deploymentLocation = packageInfo.DeploymentLocation; if (!string.IsNullOrWhiteSpace(packageInfo.Arguments)) { var decryptedArguments = ArgumentsUtility.DecryptPackageArgumentsFile(_fileSystem, packageInfo.Package.Id, packageInfo.Package.Version.ToNormalizedStringChecked()); @@ -251,7 +249,7 @@ Package url{6} Tags: {9} Software Site: {10} Software License: {11}{12}{13}{14}{15}{16} - Description: {17}{18}{19}{20} + Description: {17}{18}{19} ".FormatWith( package.Title.EscapeCurlyBraces(), package.Published.GetValueOrDefault().UtcDateTime.ToShortDateString(), @@ -286,7 +284,6 @@ Package url{6} package.Summary != null && !string.IsNullOrWhiteSpace(package.Summary.ToStringSafe()) ? "\r\n Summary: {0}".FormatWith(package.Summary.EscapeCurlyBraces().ToStringSafe()) : string.Empty, package.Description.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n "), !string.IsNullOrWhiteSpace(package.ReleaseNotes.ToStringSafe()) ? "{0} Release Notes: {1}".FormatWith(Environment.NewLine, package.ReleaseNotes.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n ")) : string.Empty, - !string.IsNullOrWhiteSpace(deploymentLocation) ? "{0} Deployed to: '{1}'".FormatWith(Environment.NewLine, deploymentLocation) : string.Empty, packageArgumentsUnencrypted != null ? packageArgumentsUnencrypted : string.Empty )); } @@ -513,8 +510,6 @@ public virtual ConcurrentDictionary Install(ChocolateyCon _fileSystem.EnsureDirectoryExists(ApplicationParameters.PackagesLocation); var packageResultsToReturn = new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase); - SetRemotePackageNamesIfAllSpecified(config, () => { }); - NuGetVersion version = !string.IsNullOrWhiteSpace(config.Version) ? NuGetVersion.Parse(config.Version) : null; if (config.Force) { @@ -523,6 +518,14 @@ public virtual ConcurrentDictionary Install(ChocolateyCon var sourceCacheContext = new ChocolateySourceCacheContext(config); var remoteRepositories = NugetCommon.GetRemoteRepositories(config, _nugetLogger, _fileSystem); + + // The following method HAS to be called AFTER the call to GetRemoteRepositories. + // In that method, the Sources on the configuration object are expanded to be the full source URL's, rather than the named + // sources from the chocolatey.config file, i.e. https://community.chocolatey.org/api/v2/ rather than simply "chocolatey". + // This is important, since the full URL is what is used to ensure that a "choco install all" is not being attempted against + // one of the configured public sources in the following method. + SetRemotePackageNamesIfAllSpecified(config, () => { }); + var remoteEndpoints = NugetCommon.GetRepositoryResources(remoteRepositories, sourceCacheContext); var localRepositorySource = NugetCommon.GetLocalRepository(); var pathResolver = NugetCommon.GetPathResolver(_fileSystem); @@ -628,7 +631,7 @@ public virtual ConcurrentDictionary Install(ChocolateyCon latestPackageVersion = version; } - var availablePackage = NugetList.FindPackage(packageName, config, _nugetLogger, sourceCacheContext, remoteEndpoints, latestPackageVersion); + var availablePackage = NugetList.FindPackage(packageName, config, _nugetLogger, (SourceCacheContext)sourceCacheContext, remoteEndpoints, latestPackageVersion); if (availablePackage == null) { @@ -1149,7 +1152,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon // this is a prerelease - opt in for newer prereleases. config.Prerelease = true; } - var availablePackage = NugetList.FindPackage(packageName, config, _nugetLogger, sourceCacheContext, remoteEndpoints, version); + var availablePackage = NugetList.FindPackage(packageName, config, _nugetLogger, (SourceCacheContext)sourceCacheContext, remoteEndpoints, version); config.Prerelease = originalPrerelease; @@ -1334,7 +1337,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon { if (version != null) { - var requestedPackageDependency = NugetList.FindPackage(parentPackage.Id, config, _nugetLogger, sourceCacheContext, remoteEndpoints, version); + var requestedPackageDependency = NugetList.FindPackage(parentPackage.Id, config, _nugetLogger, (SourceCacheContext)sourceCacheContext, remoteEndpoints, version); if (requestedPackageDependency != null) { diff --git a/src/chocolatey/infrastructure/registration/SimpleInjectorContainer.cs b/src/chocolatey/infrastructure/registration/SimpleInjectorContainer.cs index 595405dd7b..1261c869f6 100644 --- a/src/chocolatey/infrastructure/registration/SimpleInjectorContainer.cs +++ b/src/chocolatey/infrastructure/registration/SimpleInjectorContainer.cs @@ -38,12 +38,11 @@ public static class SimpleInjectorContainer private const string RegisterComponentsMethod = "RegisterComponents"; #if DEBUG + public static bool VerifyContainer { get; set; } = true; #else - private static bool _verifyContainer = false; + public static bool VerifyContainer { get; set; } = false; #endif - public static bool VerifyContainer { get; set; } = true; - /// /// Add a component registry class to the container. /// Must have `public void RegisterComponents(Container container)` diff --git a/tests/pester-tests/chocolatey.Tests.ps1 b/tests/pester-tests/chocolatey.Tests.ps1 index 2227c120e8..ea441658ac 100644 --- a/tests/pester-tests/chocolatey.Tests.ps1 +++ b/tests/pester-tests/chocolatey.Tests.ps1 @@ -195,20 +195,6 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat # $null = Invoke-Choco install MicrosoftWindowsPowerShellV2 -s windowsfeatures } - # This is Foss only as PowerShell running under version 2 doesn't have .net available and can't import the Licensed DLL. - # Tests on Windows 7 show no issues with running Chocolatey under Windows 7 with PowerShell v2 aside from issues surrounding TLS versions that we cannot resolve without an upgrade to Windows 7. - It "Imports ChocolateyInstaller module successfully in PowerShell v2" -Tag FossOnly { - $command = 'try { $ErrorActionPreference = ''Stop''; Import-Module $env:ChocolateyInstall\helpers\chocolateyInstaller.psm1 } catch { $_ ; exit 1 }' - $result = & powershell.exe -Version 2 -noprofile -command $command - $LastExitCode | Should -BeExactly 0 -Because $result - } - - It "Imports ChocolateyProfile module successfully in PowerShell v2" { - $command = 'try { $ErrorActionPreference = ''Stop''; Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 } catch { $_ ; exit 1 }' - $result = & powershell.exe -Version 2 -noprofile -command $command - $LastExitCode | Should -BeExactly 0 -Because $result - } - Context "chocolateyScriptRunner.ps1" { BeforeAll { $Command = @' diff --git a/tests/pester-tests/commands/choco-apikey.Tests.ps1 b/tests/pester-tests/commands/choco-apikey.Tests.ps1 index 5ed9daf81f..9660a61c30 100644 --- a/tests/pester-tests/commands/choco-apikey.Tests.ps1 +++ b/tests/pester-tests/commands/choco-apikey.Tests.ps1 @@ -371,6 +371,41 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, ApiKeyCommand { } } + Context "Adding an apikey when it is already added" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + # Ensure that the apikey is indeed set + $null = Invoke-Choco apikey add --source "https://somewhere.out/there/" --api-key "123-4567-89" + + $Output = Invoke-Choco apikey add --source "https://somewhere.out/there/" --api-key "123-4567-89" + } + + It "Exits with ExitCode 0" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco apikey add --source "https://somewhere.out/there/" --api-key "123-4567-89" + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } + } + # This needs to be the last test in this block, to ensure NuGet configurations aren't being created. Test-NuGetPaths } diff --git a/tests/pester-tests/commands/choco-config.Tests.ps1 b/tests/pester-tests/commands/choco-config.Tests.ps1 index 92868b84a3..3822126ba1 100644 --- a/tests/pester-tests/commands/choco-config.Tests.ps1 +++ b/tests/pester-tests/commands/choco-config.Tests.ps1 @@ -175,6 +175,38 @@ Describe "choco config" -Tag Chocolatey, ConfigCommand { } } + Context "Setting a configuration setting (cacheLocation) with same value that already exists" { + BeforeAll { + $null = Invoke-Choco config set cacheLocation "C:\temp\choco" + + $Output = Invoke-Choco config set cacheLocation "C:\temp\choco" + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco config set cacheLocation "C:\temp\choco" + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } + } + Context "Setting a configuration setting not available by default (newConfiguration)" { BeforeAll { $Output = Invoke-Choco config set --name newConfiguration --value some-value @@ -261,6 +293,7 @@ Describe "choco config" -Tag Chocolatey, ConfigCommand { Context "Unsetting a configuration that doesn't exist" { BeforeAll { + $null = Disable-ChocolateyFeature -Name "useEnhancedExitCodes" $Output = Invoke-Choco config unset not-existing [xml]$ConfigFileContent = Get-Content $env:ChocolateyInstall\config\chocolatey.config @@ -275,7 +308,7 @@ Describe "choco config" -Tag Chocolatey, ConfigCommand { $Output.Lines | Should -Contain $expectedLicenseHeader } - It "Displays config value Added" { + It "Changes nothing" { $Output.Lines | Should -Contain "Nothing to change. Config already set." } @@ -283,6 +316,22 @@ Describe "choco config" -Tag Chocolatey, ConfigCommand { $value = $configs.Where{ $_.key -eq "not-existing" } $value | Should -HaveCount 0 } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco config unset not-existing + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } } # This needs to be the last test in this block, to ensure NuGet configurations aren't being created. diff --git a/tests/pester-tests/commands/choco-feature.Tests.ps1 b/tests/pester-tests/commands/choco-feature.Tests.ps1 index 21322d8b78..48acb6a4ce 100644 --- a/tests/pester-tests/commands/choco-feature.Tests.ps1 +++ b/tests/pester-tests/commands/choco-feature.Tests.ps1 @@ -112,6 +112,76 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, FeatureCommand { } } + Context "Enabling a feature when it is already enabled" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + # Ensure that the feature is already enabled + $null = Invoke-Choco feature enable --name allowGlobalConfirmation + + $Output = Invoke-Choco feature enable --name allowGlobalConfirmation + } + + It "Exits with ExitCode 0" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco feature enable --name allowGlobalConfirmation + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } + } + + Context "Disabling a feature when it is already disabled" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + # Ensure that the feature is already disabled + $null = Invoke-Choco feature disable --name allowGlobalConfirmation + + $Output = Invoke-Choco feature disable --name allowGlobalConfirmation + } + + It "Exits with ExitCode 0" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco feature disable --name allowGlobalConfirmation + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } + } + Context "Disabling usePackageRepositoryOptimizations" { BeforeAll { Restore-ChocolateyInstallSnapshot diff --git a/tests/pester-tests/commands/choco-info.Tests.ps1 b/tests/pester-tests/commands/choco-info.Tests.ps1 index bc3eaa1a47..60c7b40747 100644 --- a/tests/pester-tests/commands/choco-info.Tests.ps1 +++ b/tests/pester-tests/commands/choco-info.Tests.ps1 @@ -12,6 +12,45 @@ Remove-ChocolateyTestInstall } + Context "Should include remembered arguments (including redacted) when using option --local-only" { + BeforeAll { + Initialize-ChocolateyTestInstall -Source $PSScriptRoot\testpackages + + $Setup = Invoke-Choco install installpackage --package-parameters="bob" --password="secure-password" --confirm + + $Setup.ExitCode | Should -Be 0 -Because $Setup.String + + $Output = Invoke-Choco info installpackage --local-only + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Should contain a summary" { + $Output.Lines | Should -Contain "Remembered Package Arguments:" -Because $Output.String + $Output.Lines | Should -Contain "--package-parameters='bob'" -Because $Output.String + $Output.Lines | Should -Contain "--password=[REDACTED ARGUMENT]" -Because $Output.String + } + } + + Context "Should include configured sources" { + BeforeAll { + Initialize-ChocolateyTestInstall -Source $PSScriptRoot\testpackages + Invoke-Choco install installpackage --confirm + + $Output = Invoke-Choco info installpackage --include-configured-sources --debug + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Should mention that configured sources have been included" { + $Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String + } + } + Context "Listing package information when package can be found" { BeforeDiscovery { $infoItems = @( @@ -187,11 +226,11 @@ } It 'Outputs warning about unable to load service index' { - $Output.Lines | Should -Contain "Unable to load the service index for source $InvalidSource." + $Output.Lines | Should -Contain "Unable to load the service index for source $InvalidSource." -Because $Output.String } It 'Output information about the package' { - $Output.String | Should -Match "Title: Chocolatey " + $Output.String | Should -Match "Title: Chocolatey " -Because $Output.String } } diff --git a/tests/pester-tests/commands/choco-install.Tests.ps1 b/tests/pester-tests/commands/choco-install.Tests.ps1 index 6f19163f24..67b40473f2 100644 --- a/tests/pester-tests/commands/choco-install.Tests.ps1 +++ b/tests/pester-tests/commands/choco-install.Tests.ps1 @@ -83,7 +83,153 @@ $PackageUnderTest = "installpackage" - $Output = Invoke-Choco install $PackageUnderTest --confirm + $Output = Invoke-Choco install $PackageUnderTest --debug --confirm + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Installed a package to the lib directory" { + "$env:ChocolateyInstall\lib\$PackageUnderTest" | Should -Exist + } + + # We are skipping this for now, until we have stabilized the directory + # path reporting functionality. There are times that this test will + # fail due to Chocolatey not reporting the path. + # This failure seems to happen randomly, and is therefore not a + # reliable test we can make. + It "Outputs the installation directory (which should exist)" -Skip { + $directoryPath = "$env:ChocolateyInstall\lib\$PackageUnderTest" + $lineRegex = [regex]::Escape($directoryPath) + + $foundPath = $Output.Lines -match $lineRegex + $foundPath | Should -Not -BeNullOrEmpty + $foundPath | Should -Exist + } + + It "Installs the expected version of the package" { + "$env:ChocolateyInstall\lib\$PackageUnderTest\$PackageUnderTest.nuspec" | Should -Exist + [xml]$XML = Get-Content "$env:ChocolateyInstall\lib\$PackageUnderTest\$PackageUnderTest.nuspec" + $XML.package.metadata.version | Should -Be "1.0.0" + } + + It "Creates a Console Shim in the Bin Directory" { + "$env:ChocolateyInstall\bin\console.exe" | Should -Exist + } + + It "Creates a Graphical Shim in the Bin Directory" { + "$env:ChocolateyInstall\bin\graphical.exe" | Should -Exist + } + + It "Does not create a Shim for Ignored Executable in the Bin Directory" { + "$env:ChocolateyInstall\bin\not.installed.exe" | Should -Not -Exist + } + + It "Does not create a Shim for Ignored Executable (with mismatched case) in the Bin Directory" { + "$env:ChocolateyInstall\bin\casemismatch.exe" | Should -Not -Exist + } + + It "Does not create an extensions folder for the package" { + "$env:ChocolateyInstall\extensions\$PackageUnderTest" | Should -Not -Exist + } + + It "Contains the output of the ChocolateyInstall.ps1 script" { + $Output.Lines | Should -Contain "Ya!" + } + + It "Outputs a message showing that installation was successful" { + $Output.String | Should -Match "Chocolatey installed 1/1 packages\." + } + + It "Should mention that package hash verification has been skipped" { + $Output.Lines | Should -Contain "Skipping package hash validation as feature 'usePackageHashValidation' is not enabled." -Because $Output.String + } + } + + Context "Installing a Package (Happy Path) with hash validation enabled" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + $null = Enable-ChocolateyFeature -Name "usePackageHashValidation" + + $PackageUnderTest = "installpackage" + + $Output = Invoke-Choco install $PackageUnderTest --debug --confirm + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Installed a package to the lib directory" { + "$env:ChocolateyInstall\lib\$PackageUnderTest" | Should -Exist + } + + # We are skipping this for now, until we have stabilized the directory + # path reporting functionality. There are times that this test will + # fail due to Chocolatey not reporting the path. + # This failure seems to happen randomly, and is therefore not a + # reliable test we can make. + It "Outputs the installation directory (which should exist)" -Skip { + $directoryPath = "$env:ChocolateyInstall\lib\$PackageUnderTest" + $lineRegex = [regex]::Escape($directoryPath) + + $foundPath = $Output.Lines -match $lineRegex + $foundPath | Should -Not -BeNullOrEmpty + $foundPath | Should -Exist + } + + It "Installs the expected version of the package" { + "$env:ChocolateyInstall\lib\$PackageUnderTest\$PackageUnderTest.nuspec" | Should -Exist + [xml]$XML = Get-Content "$env:ChocolateyInstall\lib\$PackageUnderTest\$PackageUnderTest.nuspec" + $XML.package.metadata.version | Should -Be "1.0.0" + } + + It "Creates a Console Shim in the Bin Directory" { + "$env:ChocolateyInstall\bin\console.exe" | Should -Exist + } + + It "Creates a Graphical Shim in the Bin Directory" { + "$env:ChocolateyInstall\bin\graphical.exe" | Should -Exist + } + + It "Does not create a Shim for Ignored Executable in the Bin Directory" { + "$env:ChocolateyInstall\bin\not.installed.exe" | Should -Not -Exist + } + + It "Does not create a Shim for Ignored Executable (with mismatched case) in the Bin Directory" { + "$env:ChocolateyInstall\bin\casemismatch.exe" | Should -Not -Exist + } + + It "Does not create an extensions folder for the package" { + "$env:ChocolateyInstall\extensions\$PackageUnderTest" | Should -Not -Exist + } + + It "Contains the output of the ChocolateyInstall.ps1 script" { + $Output.Lines | Should -Contain "Ya!" + } + + It "Outputs a message showing that installation was successful" { + $Output.String | Should -Match "Chocolatey installed 1/1 packages\." + } + + It "Should mention that package hash verification was skipped since local folder source is being used" { + if ((Test-HasNuGetV3Source) -or (-not $env:TEST_KITCHEN)) { + $Output.Lines | Should -Contain "Source does not provide a package hash, skipping package hash validation." -Because $Output.String + } else { + $Output.Lines | Should -Contain "Package hash matches expected hash." -Because $Output.String + } + } + } + + Context "Installing a Package (Happy Path) including configured sources" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + $PackageUnderTest = "installpackage" + + $Output = Invoke-Choco install $PackageUnderTest --include-configured-sources --debug --confirm } It "Exits with Success (0)" { @@ -141,6 +287,10 @@ It "Outputs a message showing that installation was successful" { $Output.String | Should -Match "Chocolatey installed 1/1 packages\." } + + It "Should mention that configured sources have been included" { + $Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String + } } Context "Installing a Package with Packages.config" { diff --git a/tests/pester-tests/commands/choco-outdated.Tests.ps1 b/tests/pester-tests/commands/choco-outdated.Tests.ps1 index c24de65af2..d269e95e49 100644 --- a/tests/pester-tests/commands/choco-outdated.Tests.ps1 +++ b/tests/pester-tests/commands/choco-outdated.Tests.ps1 @@ -23,6 +23,20 @@ Describe "choco outdated" -Tag Chocolatey, OutdatedCommand { Remove-ChocolateyTestInstall } + Context "Should include configured sources" { + BeforeAll { + $Output = Invoke-Choco outdated --include-configured-sources --debug + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Should mention that configured sources have been included" { + $Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String + } + } + Context "outdated ignore-pinned uses correct enhanced exit codes" -ForEach @( @{ Argument = '' ; ExitCode = 2 } @{ Argument = '--ignore-pinned' ; ExitCode = 0 } diff --git a/tests/pester-tests/commands/choco-pin.Tests.ps1 b/tests/pester-tests/commands/choco-pin.Tests.ps1 index 465b434cf7..7e8f0e0725 100644 --- a/tests/pester-tests/commands/choco-pin.Tests.ps1 +++ b/tests/pester-tests/commands/choco-pin.Tests.ps1 @@ -112,6 +112,24 @@ Describe "choco pin" -Tag Chocolatey, PinCommand { $Output.Lines | Should -Contain "Nothing to change. Pin already set or removed." $CurrentPins | Should -Contain "upgradepackage|1.0.0$listSuffix" } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco pin add --name upgradepackage + $CurrentPins = Invoke-Choco pin list --LimitOutput | ForEach-Object Lines + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Pin already set or removed." + $CurrentPins | Should -Contain "upgradepackage|1.0.0$listSuffix" + } + } } Context "Setting a Pin for a non-installed Package" { diff --git a/tests/pester-tests/commands/choco-push.Tests.ps1 b/tests/pester-tests/commands/choco-push.Tests.ps1 index 429503aa51..63a2a002f6 100644 --- a/tests/pester-tests/commands/choco-push.Tests.ps1 +++ b/tests/pester-tests/commands/choco-push.Tests.ps1 @@ -40,8 +40,8 @@ Describe "choco push" -Tag Chocolatey, PushCommand, ProxySkip -Skip:($null -eq $ It "Should Report the actual cause of the error" { $Output.Lines | Should -Contain "Attempting to push $PackageUnderTest.$VersionUnderTest.nupkg to $RepositoryToUse" -Because $Output.String - $Output.Lines | Should -Contain "An error has occurred. It's possible the package version already exists on the repository or a nuspec element is invalid. See error below..." -Because $Output.String - $Output.Lines | Should -Contain "Response status code does not indicate success: 409 (Conflict)." -Because $Output.String + $Output.Lines | Should -Contain "An error has occurred. This package version already exists on the repository and cannot be modified." -Because $Output.String + $Output.Lines | Should -Contain "Package versions that are approved, rejected, or exempted cannot be modified." -Because $Output.String } } @@ -71,7 +71,7 @@ Describe "choco push" -Tag Chocolatey, PushCommand, ProxySkip -Skip:($null -eq $ It "Should Report the actual cause of the error" { $Output.Lines | Should -Contain "Attempting to push $PackageUnderTest.$VersionUnderTest.nupkg to $RepositoryToUse" -Because $Output.String $Output.Lines | Should -Contain "An error has occurred. It's possible the package version already exists on the repository or a nuspec element is invalid. See error below..." -Because $Output.String - $Output.Lines | Should -Contain "Response status code does not indicate success: 409 (Conflict)." -Because $Output.String + $Output.Lines | Should -Contain "Response status code does not indicate success: 409 (This package had an issue pushing: A nuget package's Description property may not be more than 4000 characters long.)." -Because $Output.String } } @@ -101,7 +101,7 @@ Describe "choco push" -Tag Chocolatey, PushCommand, ProxySkip -Skip:($null -eq $ It "Should Report the actual cause of the error" { $Output.Lines | Should -Contain "Attempting to push $PackageUnderTest.$VersionUnderTest.nupkg to $RepositoryToUse" -Because $Output.String $Output.Lines | Should -Contain "An error has occurred. It's possible the package version already exists on the repository or a nuspec element is invalid. See error below..." -Because $Output.String - $Output.Lines | Should -Contain "Response status code does not indicate success: 409 (Conflict)." -Because $Output.String + $Output.Lines | Should -Contain "Response status code does not indicate success: 409 (This package had an issue pushing: A nuget package's Title property may not be more than 256 characters long.)." -Because $Output.String } } diff --git a/tests/pester-tests/commands/choco-rule.Tests.ps1 b/tests/pester-tests/commands/choco-rule.Tests.ps1 new file mode 100644 index 0000000000..b2fc482eb9 --- /dev/null +++ b/tests/pester-tests/commands/choco-rule.Tests.ps1 @@ -0,0 +1,92 @@ +Import-Module helpers/common-helpers + +Describe "choco rule" -Tag Chocolatey, RuleCommand { + BeforeDiscovery { + } + + BeforeAll { + Remove-NuGetPaths + Initialize-ChocolateyTestInstall + + New-ChocolateyInstallSnapshot + } + + AfterAll { + Remove-ChocolateyTestInstall + } + + Context "Running without subcommand specified" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + $Output = Invoke-Choco rule + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Displays the rules expected" { + $Output.Lines | Should -Contain 'CHCR0001: A required element is missing or has no content in the package nuspec file.' -Because $Output.String + $Output.Lines | Should -Contain 'CHCR0002: Enabling license acceptance requires a license url.' -Because $Output.String + $Output.Lines | Should -Contain 'CHCU0001: The specified content of the element is not of the expected type and can not be accepted.' -Because $Output.String + $Output.Lines | Should -Contain 'CHCU0002: Unsupported element is used.' -Because $Output.String + } + } + + Context "Running with list subcommand" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + $Output = Invoke-Choco rule list + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Displays the rules expected" { + $Output.Lines | Should -Contain 'CHCR0001: A required element is missing or has no content in the package nuspec file.' -Because $Output.String + $Output.Lines | Should -Contain 'CHCR0002: Enabling license acceptance requires a license url.' -Because $Output.String + $Output.Lines | Should -Contain 'CHCU0001: The specified content of the element is not of the expected type and can not be accepted.' -Because $Output.String + $Output.Lines | Should -Contain 'CHCU0002: Unsupported element is used.' -Because $Output.String + } + } + + Context "Running with get subcommand specified with no additional parameters" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + $Output = Invoke-Choco rule get + } + + It "Exits with Failure (1)" { + $Output.ExitCode | Should -Be 1 -Because $Output.String + } + + It "Displays error with correct format" { + $Output.Lines | Should -Contain "A Rule Name (-n|--name) is required when getting information for a specific rule." -Because $Output.String + } + } + + Context "Running with get subcommand specified with --name parameter" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + $Output = Invoke-Choco rule get --name CHCU0001 + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Displays rule information" { + $Output.Lines | Should -Contain "Name: CHCU0001 | Severity: Error" -Because $Output.String + $Output.Lines | Should -Contain "Summary: The specified content of the element is not of the expected type and can not be accepted." -Because $Output.String + $Output.Lines | Should -Contain "Help URL:" -Because $Output.String + } + } + + # This needs to be the last test in this block, to ensure NuGet configurations aren't being created. + Test-NuGetPaths +} \ No newline at end of file diff --git a/tests/pester-tests/commands/choco-search.Tests.ps1 b/tests/pester-tests/commands/choco-search.Tests.ps1 index 15b4fe5801..2aefee9dd4 100644 --- a/tests/pester-tests/commands/choco-search.Tests.ps1 +++ b/tests/pester-tests/commands/choco-search.Tests.ps1 @@ -64,6 +64,20 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, SearchCommand, FindComma } } + Context "Should include configured sources" { + BeforeAll { + $Output = Invoke-Choco $_ upgradepackage --include-configured-sources --debug + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Should mention that configured sources have been included" { + $Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String + } + } + Context "Searching for a particular package" { BeforeAll { $Output = Invoke-Choco $_ upgradepackage diff --git a/tests/pester-tests/commands/choco-source.Tests.ps1 b/tests/pester-tests/commands/choco-source.Tests.ps1 index 701550edad..36ae2a9866 100644 --- a/tests/pester-tests/commands/choco-source.Tests.ps1 +++ b/tests/pester-tests/commands/choco-source.Tests.ps1 @@ -67,6 +67,45 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, SourceCommand { } } + Context "Add source that already exists" { + BeforeAll { + $null = Disable-ChocolateyFeature -Name "useEnhancedExitCodes" + + # Ensure source is already added + Invoke-Choco $CurrentCommand add --name "already-exists" --source "https://somewhere/out/there/" + + $Output = Invoke-Choco $CurrentCommand add --name "already-exists" --source "https://somewhere/out/there/" + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Displays chocolatey name with version" { + $Output.Lines | Should -Contain $expectedHeader + } + + It "Displays no change made" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco $CurrentCommand add --name "already-exists" --source "https://somewhere/out/there/" + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } + } + Context "Add single unauthenticated source with priority" { BeforeAll { $Output = Invoke-Choco $CurrentCommand add --name "dummy-long" --source "https://priority.test.com/api" --priority 1 @@ -304,6 +343,8 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, SourceCommand { Context "Removing missing source" { BeforeAll { + $null = Disable-ChocolateyFeature -Name "useEnhancedExitCodes" + # Make sure the source is removed Invoke-Choco $CurrentCommand remove --name "not-existing" @@ -321,6 +362,22 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, SourceCommand { It "Displays message about no change made" { $Output.Lines | Should -Contain "Nothing to change. Config already set." } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco $CurrentCommand remove --name "not-existing" + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } } Context "Disabling existing source" { @@ -387,6 +444,8 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, SourceCommand { Context "Disabling missing source" { BeforeAll { + $null = Disable-ChocolateyFeature -Name "useEnhancedExitCodes" + # Ensure source is not available Invoke-Choco $CurrentCommand remove --name "not-existing" @@ -404,10 +463,68 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, SourceCommand { It "Displays no change made" { $Output.Lines | Should -Contain "Nothing to change. Config already set." } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco $CurrentCommand disable --name "not-existing" + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } + } + + Context "Disabling source that is already disabled" { + BeforeAll { + $null = Disable-ChocolateyFeature -Name "useEnhancedExitCodes" + + # Ensure source is not available + Invoke-Choco $CurrentCommand add --name "already-disabled" --source "https://somewhere/out/there/" + Invoke-Choco $CurrentCommand disable --name "already-disabled" + + $Output = Invoke-Choco $CurrentCommand disable --name "already-disabled" + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Displays chocolatey name with version" { + $Output.Lines | Should -Contain $expectedHeader + } + + It "Displays no change made" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco $CurrentCommand disable --name "already-disabled" + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } } Context "Enabling missing source" { BeforeAll { + $null = Disable-ChocolateyFeature -Name "useEnhancedExitCodes" + # Ensure source is not available Invoke-Choco $CurrentCommand remove --name "not-existing" @@ -425,6 +542,62 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, SourceCommand { It "Displays no change made" { $Output.Lines | Should -Contain "Nothing to change. Config already set." } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco $CurrentCommand enable --name "not-existing" + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } + } + + Context "Enabling source that is already enabled" { + BeforeAll { + $null = Disable-ChocolateyFeature -Name "useEnhancedExitCodes" + + # Ensure source is enable + Invoke-Choco $CurrentCommand add --name "already-enabled" --source "https://somewhere/out/there/" + Invoke-Choco $CurrentCommand enable --name "already-enabled" + + $Output = Invoke-Choco $CurrentCommand enable --name "already-enabled" + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Displays chocolatey name with version" { + $Output.Lines | Should -Contain $expectedHeader + } + + It "Displays no change made" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco $CurrentCommand enable --name "already-enabled" + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Config already set." + } + } } # This needs to be the last test in this block, to ensure NuGet configurations aren't being created. diff --git a/tests/pester-tests/commands/choco-upgrade.Tests.ps1 b/tests/pester-tests/commands/choco-upgrade.Tests.ps1 index 1521a0bf7c..c0f876b07d 100644 --- a/tests/pester-tests/commands/choco-upgrade.Tests.ps1 +++ b/tests/pester-tests/commands/choco-upgrade.Tests.ps1 @@ -11,6 +11,36 @@ Remove-ChocolateyTestInstall } + Context "Upgrade pinned package using () option" -ForEach @( + @{ Command = '--ignore-pinned' ; Contains = $true } + @{ Command = '' ; Contains = $false } + ) { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + $Package = 'upgradepackage' + + # This test relies on the correct usage of the --pin option on the install + # command, but this is tested elsewhere + $null = Invoke-Choco install $Package --pin --version 1.0.0 --confirm + $null = Invoke-Choco upgrade $Package $Command --confirm + $Output = Invoke-Choco pin list + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Output should include upgraded package, with new pin in place" { + if ($Contains) { + $Output.String | Should -Match "$Package|1.1.0" + } + else { + $Output.String | Should -Match "$Package|1.0.0" + } + } + } + Context "Upgrade package with () specified" -ForEach @( @{ Command = '--pin' ; Contains = $true } @{ Command = '' ; Contains = $false } @@ -73,6 +103,96 @@ } } + Context "Should include configured sources" { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + Enable-ChocolateySource -Name hermes-setup + $null = Invoke-Choco install wget + + $Output = Invoke-Choco upgrade wget --include-configured-sources --debug + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Should mention that configured sources have been included" { + $Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String + } + } + + Context "Attempt to upgrade a package when there isn't an upgrade available" -Tag Internal { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + Enable-ChocolateySource -Name hermes-setup + $null = Invoke-Choco install wget + + $Output = Invoke-Choco upgrade wget + } + + It 'Exits with Success (0)' { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It 'Displays that upgrade was attempted but wasnt required' { + $Output.Lines | Should -Contain "Chocolatey upgraded 0/1 packages." -Because $Output.String + } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco upgrade wget + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It 'Displays that upgrade was attempted but wasnt required' { + $Output.Lines | Should -Contain "Chocolatey upgraded 0/1 packages." -Because $Output.String + } + } + } + + Context "Attempt to run upgrade all when there isn't any upgrade available" -Tag Internal { + BeforeAll { + Restore-ChocolateyInstallSnapshot + + Enable-ChocolateySource -Name hermes-setup + $null = Invoke-Choco install wget + $null = Invoke-Choco install curl + + $Output = Invoke-Choco upgrade all + } + + It 'Exits with Success (0)' { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It 'Displays that upgrade was attempted but wasnt required' { + $Output.String | Should -MatchExactly "Chocolatey upgraded 0" + } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco upgrade all + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It 'Displays that upgrade was attempted but wasnt required' { + $Output.String | Should -MatchExactly "Chocolatey upgraded 0" + } + } + } + # We exclude this test when running CCM, as it will install and remove # the firefox package which is used through other tests that will be affected. Context "Upgrading packages while remembering arguments with multiple packages using arguments" -Tag CCMExcluded, Internal, VMOnly { diff --git a/tests/pester-tests/features/CygwinSource.Tests.ps1 b/tests/pester-tests/features/CygwinSource.Tests.ps1 new file mode 100644 index 0000000000..90f3b78ef6 --- /dev/null +++ b/tests/pester-tests/features/CygwinSource.Tests.ps1 @@ -0,0 +1,30 @@ +Import-Module helpers/common-helpers + +# This is skipped when not run in CI because it modifies the local system. +Describe "Cygwin Source" -Tag Chocolatey, CygwinSource -Skip:(-not $env:TEST_KITCHEN) { + BeforeAll { + Initialize-ChocolateyTestInstall + New-ChocolateyInstallSnapshot + Enable-ChocolateySource -Name hermes-setup + $null = Invoke-Choco install cygwin + } + + AfterAll { + $null = Invoke-Choco uninstall cygwin --remove-dependencies + Remove-ChocolateyTestInstall + } + + Context "install all" { + BeforeAll { + $Output = Invoke-Choco install all --source=cygwin + } + + It 'Exits with exit code (1)' { + $Output.ExitCode | Should -Be 1 -Because $Output.String + } + + It 'Outputs exception' { + $Output.Lines | Should -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String + } + } +} \ No newline at end of file diff --git a/tests/pester-tests/features/PythonSource.Tests.ps1 b/tests/pester-tests/features/PythonSource.Tests.ps1 index 63d91cf424..2a0aad6b67 100644 --- a/tests/pester-tests/features/PythonSource.Tests.ps1 +++ b/tests/pester-tests/features/PythonSource.Tests.ps1 @@ -27,12 +27,29 @@ Describe "Python Source" -Tag Chocolatey, UpgradeCommand, PythonSource, ProxySki } It 'Exits with correct exit code ()' { - $Output.ExitCode | Should -Be $ExitCode + $Output.ExitCode | Should -Be $ExitCode -Because $Output.String } It 'Outputs properly' { - $Output.Lines | Should -Not:($ExitCode -eq 0) -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." - $Output.Lines | Should -Contain "Chocolatey upgraded $Count/$Count packages." + $Output.Lines | Should -Not:($ExitCode -eq 0) -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String + $Output.Lines | Should -Contain "Chocolatey upgraded $Count/$Count packages." -Because $Output.String + } + } + + Context "install all" { + BeforeAll { + # For some reason under kitchen-pester we don't have pip on the path. This might be due to our snapshotting... + Import-Module $env:ChocolateyInstall/helpers/ChocolateyProfile.psm1 + Update-SessionEnvironment + $Output = Invoke-Choco install all --source=python + } + + It 'Exits with exit code (1)' { + $Output.ExitCode | Should -Be 1 -Because $Output.String + } + + It 'Outputs exception' { + $Output.Lines | Should -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String } } } diff --git a/tests/pester-tests/features/RubySource.Tests.ps1 b/tests/pester-tests/features/RubySource.Tests.ps1 new file mode 100644 index 0000000000..83aba65f82 --- /dev/null +++ b/tests/pester-tests/features/RubySource.Tests.ps1 @@ -0,0 +1,30 @@ +Import-Module helpers/common-helpers + +# This is skipped when not run in CI because it modifies the local system. +Describe "Ruby Source" -Tag Chocolatey, RubySource -Skip:(-not $env:TEST_KITCHEN) { + BeforeAll { + Initialize-ChocolateyTestInstall + New-ChocolateyInstallSnapshot + Enable-ChocolateySource -Name hermes-setup + $null = Invoke-Choco install ruby.portable + } + + AfterAll { + $null = Invoke-Choco uninstall ruby.portable --remove-dependencies + Remove-ChocolateyTestInstall + } + + Context "install all" { + BeforeAll { + $Output = Invoke-Choco install all --source=ruby + } + + It 'Exits with exit code (1)' { + $Output.ExitCode | Should -Be 1 -Because $Output.String + } + + It 'Outputs exception' { + $Output.Lines | Should -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String + } + } +} \ No newline at end of file diff --git a/tests/pester-tests/features/WindowsFeaturesSource.Tests.ps1 b/tests/pester-tests/features/WindowsFeaturesSource.Tests.ps1 new file mode 100644 index 0000000000..53bd633ea0 --- /dev/null +++ b/tests/pester-tests/features/WindowsFeaturesSource.Tests.ps1 @@ -0,0 +1,26 @@ +Import-Module helpers/common-helpers + +Describe "Windows Features Source" -Tag Chocolatey, WindowsFeaturesSource { + BeforeAll { + Initialize-ChocolateyTestInstall + New-ChocolateyInstallSnapshot + } + + AfterAll { + Remove-ChocolateyTestInstall + } + + Context "install all" { + BeforeAll { + $Output = Invoke-Choco install all --source=windowsfeatures + } + + It 'Exits with exit code (1)' { + $Output.ExitCode | Should -Be 1 -Because $Output.String + } + + It 'Outputs exception' { + $Output.Lines | Should -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String + } + } +} \ No newline at end of file diff --git a/tests/pester-tests/powershell-commands/Get-EnvironmentVariable.Tests.ps1 b/tests/pester-tests/powershell-commands/Get-EnvironmentVariable.Tests.ps1 index d0bf326a46..0e6c58f98f 100644 --- a/tests/pester-tests/powershell-commands/Get-EnvironmentVariable.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Get-EnvironmentVariable.Tests.ps1 @@ -21,9 +21,19 @@ Describe 'Get-EnvironmentVariable helper function tests' -Tags Cmdlets { } } - Context 'Can retrieve the PATH variable without expanding environment names for the scope' { - It 'Retrieves the PATH value with un-expanded environment names' { - Get-EnvironmentVariable -Name 'PATH' -Scope 'Machine' | Should -Match '%[^%;\]+%' + Context 'Can retrieve the PATH variable without expanding environment names for the Machine scope' { + BeforeAll { + Install-ChocolateyPath -Path "%systemroot%\test" -PathType Machine + } + + AfterAll { + Uninstall-ChocolateyPath -Path "%systemroot%\test" -PathType Machine + } + + It 'Retrieves the Machine PATH value with un-expanded environment names' { + # We expect there to be an entry similar to the following: "%SystemRoot%\system32", since this + # is there by default in a Windows install + Get-EnvironmentVariable -Name 'PATH' -Scope 'Machine' -PreserveVariables | Should -Match '%systemroot%\\test' } } } \ No newline at end of file diff --git a/tests/pester-tests/powershell-commands/Install-ChocolateyPath.Tests.ps1 b/tests/pester-tests/powershell-commands/Install-ChocolateyPath.Tests.ps1 index 81706033bf..379a73db76 100644 --- a/tests/pester-tests/powershell-commands/Install-ChocolateyPath.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Install-ChocolateyPath.Tests.ps1 @@ -16,9 +16,13 @@ @{ Scope = 'Machine' } ) { Context 'Path "<_>"' -ForEach @("C:\test", "C:\tools") { + AfterEach { + Uninstall-ChocolateyPath -Path $_ -Scope $Scope + } + It 'stores the value in the desired PATH scope' { Install-ChocolateyPath -Path $_ -Scope $Scope - [Environment]::GetEnvironmentVariable('PATH', $_, $Scope) -split [IO.Path]::PathSeparator | Should -Contain $_ + [Environment]::GetEnvironmentVariable('PATH', $Scope) -split [IO.Path]::PathSeparator | Should -Contain $_ } } } diff --git a/tests/pester-tests/powershell-commands/Set-EnvironmentVariable.Tests.ps1 b/tests/pester-tests/powershell-commands/Set-EnvironmentVariable.Tests.ps1 index 6b5cc580cd..7e67ca9e2a 100644 --- a/tests/pester-tests/powershell-commands/Set-EnvironmentVariable.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Set-EnvironmentVariable.Tests.ps1 @@ -6,7 +6,7 @@ Describe 'Set-EnvironmentVariable helper function tests' -Tags Cmdlets { Import-Module "$testLocation\helpers\chocolateyInstaller.psm1" } - Context 'Sets an environment variable value at the target scope' -ForEach @( + Context 'Sets an environment variable value at the target ' -ForEach @( @{ Scope = 'Process' } @{ Scope = 'User' } @{ Scope = 'Machine' } @@ -20,18 +20,21 @@ Describe 'Set-EnvironmentVariable helper function tests' -Tags Cmdlets { } Describe 'Setting environment variable ' -ForEach $variables { - It 'Sets the target environment variable in the proper scope, as well as current process scope' { + BeforeAll { Set-EnvironmentVariable -Name $Name -Value $Value -Scope $Scope - [Environment]::GetEnvironmentVariable($Name, $Scope) | Should -BeExactly $Value - - if ($Scope -ne 'Process') { - [Environment]::GetEnvironmentVariable($Name) | Should -BeExactly $Value - } } AfterAll { Set-EnvironmentVariable -Name $Name -Value "" -Scope $Scope } + + It 'sets the target environment variable in the proper scope' { + [Environment]::GetEnvironmentVariable($Name, $Scope) | Should -BeExactly $Value + } + + It 'propagates the change to the current process' { + Get-Content "Env:\$Name" | Should -BeExactly $Value + } } } } \ No newline at end of file diff --git a/tests/pester-tests/powershell-commands/Uninstall-ChocolateyPath.Tests.ps1 b/tests/pester-tests/powershell-commands/Uninstall-ChocolateyPath.Tests.ps1 index 6d15ff28c1..29dbeec65b 100644 --- a/tests/pester-tests/powershell-commands/Uninstall-ChocolateyPath.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Uninstall-ChocolateyPath.Tests.ps1 @@ -18,7 +18,7 @@ It 'removes a stored PATH value in the desired PATH scope' { Uninstall-ChocolateyPath -Path $_ -Scope $Scope - [Environment]::GetEnvironmentVariable('PATH', $_, $Scope) -split [IO.Path]::PathSeparator | Should -Not -Contain $_ + [Environment]::GetEnvironmentVariable('PATH', $Scope) -split [IO.Path]::PathSeparator | Should -Not -Contain $_ } } } diff --git a/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 b/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 index 742bc3da5f..9f8bcccbc6 100644 --- a/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 @@ -17,12 +17,13 @@ Update-SessionEnvironment $env:Test | Should -BeExactly 'user-value' $env:Test2 | Should -BeExactly 'machine-value' - $env:Test3 | Should -BeNullOrEmpty -Because 'Process-only values should not be preserved' + $env:Test3 | Should -BeExactly 'process-value' } AfterAll { [Environment]::SetEnvironmentVariable("Test", [string]::Empty, "User") [Environment]::SetEnvironmentVariable("Test2", [string]::Empty, "Machine") + $env:Test3 = '' } } } \ No newline at end of file