Skip to content

Conversation

@adityapatwardhan
Copy link
Member

Fix the get-help -online test so that when a default browser is not set,
the test does not fail.

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
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Two thoughts:

  1. 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?
  2. If you keep it this way then comments are needed to describe what you are doing and why

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like unneeded formating.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@adityapatwardhan
Copy link
Member Author

@Francisco-Gamino @mirichmo

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)
Copy link
Member

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

Copy link
Member Author

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')
Copy link
Contributor

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
}

Copy link
Member Author

@adityapatwardhan adityapatwardhan Jan 30, 2017

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.

@mirichmo
Copy link
Member

@Francisco-Gamino Do you have any additional comments?

@Francisco-Gamino
Copy link
Contributor

Francisco-Gamino commented Jan 31, 2017

@adityapatwardhan : You should probably squash your commits into one. Other than that, LGTM.

@adityapatwardhan
Copy link
Member Author

@PowerShell/powershell-maintainers This is ready for merge.

@daxian-dbw
Copy link
Member

Chatted with @adityapatwardhan offline, and it looks like a bug in the default browser detection code because:

  • cmd /c start /B www.bing.com would open www.bing.com in IE
  • get-help -online gps works in Windows PowerShell on the same machine, but fails on PSv6

We need to fix this in product code. @Francisco-Gamino: thought?

@adityapatwardhan
Copy link
Member Author

This is workaround due to #3079. This should be removed when #3079 is fixed.

@TravisEz13
Copy link
Member

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.

@adityapatwardhan
Copy link
Member Author

@TravisEz13 Checks have passed. Ready for merge.

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.

8 participants