11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4- #nullable disable
5-
6- using System . CommandLine ;
74using Microsoft . DotNet . Cli . Commands . Test ;
5+ using Microsoft . DotNet . Cli . Extensions ;
6+ using TestCommand = Microsoft . DotNet . Cli . Commands . Test . TestCommand ;
87
98namespace Microsoft . DotNet . Cli . Test . Tests
109{
@@ -14,7 +13,7 @@ public class TestCommandParserTests
1413 public void SurroundWithDoubleQuotesWithNullThrows ( )
1514 {
1615 Assert . Throws < ArgumentNullException > ( ( ) =>
17- TestCommandParser . SurroundWithDoubleQuotes ( null ) ) ;
16+ TestCommandParser . SurroundWithDoubleQuotes ( null ! ) ) ;
1817 }
1918
2019 [ Theory ]
@@ -74,5 +73,71 @@ public void VSTestCommandIncludesPropertiesOption()
7473 propertyOption . Should ( ) . NotBeNull ( "VSTest command should include CommonOptions.PropertiesOption to support /p Property=Value syntax" ) ;
7574 propertyOption . Aliases . Should ( ) . Contain ( "/p" , "PropertiesOption should include /p alias for MSBuild compatibility" ) ;
7675 }
76+
77+ [ Fact ]
78+ public void DllDetectionShouldExcludeRunArgumentsAndGlobalProperties ( )
79+ {
80+ var parseResult = Parser . Parse ( """test -p:"RunConfig=abd.dll" -- RunConfig=abd.dll -p:"RunConfig=abd.dll" --results-directory hey.dll""" ) ;
81+ var args = parseResult . GetArguments ( ) ;
82+
83+ ( args , string [ ] settings ) = TestCommand . SeparateSettingsFromArgs ( args ) ;
84+ int settingsCount = TestCommand . GetSettingsCount ( settings ) ;
85+ settingsCount . Should ( ) . Be ( 4 ) ;
86+
87+ // Our unmatched tokens for this test case are only the settings (after the `--`).
88+ Assert . Equal ( settingsCount , parseResult . UnmatchedTokens . Count ) ;
89+
90+ Assert . Equal ( "--" , settings [ 0 ] ) ;
91+ Assert . Equal ( settings . Length , settingsCount + 1 ) ;
92+ for ( int i = 1 ; i <= settingsCount ; i ++ )
93+ {
94+ Assert . Equal ( settings [ ^ i ] , parseResult . UnmatchedTokens [ ^ i ] ) ;
95+ }
96+
97+ TestCommand . ContainsBuiltTestSources ( parseResult , settingsCount ) . Should ( ) . Be ( false ) ;
98+ }
99+
100+ [ Fact ]
101+ public void DllDetectionShouldBeTrueWhenPresentAloneEvenIfDuplicatedInSettings ( )
102+ {
103+ var parseResult = Parser . Parse ( """test abd.dll -- abd.dll""" ) ;
104+ var args = parseResult . GetArguments ( ) ;
105+
106+ ( args , string [ ] settings ) = TestCommand . SeparateSettingsFromArgs ( args ) ;
107+ int settingsCount = TestCommand . GetSettingsCount ( settings ) ;
108+ settingsCount . Should ( ) . Be ( 1 ) ;
109+
110+ // Our unmatched tokens here are all the settings, plus the abd.dll before the `--`.
111+ Assert . Equal ( settingsCount + 1 , parseResult . UnmatchedTokens . Count ) ;
112+
113+ Assert . Equal ( "--" , settings [ 0 ] ) ;
114+ Assert . Equal ( settings . Length , settingsCount + 1 ) ;
115+ for ( int i = 1 ; i <= settingsCount ; i ++ )
116+ {
117+ Assert . Equal ( settings [ ^ i ] , parseResult . UnmatchedTokens [ ^ i ] ) ;
118+ }
119+
120+ TestCommand . ContainsBuiltTestSources ( parseResult , settingsCount ) . Should ( ) . Be ( true ) ;
121+ }
122+
123+ [ Theory ]
124+ [ InlineData ( "abd.dll" , true ) ]
125+ [ InlineData ( "abd.dll --" , true ) ]
126+ [ InlineData ( "-dl:abd.dll" , false ) ]
127+ [ InlineData ( "-dl:abd.dll --" , false ) ]
128+ [ InlineData ( "-abcd:abd.dll" , false ) ]
129+ [ InlineData ( "-abcd:abd.dll --" , false ) ]
130+ [ InlineData ( "-p:abd.dll" , false ) ]
131+ [ InlineData ( "-p:abd.dll --" , false ) ]
132+ public void DllDetectionShouldWorkWhenNoSettings ( string testArgs , bool expectedContainsBuiltTestSource )
133+ {
134+ var parseResult = Parser . Parse ( $ "test { testArgs } ") ;
135+ var args = parseResult . GetArguments ( ) ;
136+
137+ ( args , string [ ] settings ) = TestCommand . SeparateSettingsFromArgs ( args ) ;
138+ int settingsCount = TestCommand . GetSettingsCount ( settings ) ;
139+ settingsCount . Should ( ) . Be ( 0 ) ;
140+ TestCommand . ContainsBuiltTestSources ( parseResult , settingsCount ) . Should ( ) . Be ( expectedContainsBuiltTestSource ) ;
141+ }
77142 }
78143}
0 commit comments