-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix get-help online test #3051
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
Fix get-help online test #3051
Conversation
Fix the get-help -online test so that when a default browser is not set, the test does not fail.
| { | ||
| { throw $errorThrown } | Should Not Throw | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two thoughts:
- This solution seems overly complex and difficult to parse. Can you simplify it and still retain the same behavior? Maybe use an else within the catch block?
- If you keep it this way then comments are needed to describe what you are doing and why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added code to check if default browser is set.
|
|
||
| It "Get-Help get-process -online" -skip:$skipTest { | ||
|
|
||
| { Get-Help get-process -online } | Should Not Throw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to check if the default browser is set? If it is, run the test; otherwise, skip it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I have added the code similar to the product.
|
|
||
| $skipTest = [System.Management.Automation.Platform]::IsIoT -or | ||
| [System.Management.Automation.Platform]::IsNanoServer | ||
| [System.Management.Automation.Platform]::IsNanoServer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like unneeded formating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
Are you OK with the changes? |
| if($IsWindows) | ||
| { | ||
| $regKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice" | ||
| $progId = [Microsoft.Win32.Registry]::GetValue($regKey, "ProgId", $null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a try-catch here? This can potentially throw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mirichmo Fixed.
| if($browserKey) | ||
| { | ||
| $browserExe = $browserKey.GetValue($null) | ||
| if($browserExe -notmatch '.exe') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @adityapatwardhan. To get the default browser executable path you need to parse the output of $browserKey.GetValue($null). This would look something like this: $browserExe = (($browserKey.GetValue($null) -replace '"' ,"") -split " ")[0].
Also, you could potentially set $skipTest to $false by default which will simplify your logic to something like this:
$skipTest = $true
try
{
$regKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"
$progId = [Microsoft.Win32.Registry]::GetValue($regKey, "ProgId", $null)
if($progId)
{
$browserKey = [Microsoft.Win32.Registry]::ClassesRoot.OpenSubKey("$progId\shell\open\command", $false)
if($browserKey)
{
$browserExe = (($browserKey.GetValue($null) -replace '"' ,"") -split " ")[0]
if($browserExe.EndsWith('.exe'))
{
$skipTest = $false
}
}
}
}
catch
{
# ignore the failure
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. @Francisco-Gamino please have a look.
|
@Francisco-Gamino Do you have any additional comments? |
|
@adityapatwardhan : You should probably squash your commits into one. Other than that, LGTM. |
|
@PowerShell/powershell-maintainers This is ready for merge. |
|
Chatted with @adityapatwardhan offline, and it looks like a bug in the default browser detection code because:
We need to fix this in product code. @Francisco-Gamino: thought? |
|
Perhaps you should put a comment in the code to the effect that this is a workaround for #3079 . This would help if someone is trying to understand the code. |
|
@TravisEz13 Checks have passed. Ready for merge. |
Fix the get-help -online test so that when a default browser is not set,
the test does not fail.