Skip to content

Commit 574dcb6

Browse files
committed
(maint) Add Xunit Trait Filter
Previously when running tests all test would need to be run, however when this can take a while. This commit adds an option to add a trait filter to XUnit as per the Xunit documentation [1]. Later commits may add the actual trait attributes to the tests. [1] https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests
1 parent e3179e4 commit 574dcb6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

PowerShellEditorServices.build.ps1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ param(
1111

1212
[string]$ModulesJsonPath = "$PSScriptRoot/modules.json",
1313

14-
[string]$DefaultModuleRepository = "PSGallery"
14+
[string]$DefaultModuleRepository = "PSGallery",
15+
16+
[string]$TestFilter = ''
1517
)
1618

1719
#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"}
@@ -223,24 +225,31 @@ function UploadTestLogs {
223225
}
224226
}
225227

228+
function XunitTraitFilter {
229+
$TraitFilter = ''
230+
# Reference https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests
231+
if (![string]::IsNullOrEmpty($TestFilter)) { $TraitFilter = "-trait $TestFilter" }
232+
Write-Output $TraitFilter
233+
}
234+
226235
task Test TestServer,TestProtocol
227236

228237
task TestServer -If { !$script:IsUnix } {
229238
Set-Location .\test\PowerShellEditorServices.Test\
230239
exec { & $script:dotnetExe build -c $Configuration -f net452 }
231-
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild }
240+
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild (XunitTraitFilter) }
232241
}
233242

234243
task TestProtocol -If { !$script:IsUnix } {
235244
Set-Location .\test\PowerShellEditorServices.Test.Protocol\
236245
exec { & $script:dotnetExe build -c $Configuration -f net452 }
237-
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild }
246+
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild (XunitTraitFilter) }
238247
}
239248

240249
task TestHost -If { !$script:IsUnix } {
241250
Set-Location .\test\PowerShellEditorServices.Test.Host\
242251
exec { & $script:dotnetExe build -c $Configuration -f net452 }
243-
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild }
252+
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild (XunitTraitFilter) }
244253
}
245254

246255
task CITest ?Test, {

0 commit comments

Comments
 (0)