|
| 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