1- $ProjectRoot = (Resolve-Path " $PSScriptRoot \.." ).path
2- $ModuleName = Split-Path $ProjectRoot - Leaf
3- $ModuleRoot = " $ProjectRoot \$ModuleName \$ModuleName .psm1"
4- $ManifestRoot = " $ProjectRoot \$ModuleName \$ModuleName .psd1"
5- $Functions = " $ProjectRoot \$ModuleName \Functions"
6- $Helpers = " $ProjectRoot \$ModuleName \Helpers"
7- Write-Output $Functions
8- Get-ChildItem - Path $Functions - Include * .ps1 - Recurse
9- Write-Output $Helpers
10- Get-ChildItem - Path $Helpers - Include * .ps1 - Recurse
11-
12-
131BeforeAll {
142 Try {
153 Import-module PSScriptAnalyzer - ErrorAction STOP
@@ -20,68 +8,115 @@ BeforeAll {
208 IF (! (Get-Module PSScriptAnalyzer)){
219 Install-Module - Name PSScriptAnalyzer - Force
2210 }
23-
24- $ProjectRoot = (Resolve-Path " $PSScriptRoot \.." ).path
25- $ModuleName = Split-Path $ProjectRoot - Leaf
26- $ModuleRoot = " $ProjectRoot \$ModuleName \$ModuleName .psm1"
27- $ManifestRoot = " $ProjectRoot \$ModuleName \$ModuleName .psd1"
28- $Functions = " $ProjectRoot \$ModuleName \Functions"
29- $Helpers = " $ProjectRoot \$ModuleName \Helpers"
30- Write-Output $Functions
31- Write-Output $Helpers
11+
12+ # $Scripts = Get-ChildItem -Include *.ps1 -Exclude *WiP.ps1 -Recurse
13+ $ProjectRoot = (Resolve-Path " $PSScriptRoot \.." ).path
14+ $ModuleName = Split-Path $ProjectRoot - Leaf
15+ $ModuleRoot = Join-Path - Path $ProjectRoot - ChildPath $ModuleName - AdditionalChildPath " $ModuleName .psm1"
16+ $ManifestRoot = Join-Path - Path $ProjectRoot - ChildPath $ModuleName - AdditionalChildPath " $ModuleName .psd1"
17+ $Functions = Join-Path - Path $ProjectRoot - ChildPath $ModuleName - AdditionalChildPath Functions
18+ $Helpers = Join-Path - Path $ProjectRoot - ChildPath $ModuleName - AdditionalChildPath Helpers
3219}
3320
34- Describe " General project validation: $ModuleName " {
35- $Scripts = Get-ChildItem - Path $Functions , $Helpers - Include * .ps1 - Recurse
21+ Describe " General project validation: $ModuleName " - Tag ' Module_Validation' {
3622
37- # TestCases are splatted to the script
38- $TestCase = $Scripts | Foreach-Object {@ {file = $_ }}
39- It " Script <file> should be valid powershell" - TestCases $TestCase {
40- param ($File )
23+ Context ' Project should be viable' {
4124
42- $File.Fullname | Should - Exist
25+ It " Test-Path $ProjectRoot should be True" {
26+ Test-Path $ProjectRoot | Should - Be $True
27+ }
4328
44- $Contents = Get-Content - Path $File.Fullname - ErrorAction Stop
45- $Errors = $null
46- $null = [System.Management.Automation.PSParser ]::Tokenize($Contents , [ref ]$Errors )
47- $Errors.Count | Should - Be 0
48- }
49- It " Script <file> should exist" - TestCases $TestCase {
50- param ($File )
51- Test-Path $File.Fullname | Should - Be $True
52- }
29+ It " Test-Path $Moduleroot should be True" {
30+ Test-Path $Moduleroot | Should - Be $True
31+ }
5332
54- It " Script <file> should have help block" - TestCases $TestCase {
55- param ($File )
56- $File.Fullname | Should - FileContentMatch ' <#'
57- $File.Fullname | Should - FileContentMatch ' #>'
58- }
33+ It " Test-Path $ManifestRoot should be True" {
34+ Test-Path $ManifestRoot | Should - Be $True
35+ }
5936
60- It " Script <file> should have Synopsis" - TestCases $TestCase {
61- param ($File )
62- $File.Fullname | Should - FileContentMatch ' .SYNOPSIS'
63- }
37+ it ' Passes all default PSScriptAnalyzer rules' {
38+ Invoke-ScriptAnalyzer - Path $ManifestRoot - ExcludeRule PSUseToExportFieldsInManifest | should - BeNullOrEmpty
39+ }
6440
65- It " Script <file> should have help DESCRIPTION" - TestCases $TestCase {
66- param ($File )
67- $File.Fullname | Should - FileContentMatch ' DESCRIPTION'
68- }
6941
70- It " Script <file> should have help EXAMPLE" - TestCases $TestCase {
71- param ($File )
72- $File.Fullname | Should - FileContentMatch ' EXAMPLE'
7342 }
43+ }
44+
45+ Describe " Validating commands are viable" - Tag ' Command_Validation' {
46+
47+ Context ' Public functions should be viable' {
48+
49+ BeforeAll {
50+ $AllFunctions = Get-ChildItem - Path $Functions - Include * .ps1 - Recurse
51+ $TestCase = $AllFunctions | Foreach-Object {@ {file = $_ }}
52+ }
53+
54+
55+ It " Script <file> should be valid powershell" - TestCases $TestCase {
56+ param ($File )
57+
58+ $File.Fullname | Should - Exist
59+
60+ $Contents = Get-Content - Path $File.Fullname - ErrorAction Stop
61+ $Errors = $null
62+ $null = [System.Management.Automation.PSParser ]::Tokenize($Contents , [ref ]$Errors )
63+ $Errors.Count | Should - Be 0
64+
65+ }
66+
67+ It " Script <file> should exist" - TestCases $TestCase {
68+ param ($File )
69+ Test-Path $File.Fullname | Should - Be $True
70+ }
71+
72+ It " Script <file> should have help block" - TestCases $TestCase {
73+ param ($File )
74+ $File.Fullname | Should - FileContentMatch ' <#'
75+ $File.Fullname | Should - FileContentMatch ' #>'
76+ }
77+
78+ It " Script <file> should have Synopsis" - TestCases $TestCase {
79+ param ($File )
80+ $File.Fullname | Should - FileContentMatch ' .SYNOPSIS'
81+ }
82+
83+ It " Script <file> should have help DESCRIPTION" - TestCases $TestCase {
84+ param ($File )
85+ $File.Fullname | Should - FileContentMatch ' DESCRIPTION'
86+ }
87+
88+ It " Script <file> should have help EXAMPLE" - TestCases $TestCase {
89+ param ($File )
90+ $File.Fullname | Should - FileContentMatch ' EXAMPLE'
91+ }
7492
75- It " Test-Path $Moduleroot should be True" {
76- Test-Path $Moduleroot | Should - Be $True
77- }
78-
79- It " Test-Path $ManifestRoot should be True" {
80- Test-Path $ManifestRoot | Should - Be $True
8193 }
8294
83- it ' Passes all default PSScriptAnalyzer rules' {
84- Invoke-ScriptAnalyzer - Path $ (gci $ModuleRoot ).Fullname - ExcludeRule PSUseBOMForUnicodeEncodedFile | should - BeNullOrEmpty
95+ Context ' Private helpers should be viable' {
96+
97+ BeforeAll {
98+ $AllHelpers = Get-ChildItem - Path $Functions - Include * .ps1 - Recurse
99+ $TestCase = $AllHelpers | Foreach-Object {@ {file = $_ }}
100+ }
101+
102+ It " Script <file> should be valid powershell" - TestCases $TestCase {
103+ param ($File )
104+
105+ $File.Fullname | Should - Exist
106+
107+ $Contents = Get-Content - Path $File.Fullname - ErrorAction Stop
108+ $Errors = $null
109+ $null = [System.Management.Automation.PSParser ]::Tokenize($Contents , [ref ]$Errors )
110+ $Errors.Count | Should - Be 0
111+
112+ }
113+
114+ It " Script <file> should exist" - TestCases $TestCase {
115+ param ($File )
116+ Test-Path $File.Fullname | Should - Be $True
117+ }
118+
119+
85120 }
86121
87122}
0 commit comments