Skip to content

Commit 69f9194

Browse files
author
Kapil Borle
committed
Improve testing switch usage in build script
When .\build.ps1 -Test is given, it runs engine and rules tests. Now if -Engine switch is added to previous command, only engine tests are run and so for rules. When -RunInDifferentProcess sitch is given, it opens another PS console and runs the tests there.
1 parent 0711fb2 commit 69f9194

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

build.ps1

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
[CmdletBinding()]
22
param(
3-
3+
4+
[Parameter(ParameterSetName='Build')]
45
[ValidateSet('PSV3 Debug','PSV3 Release','Debug','Release')]
56
[string] $Configuration = 'Debug',
67

8+
[Parameter(ParameterSetName='Build')]
79
[switch] $BuildSolution = $false,
810

11+
[Parameter(ParameterSetName='Build')]
912
[switch] $CleanSolution = $false,
1013

14+
[Parameter(ParameterSetName='Build')]
1115
[switch] $BuildDocs = $false,
1216

17+
[Parameter(ParameterSetName='Build')]
1318
[switch] $CleanOutput = $false,
1419

20+
[Parameter(ParameterSetName='Build')]
1521
[switch] $Install = $false,
1622

23+
[Parameter(ParameterSetName='Build')]
1724
[switch] $Uninstall = $false,
1825

26+
[Parameter(ParameterSetName='Test')]
1927
[switch] $Test = $false,
2028

29+
[Parameter(ParameterSetName='Test')]
2130
[switch] $Engine = $false,
2231

23-
[switch] $Rules = $false
32+
[Parameter(ParameterSetName='Test')]
33+
[switch] $Rules = $false,
34+
35+
[Parameter(ParameterSetName='Test')]
36+
[switch] $RunInDifferentProcess = $false
2437
)
2538

2639
# Some cmdlets like copy-item do not respond to the $verbosepreference variable
@@ -118,7 +131,7 @@ if ($Test)
118131
Import-Module PSScriptAnalyzer -ErrorAction Stop
119132
Import-Module -Name Pester -RequiredVersion 3.4.0 -ErrorAction Stop
120133

121-
134+
122135
Function GetTestRunnerScriptContent($testPath)
123136
{
124137
$x = @"
@@ -127,7 +140,7 @@ if ($Test)
127140
"@
128141
return $x
129142
}
130-
143+
131144
Function CreateTestRunnerScript($testPath)
132145
{
133146
$tmptmpFilePath = [System.IO.Path]::GetTempFileName()
@@ -150,17 +163,18 @@ if ($Test)
150163
}
151164
return $testPath
152165
}
153-
154-
Function RunTest($TestType, $DifferentProcess)
166+
167+
Function RunTest($TestType, [Boolean] $DifferentProcess)
155168
{
156-
$testPath = GetTestPath($TestType)
169+
$testPath = GetTestPath($TestType)
157170
if ($DifferentProcess)
158171
{
159172
$testScriptFilePath = CreateTestRunnerScript $testPath
160173
Start-Process powershell -ArgumentList "-NoExit","-File $testScriptFilePath" -Verb runas
174+
# clean up the test file
161175
}
162176
else
163-
{
177+
{
164178
try
165179
{
166180
Push-Location .
@@ -169,24 +183,22 @@ if ($Test)
169183
finally
170184
{
171185
Pop-Location
186+
172187
}
173188
}
174-
# clean up the test file
175189
}
176190

177-
if ($Engine)
191+
if ($Engine -or (-not ($Engine -or $Rules)))
178192
{
179-
RunTest('engine')
193+
RunTest 'engine' $RunInDifferentProcess
180194
}
181-
if ($Rules)
195+
if ($Rules -or (-not ($Engine -or $Rules)))
182196
{
183-
RunTest('rules')
197+
RunTest 'rules' $RunInDifferentProcess
184198
}
185199
}
186200

187201
if ($Uninstall)
188202
{
189203
Remove-Item -Path $modulePSSAPath -Force -Verbose:$verbosity -Recurse
190-
}
191-
192-
204+
}

0 commit comments

Comments
 (0)