File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -1136,10 +1136,32 @@ module Interactions =
11361136 )
11371137 |> Promise.ofThenable
11381138
1139+ let private filterEscapeCharacter = '\\'
1140+ let private filterSpecialCharacters = [| '\\' ; '(' ; ')' ; '&' ; '|' ; '=' ; '!' ; '~' |]
1141+ let private filterSpecialCharactersSet = Set.ofArray filterSpecialCharacters
11391142
11401143 let private buildFilterExpression ( tests : TestItem array ) =
1144+ // Escape any special characters in test names, as per https://github.com/microsoft/vstest/blob/main/docs/filter.md
1145+ let escapeFilterExpression ( str : string ) =
1146+
1147+ if str.IndexOfAny( filterSpecialCharacters) < 0 then
1148+ str
1149+ else
1150+ let builder = StringBuilder()
1151+
1152+ for i = 0 to str.Length - 1 do
1153+ let currentChar = str[ i]
1154+
1155+ if filterSpecialCharactersSet.Contains currentChar then
1156+ builder.Append( filterEscapeCharacter) |> ignore
1157+
1158+ builder.Append( currentChar) |> ignore
1159+
1160+ builder.ToString()
1161+
11411162 let testToFilterExpression ( test : TestItem ) =
1142- let fullName = TestItem.getFullName test.id
1163+ let fullTestName = TestItem.getFullName test.id
1164+ let fullName = escapeFilterExpression fullTestName
11431165
11441166 if fullName.Contains( " " ) && test.TestFramework = TestFrameworkId.NUnit then
11451167 // workaround for https://github.com/nunit/nunit3-vs-adapter/issues/876
You can’t perform that action at this time.
0 commit comments