Add all other common module files
This commit is contained in:
32
Tests/Project/Help.Tests.ps1
Normal file
32
Tests/Project/Help.Tests.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
$Script:ModuleName = 'LDTestFramework'
|
||||
$Script:ModuleRoot = Split-Path -Path $PSScriptRoot -Parent
|
||||
|
||||
Describe "Public commands have comment-based or external help" -Tags 'Build' {
|
||||
$functions = Get-Command -Module $ModuleName
|
||||
$help = foreach ($function in $functions) {
|
||||
Get-Help -Name $function.Name
|
||||
}
|
||||
|
||||
foreach ($node in $help)
|
||||
{
|
||||
Context $node.Name {
|
||||
It "Should have a Description or Synopsis" -Pending {
|
||||
($node.Description + $node.Synopsis) | Should Not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "Should have an Example" -Pending {
|
||||
$node.Examples | Should Not BeNullOrEmpty
|
||||
}
|
||||
|
||||
foreach ($parameter in $node.Parameters.Parameter)
|
||||
{
|
||||
if ($parameter -notmatch 'WhatIf|Confirm')
|
||||
{
|
||||
It "Should have a Description for Parameter [$($parameter.Name)]" -Pending {
|
||||
$parameter.Description.Text | Should Not BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Tests/Project/Module.Tests.ps1
Normal file
44
Tests/Project/Module.Tests.ps1
Normal file
@@ -0,0 +1,44 @@
|
||||
$Script:ModuleName = 'LDTestFramework'
|
||||
$Script:ModuleRoot = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent
|
||||
$Script:SourceRoot = Join-Path -Path $ModuleRoot -ChildPath $ModuleName
|
||||
|
||||
Describe "All commands pass PSScriptAnalyzer rules" -Tag 'Build' {
|
||||
$rules = "$ModuleRoot\ScriptAnalyzerSettings.psd1"
|
||||
$scripts = Get-ChildItem -Path $SourceRoot -Include '*.ps1', '*.psm1', '*.psd1' -Recurse |
|
||||
Where-Object FullName -notmatch 'Classes'
|
||||
|
||||
foreach ($script in $scripts)
|
||||
{
|
||||
Context $script.FullName {
|
||||
$results = Invoke-ScriptAnalyzer -Path $script.FullName -Settings $rules
|
||||
if ($results)
|
||||
{
|
||||
foreach ($rule in $results)
|
||||
{
|
||||
It $rule.RuleName -Pending {
|
||||
$message = "{0} Line {1}: {2}" -f $rule.Severity, $rule.Line, $rule.Message
|
||||
$message | Should Be ""
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
It "Should not fail any rules" {
|
||||
$results | Should BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Public commands have Pester tests" -Tag 'Build' {
|
||||
$commands = Get-Command -Module $ModuleName
|
||||
|
||||
foreach ($command in $commands.Name)
|
||||
{
|
||||
$file = Get-ChildItem -Path "$ModuleRoot\Tests" -Include "$command.Tests.ps1" -Recurse
|
||||
It "Should have a Pester test for [$command]" -Skip:($null -eq $file) {
|
||||
$file.FullName | Should Not BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user