-
Notifications
You must be signed in to change notification settings - Fork 1
/
Eventbrite.Norm.Tests.ps1
98 lines (61 loc) · 3.1 KB
/
Eventbrite.Norm.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
90
91
92
93
94
95
96
$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
}
}
$function = $AllFunctions.Where{ $_.Name -eq $PrivateFunction.BaseName}
$PrivateFunctionTests = $PrivateFunctionstests.Where{$_.Name -match $PrivateFunction.BaseName }
foreach ($PrivateFunctionTest in $PrivateFunctionTests) {
. $($PrivateFunctionTest.FullName) $function
}
}
}
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
}
}
}