Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  reference chocolateyErrored from script scope in chocolatey.ps1 in case chocolatey is intercepted from a module (like boxstarter)
  write to the correctly scopped chocolateyErrored variable
  (shimgen) updating shims
  • Loading branch information
ferventcoder committed Jan 22, 2015
2 parents ad6b488 + bcea921 commit b77f9b1
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/chocolatey.ps1
Expand Up @@ -166,7 +166,7 @@ if ($forceX86) {

$env:chocolateyPackageParameters = $packageParameters

$chocolateyErrored = $false
$script:chocolateyErrored = $false
$badPackages = ''

#todo: This does not catch package names that come later
Expand All @@ -193,7 +193,7 @@ foreach ($packageName in $packageNames) {
}
}
catch {
$chocolateyErrored = $true
$script:chocolateyErrored = $true
Write-Host "$($_.Exception.Message)" -BackgroundColor $ErrorColor -ForegroundColor White ;
if ($badPackages -ne '') { $badPackages += ', '}
$badPackages += "$packageName"
Expand All @@ -208,7 +208,7 @@ if ($badPackages -ne '') {
Write-Host "Command `'$command`' failed (sometimes this indicates a partial failure). Additional info/packages: $badpackages" -BackgroundColor $ErrorColor -ForegroundColor White
}

if ($chocolateyErrored) {
if ($script:chocolateyErrored) {
Write-Debug "Exiting with non-zero exit code."
exit 1
}
Expand Down
4 changes: 2 additions & 2 deletions src/functions/Chocolatey-NuGet.ps1
Expand Up @@ -76,7 +76,7 @@ Write-Debug "Installing packages to `"$nugetLibPath`"."
Write-Host " "
Write-Host "$installedPackageName v$installedPackageVersion" -ForegroundColor $Note -BackgroundColor Black

if ([System.IO.Directory]::Exists($packageFolder)) {
if (Test-Path $packageFolder) {
try {
Delete-ExistingErrorLog $installedPackageName
Run-ChocolateyPS1 $packageFolder $installedPackageName "install" $installerArguments
Expand All @@ -90,7 +90,7 @@ Write-Debug "Installing packages to `"$nugetLibPath`"."
Write-Error "Package `'$installedPackageName v$installedPackageVersion`' did not install successfully: $($_.Exception.Message)"
if ($badPackages -ne '') { $badPackages += ', '}
$badPackages += "$packageName"
$chocolateyErrored = $true
$script:chocolateyErrored = $true
}
}
}
Expand Down
Binary file modified src/redirects/choco.exe
Binary file not shown.
Binary file modified src/redirects/chocolatey.exe
Binary file not shown.
Binary file modified src/redirects/cinst.exe
Binary file not shown.
Binary file modified src/redirects/clist.exe
Binary file not shown.
Binary file modified src/redirects/cpack.exe
Binary file not shown.
Binary file modified src/redirects/cpush.exe
Binary file not shown.
Binary file modified src/redirects/cuninst.exe
Binary file not shown.
Binary file modified src/redirects/cup.exe
Binary file not shown.
Binary file modified src/redirects/cver.exe
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/unit/Chocolatey-NuGet.tests.ps1
@@ -1,6 +1,7 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Definition
$common = Join-Path (Split-Path -Parent $here) '_Common.ps1'
. $common
$chocolateyErrored = $false

Describe "Chocolatey-NuGet" {
Context "under normal circumstances" {
Expand All @@ -17,6 +18,22 @@ Describe "Chocolatey-NuGet" {
}
}

Context "chocolateyPS1 throws an error" {
$nugetLibPath = "c:\fake-lib"
Mock Update-SessionEnvironment
Mock Run-NuGet {"Successfully installed 'somepackage 1.0.0'"} -Verifiable -ParameterFilter {$packageName -eq 'somepackage'}
Mock Run-ChocolateyPS1 { throw "big bad error" }
Mock Test-Path { $true } -ParameterFilter {$path -eq 'c:\fake-lib\somepackage.1.0.0'}
Mock Move-BadInstall
Mock Write-Error

Chocolatey-NuGet 'somepackage'

It "should set chocolateyErrored to true" {
$chocolateyErrored | should be $true
}
}

Context "with packageName 'all'" {
Mock Update-SessionEnvironment
Mock Chocolatey-InstallAll {} -Verifiable -ParameterFilter {$source -eq 'source'}
Expand Down

0 comments on commit b77f9b1

Please sign in to comment.