Skip to content

Commit 32c4af4

Browse files
authored
Merge pull request #19 from kookie/pester-test
Pester Tests for comment based help
2 parents 321d901 + eba5a76 commit 32c4af4

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

AD-SITE-Get-ADSiteInventory/Get-ADSiteInventory.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@
105105
}#get-ADSiteServicesInfo
106106

107107
#get-ADSiteServicesInfo #| export-csv .\test.csv
108-
Get-ADSiteInventory
108+
#Get-ADSiteInventory

Help.Tests.ps1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
$scripts = Get-ChildItem -Path $PSScriptRoot -Recurse -Filter *.ps1 |
2+
Where-Object FullName -NotMatch '.Tests.'
3+
4+
[regex]$regex = "(^[A-Z\-]+-)"
5+
6+
Describe -Tag 'Help' 'Help' {
7+
8+
foreach ($script in $scripts) {
9+
10+
Context "[$($script.BaseName)] Validate Comment Based Help" {
11+
12+
# Correct name where file name does not match function name
13+
if ($script.Name -Match $regex) {
14+
$name = $script.BaseName.Replace($Matches[0], '')
15+
} elseif ($script.Name -match 'O365-') {
16+
$name = $script.BaseName.Replace($Matches[0], '')
17+
} elseif ($script.Name -match 'Function_Template.ps1') {
18+
$name = 'Get-Something'
19+
} else {
20+
$name = $script.BaseName
21+
}
22+
23+
# Only process functions and not scripts
24+
if ((Get-Content -Path $script.FullName -TotalCount 1) -match 'function') {
25+
26+
# Dot Source script
27+
. $($script.FullName)
28+
29+
$functionHelp = Get-Help $name -Full
30+
31+
It 'Contains Description' {
32+
$functionHelp.Description | Should Not BeNullOrEmpty
33+
}
34+
35+
It 'Contains Synopsis' {
36+
$functionHelp.Synopsis | Should Not BeNullOrEmpty
37+
}
38+
39+
It 'Contains Examples' {
40+
$functionHelp.Examples | Should Not BeNullOrEmpty
41+
}
42+
43+
It 'Contains Parameters' {
44+
$functionHelp.Parameters | Should Not BeNullOrEmpty
45+
}
46+
} else {
47+
It "[$($script.BaseName)] is not a function and skipped" {
48+
} -Skip
49+
}
50+
}
51+
}
52+
}
53+

0 commit comments

Comments
 (0)