@@ -23,9 +23,6 @@ static void ValidatePathOptions(ParseResult parseResult)
2323 if ( parseResult . HasOption ( TestingPlatformOptions . TestModulesFilterOption ) )
2424 count ++ ;
2525
26- if ( parseResult . HasOption ( TestingPlatformOptions . DirectoryOption ) )
27- count ++ ;
28-
2926 if ( parseResult . HasOption ( TestingPlatformOptions . SolutionOption ) )
3027 count ++ ;
3128
@@ -60,18 +57,12 @@ public static bool ValidateBuildPathOptions(BuildOptions buildPathOptions, Termi
6057
6158 if ( ! string . IsNullOrEmpty ( pathOptions . ProjectPath ) )
6259 {
63- return ValidateProjectFilePath ( pathOptions . ProjectPath , output ) ;
60+ return ValidateProjectPath ( pathOptions . ProjectPath , output ) ;
6461 }
6562
6663 if ( ! string . IsNullOrEmpty ( pathOptions . SolutionPath ) )
6764 {
68- return ValidateSolutionFilePath ( pathOptions . SolutionPath , output ) ;
69- }
70-
71- if ( ! string . IsNullOrEmpty ( pathOptions . DirectoryPath ) && ! Directory . Exists ( pathOptions . DirectoryPath ) )
72- {
73- output . WriteMessage ( string . Format ( CliCommandStrings . CmdNonExistentDirectoryErrorDescription , pathOptions . DirectoryPath ) ) ;
74- return false ;
65+ return ValidateSolutionPath ( pathOptions . SolutionPath , output ) ;
7566 }
7667
7768 return true ;
@@ -105,39 +96,53 @@ public static void ValidateSolutionOrProjectOrDirectoryOrModulesArePassedCorrect
10596 {
10697 throw new GracefulException ( CliCommandStrings . TestCommandUseProject ) ;
10798 }
108- else if ( Directory . Exists ( token ) )
109- {
110- throw new GracefulException ( CliCommandStrings . TestCommandUseDirectory ) ;
111- }
11299 else if ( ( token . EndsWith ( ".dll" , StringComparison . OrdinalIgnoreCase ) ||
113100 token . EndsWith ( ".exe" , StringComparison . OrdinalIgnoreCase ) ) &&
114101 File . Exists ( token ) )
115102 {
116103 throw new GracefulException ( CliCommandStrings . TestCommandUseTestModules ) ;
117104 }
105+ else if ( Directory . Exists ( token ) )
106+ {
107+ throw new GracefulException ( CliCommandStrings . TestCommandUseDirectoryWithSwitch ) ;
108+ }
118109 }
119110 }
120111
121- private static bool ValidateSolutionFilePath ( string filePath , TerminalTestReporter output )
112+ private static bool ValidateSolutionPath ( string path , TerminalTestReporter output )
122113 {
123- if ( ! CliConstants . SolutionExtensions . Contains ( Path . GetExtension ( filePath ) ) )
114+ // If it's a directory, just check if it exists
115+ if ( Directory . Exists ( path ) )
124116 {
125- output . WriteMessage ( string . Format ( CliCommandStrings . CmdInvalidSolutionFileExtensionErrorDescription , filePath ) ) ;
117+ return true ;
118+ }
119+
120+ // If it's not a directory, validate as a file path
121+ if ( ! CliConstants . SolutionExtensions . Contains ( Path . GetExtension ( path ) ) )
122+ {
123+ output . WriteMessage ( string . Format ( CliCommandStrings . CmdInvalidSolutionFileExtensionErrorDescription , path ) ) ;
126124 return false ;
127125 }
128126
129- return ValidateFilePathExists ( filePath , output ) ;
127+ return ValidateFilePathExists ( path , output ) ;
130128 }
131129
132- private static bool ValidateProjectFilePath ( string filePath , TerminalTestReporter output )
130+ private static bool ValidateProjectPath ( string path , TerminalTestReporter output )
133131 {
134- if ( ! Path . GetExtension ( filePath ) . EndsWith ( "proj" , StringComparison . OrdinalIgnoreCase ) )
132+ // If it's a directory, just check if it exists
133+ if ( Directory . Exists ( path ) )
134+ {
135+ return true ;
136+ }
137+
138+ // If it's not a directory, validate as a file path
139+ if ( ! Path . GetExtension ( path ) . EndsWith ( "proj" , StringComparison . OrdinalIgnoreCase ) )
135140 {
136- output . WriteMessage ( string . Format ( CliCommandStrings . CmdInvalidProjectFileExtensionErrorDescription , filePath ) ) ;
141+ output . WriteMessage ( string . Format ( CliCommandStrings . CmdInvalidProjectFileExtensionErrorDescription , path ) ) ;
137142 return false ;
138143 }
139144
140- return ValidateFilePathExists ( filePath , output ) ;
145+ return ValidateFilePathExists ( path , output ) ;
141146 }
142147
143148 private static bool ValidateFilePathExists ( string filePath , TerminalTestReporter output )
0 commit comments