Skip to content

Commit 40453a5

Browse files
committed
Add targeted test file option to build script
1 parent 0151b9d commit 40453a5

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎build.ps1‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ param(
3030
[Parameter(Mandatory=$true,ParameterSetName='Test')]
3131
[switch] $Test,
3232

33+
[Parameter(ParameterSetName='Test')]
34+
[string] $TestPath,
35+
3336
[Parameter(ParameterSetName='Test')]
3437
[switch] $InProcess,
3538
[string] $WithPowerShell,
@@ -88,6 +91,7 @@ END {
8891
"Test" {
8992
$testArgs = @{
9093
InProcess = $InProcess
94+
TestPath = $TestPath
9195
WithPowerShell = $WithPowerShell
9296
Verbose = $verboseWanted
9397
}

‎build.psm1‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ function Test-ScriptAnalyzer
296296
[CmdletBinding()]
297297
param (
298298
[switch] $InProcess,
299+
[string] $TestPath,
299300
[string] $WithPowerShell
300301
)
301302

@@ -318,7 +319,16 @@ function Test-ScriptAnalyzer
318319
#
319320
#
320321
$testModulePath = Join-Path "${projectRoot}" -ChildPath out
321-
$testScripts = "'${projectRoot}\Tests\Build','${projectRoot}\Tests\Engine','${projectRoot}\Tests\Rules','${projectRoot}\Tests\Documentation'"
322+
if ($TestPath) {
323+
$resolvedTestPath = (Resolve-Path -LiteralPath $TestPath -ErrorAction Stop).Path
324+
if ((Get-Item -LiteralPath $resolvedTestPath).PSIsContainer) {
325+
throw "TestPath must point to a test file."
326+
}
327+
$testScripts = "'{0}'" -f $resolvedTestPath.Replace("'", "''")
328+
}
329+
else {
330+
$testScripts = "'${projectRoot}\Tests\Build','${projectRoot}\Tests\Engine','${projectRoot}\Tests\Rules','${projectRoot}\Tests\Documentation'"
331+
}
322332
try {
323333
$savedModulePath = $env:PSModulePath
324334
$env:PSModulePath = "${testModulePath}{0}${env:PSModulePath}" -f [System.IO.Path]::PathSeparator

0 commit comments

Comments
 (0)