Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Mandatory from Test-PoshGitImportedInScript -Path #384

Merged
merged 2 commits into from
Jan 30, 2017

Conversation

dahlbyk
Copy link
Owner

@dahlbyk dahlbyk commented Jan 30, 2017

Fix #381

full error trace is available here: https://gist.github.com/choco-bot/8fd09f341ed80aa5cf6ae01f39b49763

2017-01-30 18:46:34,436 [ERROR] - ERROR: Cannot bind argument to parameter 'Path' because it is an empty string.
 at Add-PoshGitToProfile, C:\tools\poshgit\dahlbyk-posh-git-9f6b256\src\Utils.ps1: line 98
at <ScriptBlock>, C:\tools\poshgit\dahlbyk-posh-git-9f6b256\install.ps1: line 6
at <ScriptBlock>, C:\ProgramData\chocolatey\lib\poshgit\tools\chocolateyInstall.ps1: line 42
at <ScriptBlock>, C:\ProgramData\chocolatey\helpers\chocolateyScriptRunner.ps1: line 48
at <ScriptBlock>, <No file>: line 1

As of #376, install.ps1 passes $WhatIf on to Add-PoshGitToProfile, which matches a hack added to let tests override $profilePath. Ultimately this causes $profilePath to be empty when passed as a Mandatory parameter to Test-PoshGitImportedInScript. Two-part fix:

  1. Test-PoshGitImportedInScript can correctly handle a $null/empty $Path, so it's safer to remove Mandatory.
  2. We can skip the test argument hack by checking the argument type.

@@ -84,7 +84,8 @@ function Add-PoshGitToProfile([switch]$AllHosts, [switch]$Force, [switch]$WhatIf
$profilePath = if ($AllHosts) { $PROFILE.CurrentUserAllHosts } else { $PROFILE.CurrentUserCurrentHost }

# Under test, we override some variables using $args as a backdoor.
if ($args.Count -gt 0) {
# TODO: Can we just turn these into optional parameters with well-defined behavior?
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rkeithhill this question is for you. Can we just make $ProfilePath and real (optional) argument that is documented to override $AllHosts?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could use environment variables to override.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not make the public parameters any more complicated for the sake of tests. Yes, we could use env vars but those are global to the process and could impact tests if they ever ran in parallel (which they currently don't).

@dahlbyk dahlbyk merged commit 5fe6233 into master Jan 30, 2017
@dahlbyk dahlbyk deleted the choco-install-error branch January 30, 2017 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't install latest release
2 participants