-
Notifications
You must be signed in to change notification settings - Fork 6
/
PesterHelpers.Min.Tests.ps1
91 lines (56 loc) · 2.77 KB
/
PesterHelpers.Min.Tests.ps1
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path
$PrivateFunctions = Get-ChildItem "$here\Private\" -Filter '*.ps1' -Recurse | Where-Object {$_.name -NotMatch "Tests.ps1"}
$PublicFunctions = Get-ChildItem "$here\Public\" -Filter '*.ps1' -Recurse | Where-Object {$_.name -NotMatch "Tests.ps1"}
$PrivateFunctionsTests = Get-ChildItem "$here\Private\" -Filter '*Tests.ps1' -Recurse
$PublicFunctionsTests = Get-ChildItem "$here\Public\" -Filter '*Tests.ps1' -Recurse
$Rules = Get-ScriptAnalyzerRule
$manifest = Get-Item "$Here\*.psd1"
$module = $manifest.BaseName
Import-Module "$Here\*.psd1"
$ModuleData = Get-Module $Module
$AllFunctions = & $moduleData {Param($modulename) Get-command -CommandType Function -Module $modulename} $module
$PublicFunctionPath = "$here\Public\"
$PrivateFunctionPath = "$here\Private\"
if ($PrivateFunctions.count -gt 0) {
foreach($PrivateFunction in $PrivateFunctions)
{
Describe "Testing Private Function - $($PrivateFunction.BaseName) for Standard Processing" {
It "Is valid Powershell (Has no script errors)" {
$contents = Get-Content -Path $PrivateFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
}
}
}
}
if ($PublicFunctions.count -gt 0) {
foreach($PublicFunction in $PublicFunctions)
{
Describe "Testing Public Function - $($PublicFunction.BaseName) for Standard Processing" {
It "Is valid Powershell (Has no script errors)" {
$contents = Get-Content -Path $PublicFunction.FullName -ErrorAction Stop
$errors = $null
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)
$errors.Count | Should Be 0
}
}
$function = $AllFunctions.Where{ $_.Name -eq $PublicFunction.BaseName}
$publicfunctionTests = $Publicfunctionstests.Where{$_.Name -match $PublicFunction.BaseName }
foreach ($publicfunctionTest in $publicfunctionTests) {
. $($PublicFunctionTest.FullName) $function
}
}
}
Describe 'ScriptAnalyzer Rule Testing' {
Context 'Public Functions' {
It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PublicFunctionPath -Recurse ).Count | Should Be 0
}
}
Context 'Private Functions' {
It 'Passes the Script Analyzer ' {
(Invoke-ScriptAnalyzer -Path $PrivateFunctionPath ).Count | Should Be 0
}
}
}