Skip to content

Commit 2a95411

Browse files
steveisokCopilotmax-charlamb
authored
Add test filtering by class or method name (dotnet#5687)
test.sh|ps1 -methodfilter "Namespace.ClassName.MethodName" test.sh|ps1 -classfilter "Namespace.ClassName" --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Max Charlamb <44248479+max-charlamb@users.noreply.github.com>
1 parent 3272544 commit 2a95411

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

eng/build.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Param(
1212
[switch] $skipnative,
1313
[switch] $bundletools,
1414
[switch] $useCdac,
15+
[string] $methodfilter = '',
16+
[string] $classfilter = '',
1517
[ValidatePattern("(default|\d+\.\d+.\d+(-[a-z0-9\.]+)?)")][string] $dotnetruntimeversion = 'default',
1618
[ValidatePattern("(default|\d+\.\d+.\d+(-[a-z0-9\.]+)?)")][string] $dotnetruntimedownloadversion= 'default',
1719
[string] $runtimesourcefeed = '',
@@ -98,6 +100,17 @@ if ($test) {
98100
if ($useCdac) {
99101
$env:SOS_TEST_CDAC="true"
100102
}
103+
104+
# Build the test filter argument if provided
105+
# Use backslash-escaped quotes so they survive the additional quoting in tools.ps1
106+
$testFilterArg = ''
107+
if ($methodfilter -ne '') {
108+
$testFilterArg = "/p:TestRunnerAdditionalArguments=\`"-method $methodfilter\`""
109+
}
110+
elseif ($classfilter -ne '') {
111+
$testFilterArg = "/p:TestRunnerAdditionalArguments=\`"-class $classfilter\`""
112+
}
113+
101114
& "$engroot\common\build.ps1" `
102115
-test `
103116
-configuration $configuration `
@@ -111,7 +124,8 @@ if ($test) {
111124
/p:DotnetRuntimeDownloadVersion="$dotnetruntimedownloadversion" `
112125
/p:RuntimeSourceFeed="$runtimesourcefeed" `
113126
/p:RuntimeSourceFeedKey="$runtimesourcefeedkey" `
114-
/p:LiveRuntimeDir="$liveRuntimeDir"
127+
/p:LiveRuntimeDir="$liveRuntimeDir" `
128+
$testFilterArg
115129

116130
if ($lastExitCode -ne 0) {
117131
exit $lastExitCode

eng/build.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ __SkipGenerateVersion=0
2929
__InstallRuntimes=0
3030
__PrivateBuild=0
3131
__Test=0
32+
__TestFilter=
3233
__UnprocessedBuildArgs=
3334
__UseCdac=0
3435
__LiveRuntimeDir=
3536

3637
usage_list+=("-skipmanaged: do not build managed components.")
3738
usage_list+=("-skipnative: do not build native components.")
3839
usage_list+=("-test: run xunit tests")
40+
usage_list+=("-methodfilter: pass method filter to xunit runner (Namespace.ClassName.MethodName)")
41+
usage_list+=("-classfilter: pass class filter to xunit runner (Namespace.ClassName)")
3942

4043
handle_arguments() {
4144
lowerI="$(echo "${1/--/-}" | tr "[:upper:]" "[:lower:]")"
@@ -105,6 +108,16 @@ handle_arguments() {
105108
__Test=1
106109
;;
107110

111+
methodfilter|-methodfilter)
112+
__TestFilter="-method $2"
113+
__ShiftArgs=1
114+
;;
115+
116+
classfilter|-classfilter)
117+
__TestFilter="-class $2"
118+
__ShiftArgs=1
119+
;;
120+
108121
usecdac|-usecdac)
109122
__UseCdac=1
110123
;;
@@ -302,6 +315,12 @@ if [[ "$__Test" == 1 ]]; then
302315
export SOS_TEST_CDAC="true"
303316
fi
304317

318+
# Build the test filter argument if provided
319+
__TestFilterArg=
320+
if [[ -n "$__TestFilter" ]]; then
321+
__TestFilterArg="/p:TestRunnerAdditionalArguments=\"$__TestFilter\""
322+
fi
323+
305324
# __CommonMSBuildArgs contains TargetOS property
306325
"$__RepoRootDir/eng/common/build.sh" \
307326
--test \
@@ -314,6 +333,7 @@ if [[ "$__Test" == 1 ]]; then
314333
/p:RuntimeSourceFeed="$__RuntimeSourceFeed" \
315334
/p:RuntimeSourceFeedKey="$__RuntimeSourceFeedKey" \
316335
/p:LiveRuntimeDir="$__LiveRuntimeDir" \
336+
"$__TestFilterArg" \
317337
$__CommonMSBuildArgs
318338

319339
if [ $? != 0 ]; then

0 commit comments

Comments
 (0)