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