Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix get-help online test#3051

Merged
daxian-dbw merged 7 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
adityapatwardhan:HelpOnlineFixadityapatwardhan/PowerShell:HelpOnlineFixCopy head branch name to clipboard
Feb 2, 2017
Merged

Fix get-help online test#3051
daxian-dbw merged 7 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
adityapatwardhan:HelpOnlineFixadityapatwardhan/PowerShell:HelpOnlineFixCopy head branch name to clipboard

Conversation

@adityapatwardhan

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

@adityapatwardhan adityapatwardhan Jan 30, 2017

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Member

@Francisco-Gamino Do you have any additional comments?

@Francisco-Gamino

Francisco-Gamino commented Jan 31, 2017

Copy link
Copy Markdown
Contributor

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

@adityapatwardhan

Copy link
Copy Markdown
Member Author

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

@daxian-dbw

Copy link
Copy Markdown
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
Copy Markdown
Member Author

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

@TravisEz13

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.