forked from JeffHarkavy/SafeguardCmdletTesting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdlet-tests-help.ps1
More file actions
33 lines (33 loc) · 1.17 KB
/
cmdlet-tests-help.ps1
File metadata and controls
33 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
try {
Get-Command "writeCallHeader" -ErrorAction Stop > $null
} catch {
write-host "Not meant to be run as a standalone script" -ForegroundColor Red
exit
}
$TestBlockName ="Check Help Function for all commands"
$blockInfo = testBlockHeader $TestBlockName
# Runs all commands with a -? parameter and looks for output.
# Will only complain if a given command doesn't return some help.
# Note that it's not really picky about *what's* returned, just as
# long as the call doesn't throw an exception for a missing command.
try {
$Output = ""
$Errors = ""
foreach ($commandName in (get-safeguardcommand).Name|sort) {
$cmd = $commandName + " -? | findstr /b /i /r /c:""^ * $commandName"""
$Output += "`n*** $cmd ***`n"
try {
$Output += (invoke-expression $cmd) | Out-String
} catch {
$Errors += "***no command help for $commandName`n"
}
}
if ($Errors -ne "") {
badResult "Help" "$Errors"
} else {
goodResult "Help" "All commands returned help output"
}
} catch {
badResult "Help general" "Unexpected error checking help output" $_
}
testBlockHeader $TestBlockName $blockInfo