-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#7 - Add a check for external help into Test-FunctionHelpCoverage
- Loading branch information
1 parent
fb60960
commit 799d703
Showing
8 changed files
with
745 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Function Get-ExternalHelpCommand { | ||
<# | ||
.SYNOPSIS | ||
Gets the name of the commands listed in external help files. | ||
.DESCRIPTION | ||
Gets the name of the commands listed in external (MAML-formatted) help files. | ||
.PARAMETER Path | ||
Root directory where the function looks for external help files. | ||
The function looks for files with a name ending with "-help.xml" in a "en-US" subdirectory. | ||
.EXAMPLE | ||
PS C:\> Get-ExternalHelpCommand -Path 'C:\GitRepos\MyModule' | ||
Gets the name of all the commands listed in external help files found in the folder : C:\GitRepos\MyModule\. | ||
.NOTES | ||
https://info.sapien.com/index.php/scripting/scripting-help/writing-xml-help-for-advanced-functions | ||
#> | ||
[CmdletBinding()] | ||
Param ( | ||
[Parameter(Position=0, Mandatory)] | ||
[ValidateScript({ Test-Path $_ -PathType Container })] | ||
[string[]]$Path | ||
) | ||
|
||
$LocaleFolder = Get-ChildItem -Path $Path -Directory -Filter 'en-US' -Recurse | ||
If ( $LocaleFolder ) { | ||
$MamlHelpFile = Get-ChildItem -Path $LocaleFolder.FullName -File -Filter '*-help.xml' | ||
If ( $MamlHelpFile ) { | ||
Try { | ||
[xml]$Maml = Get-Content -Path $MamlHelpFile.FullName | ||
} | ||
Catch { | ||
Write-Warning "The content of the file $($MamlHelpFile.FullName) was not valid XML" | ||
return | ||
} | ||
return $Maml.helpItems.command.details.name | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<helpItems schema="maml"> | ||
|
||
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Function Public () { | ||
<# | ||
.SYNOPSIS | ||
This cmdlet configures nothing and does it remarkably well. | ||
.DESCRIPTION | ||
This cmdlet configures nothing and does it remarkably well. | ||
It takes objects as input and it sets nothing to 42. | ||
#> | ||
|
||
Function Nested ($InputObject) { | ||
Get-Item $InputObject | ||
} | ||
} | ||
|
||
Function Get-PlasterTemplate ($InputObject) { | ||
Get-Item $InputObject | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
$ModuleName = 'PSCodeHealth' | ||
Import-Module "$PSScriptRoot\..\..\..\$ModuleName\$($ModuleName).psd1" -Force | ||
|
||
Describe 'Get-ExternalHelpCommand' { | ||
InModuleScope $ModuleName { | ||
Context 'The specified folder does not contain any external help file' { | ||
|
||
It 'Should not throw' { | ||
{Get-ExternalHelpCommand -Path $TestDrive} | Should -Not -Throw | ||
} | ||
} | ||
Context 'The specified folder contains an external help file with invalid XML' { | ||
|
||
$InvalidXmlFile = "$PSScriptRoot\..\..\TestData\InvalidHelp" | ||
|
||
It 'Should not throw' { | ||
{Get-ExternalHelpCommand -Path $InvalidXmlFile -WarningAction SilentlyContinue} | | ||
Should -Not -Throw | ||
} | ||
} | ||
Context 'The specified folder contains a valid external help file' { | ||
|
||
$HelpFile = "$PSScriptRoot\..\..\TestData\TestHelp" | ||
$Results = Get-ExternalHelpCommand -Path $HelpFile | ||
$ExpectedCommandName = @('Get-PlasterTemplate', 'Invoke-Plaster', 'New-PlasterManifest', 'Test-PlasterManifest') | ||
|
||
It 'Should return an object of the type [string]' { | ||
Foreach ( $Result in $Results ) { | ||
$Result | Should -BeOfType [string] | ||
} | ||
} | ||
It 'Should return 4 objects' { | ||
$Results.Count | Should -Be 4 | ||
} | ||
It 'Should return the expected command names from the external help file' { | ||
Foreach ( $Result in $Results ) { | ||
$Result | Should -BeIn $ExpectedCommandName | ||
} | ||
} | ||
} | ||
} | ||
} |