88using System . Linq ;
99using System . Reflection ;
1010using System . Text ;
11+ using System . Text . RegularExpressions ;
1112using System . Threading . Tasks ;
1213using static System . Console ;
1314
@@ -120,40 +121,46 @@ public static void Test(ParsedCommandLine commandArgs, EndpointCollection endpoi
120121
121122 if ( commandArgs . Only != null )
122123 {
123- var index = int . Parse ( commandArgs . Only ) ;
124- if ( commandArgs . Diff )
124+ var indexes = ParseOnlyArgument ( commandArgs . Only , ( from testCase in testRunner . Tests select testCase . Name ) . ToArray ( ) ) ;
125+ if ( indexes . Length == 0 )
125126 {
126- var testCase = testRunner . Tests . ElementAt ( index ) ;
127- if ( testCase . ExpectedResponseBody == null )
127+ Error . WriteLine ( "ERROR: No testcases matches --only" ) ;
128+ }
129+
130+ foreach ( var index in indexes )
131+ {
132+ if ( commandArgs . Diff )
128133 {
129- Error . WriteLine ( $ "ERROR: Test case has no expected response body") ;
130- return ;
134+ var testCase = testRunner . Tests . ElementAt ( index ) ;
135+ if ( testCase . ExpectedResponseBody == null )
136+ {
137+ Error . WriteLine ( $ "ERROR: Test case has no expected response body") ;
138+ return ;
139+ }
140+
141+ var responseTuple = testCase . GetResponse ( endpointCollection , testRunner . Now ) ;
142+ if ( responseTuple . Item2 != null )
143+ {
144+ Error . WriteLine ( $ "ERROR: { responseTuple . Item2 } ") ;
145+ return ;
146+ }
147+
148+ var expectedFilename = Path . GetTempFileName ( ) ;
149+ var actualFilename = Path . GetTempFileName ( ) ;
150+
151+ File . WriteAllText ( expectedFilename , testCase . ExpectedResponseBody ) ;
152+ File . WriteAllText ( actualFilename , responseTuple . Item1 ) ;
153+
154+ StartExternalDiffTool ( expectedFilename , actualFilename ) ;
131155 }
132-
133- var responseTuple = testCase . GetResponseAsync ( endpointCollection ) . Result ;
134- if ( responseTuple . Item2 != null )
156+ if ( commandArgs . ShowResponse )
135157 {
136- Error . WriteLine ( $ "ERROR: { responseTuple . Item2 } ") ;
137- return ;
158+ testRunner . ShowResponse ( index ) ;
159+ }
160+ else
161+ {
162+ testRunner . ExecuteTestAndOutputResult ( index ) ;
138163 }
139-
140- var expectedFilename = Path . GetTempFileName ( ) ;
141- var actualFilename = Path . GetTempFileName ( ) ;
142-
143- File . WriteAllText ( expectedFilename , testCase . ExpectedResponseBody ) ;
144- File . WriteAllText ( actualFilename , responseTuple . Item1 ) ;
145-
146- StartExternalDiffTool ( expectedFilename , actualFilename ) ;
147-
148- return ;
149- }
150- if ( commandArgs . ShowResponse )
151- {
152- testRunner . ShowResponse ( index ) ;
153- }
154- else
155- {
156- testRunner . ExecuteTestAndOutputResult ( index ) ;
157164 }
158165 }
159166 else
@@ -162,6 +169,22 @@ public static void Test(ParsedCommandLine commandArgs, EndpointCollection endpoi
162169 }
163170 }
164171
172+ public static int [ ] ParseOnlyArgument ( string only , string [ ] names )
173+ {
174+ if ( Regex . IsMatch ( only , @"^\d+$" ) )
175+ {
176+ return new [ ] { int . Parse ( only ) } ;
177+ }
178+ else if ( Regex . IsMatch ( only , @"^(\d+)(,\d+)+$" ) )
179+ {
180+ return ( from strval in only . Split ( ',' ) select int . Parse ( strval ) ) . ToArray ( ) ;
181+ }
182+ else
183+ {
184+ return ( from i in Enumerable . Range ( 0 , names . Length ) where names [ i ] . ToLower ( ) . Contains ( only . ToLower ( ) ) select i ) . ToArray ( ) ;
185+ }
186+ }
187+
165188 public static void StartExternalDiffTool ( string expectedFilename , string actualFilename )
166189 {
167190 var difftool = Environment . GetEnvironmentVariable ( "DIFFTOOL" ) ;
0 commit comments