1
1
[CmdletBinding ()]
2
2
param (
3
+
3
4
[ValidateSet (' PSV3 Debug' , ' PSV3 Release' , ' Debug' , ' Release' )]
4
5
[string ] $Configuration = ' Debug' ,
5
6
@@ -11,7 +12,15 @@ param(
11
12
12
13
[switch ] $CleanOutput = $false ,
13
14
14
- [switch ] $Install = $false
15
+ [switch ] $Install = $false ,
16
+
17
+ [switch ] $Uninstall = $false ,
18
+
19
+ [switch ] $Test = $false ,
20
+
21
+ [switch ] $Engine = $false ,
22
+
23
+ [switch ] $Rules = $false
15
24
)
16
25
17
26
# Some cmdlets like copy-item do not respond to the $verbosepreference variable
@@ -88,16 +97,96 @@ if ($BuildDocs)
88
97
New-ExternalHelp - Path $markdownDocsPath - OutputPath $outputDocsPath - Force - Verbose:$verbosity
89
98
}
90
99
100
+
101
+ $moduleRootPath = Join-Path (Split-Path $profile ) ' Modules'
102
+ $modulePSSAPath = Join-Path $moduleRootPath ' PSScriptAnalyzer'
91
103
if ($Install )
92
104
{
93
- $modulePath = Join-Path (Split-Path $profile ) ' Modules'
94
- if (-not (Test-Path $modulePath ))
105
+ if (-not (Test-Path $moduleRootPath ))
95
106
{
96
- New-Item - Path $modulePath - ItemType Directory - Force - Verbose:$verbosity
107
+ New-Item - Path $moduleRootPath - ItemType Directory - Force - Verbose:$verbosity
97
108
}
98
109
if (-not (Test-Path - Path $destinationPath ))
99
110
{
100
111
throw " Please build the module first."
101
112
}
102
- Copy-Item - Path $destinationPath - Destination $modulePath - Recurse - Verbose:$verbosity
113
+ Copy-Item - Path $destinationPath - Destination $modulePSSAPath - Recurse - Verbose:$verbosity
114
+ }
115
+
116
+ if ($Test )
117
+ {
118
+ Import-Module PSScriptAnalyzer - ErrorAction Stop
119
+ Import-Module - Name Pester - RequiredVersion 3.4 .0 - ErrorAction Stop
120
+
121
+
122
+ Function GetTestRunnerScriptContent ($testPath )
123
+ {
124
+ $x = @"
125
+ cd $testPath
126
+ Invoke-Pester
127
+ "@
128
+ return $x
129
+ }
130
+
131
+ Function CreateTestRunnerScript ($testPath )
132
+ {
133
+ $tmptmpFilePath = [System.IO.Path ]::GetTempFileName()
134
+ $tmpFilePath = $tmptmpFilePath + ' .ps1'
135
+ Move-Item $tmptmpFilePath $tmpFilePath - Verbose:$verbosity
136
+ $content = GetTestRunnerScriptContent $testPath
137
+ Set-Content - Path $tmpFilePath - Value $content - Verbose:$verbosity
138
+ return $tmpFilePath
139
+ }
140
+
141
+ Function GetTestPath ($TestType )
142
+ {
143
+ if ($TestType -eq " engine" )
144
+ {
145
+ $testPath = Join-Path $projectRoot " Tests/Engine"
146
+ }
147
+ else
148
+ {
149
+ $testPath = Join-Path $projectRoot " Tests/Rules"
150
+ }
151
+ return $testPath
152
+ }
153
+
154
+ Function RunTest ($TestType , $DifferentProcess )
155
+ {
156
+ $testPath = GetTestPath($TestType )
157
+ if ($DifferentProcess )
158
+ {
159
+ $testScriptFilePath = CreateTestRunnerScript $testPath
160
+ Start-Process powershell - ArgumentList " -NoExit" , " -File $testScriptFilePath " - Verb runas
161
+ }
162
+ else
163
+ {
164
+ try
165
+ {
166
+ Push-Location .
167
+ ([scriptblock ]::Create((GetTestRunnerScriptContent $testPath ))).Invoke()
168
+ }
169
+ finally
170
+ {
171
+ Pop-Location
172
+ }
173
+ }
174
+ # clean up the test file
175
+ }
176
+
177
+ if ($Engine )
178
+ {
179
+ RunTest(' engine' )
180
+ }
181
+ if ($Rules )
182
+ {
183
+ RunTest(' rules' )
184
+ }
103
185
}
186
+
187
+ if ($Uninstall )
188
+ {
189
+ Remove-Item - Path $modulePSSAPath - Force - Verbose:$verbosity - Recurse
190
+ }
191
+
192
+
0 commit comments