@@ -23,9 +23,6 @@ static void ValidatePathOptions(ParseResult parseResult)
23
23
if ( parseResult . HasOption ( TestingPlatformOptions . TestModulesFilterOption ) )
24
24
count ++ ;
25
25
26
- if ( parseResult . HasOption ( TestingPlatformOptions . DirectoryOption ) )
27
- count ++ ;
28
-
29
26
if ( parseResult . HasOption ( TestingPlatformOptions . SolutionOption ) )
30
27
count ++ ;
31
28
@@ -60,18 +57,12 @@ public static bool ValidateBuildPathOptions(BuildOptions buildPathOptions, Termi
60
57
61
58
if ( ! string . IsNullOrEmpty ( pathOptions . ProjectPath ) )
62
59
{
63
- return ValidateProjectFilePath ( pathOptions . ProjectPath , output ) ;
60
+ return ValidateProjectPath ( pathOptions . ProjectPath , output ) ;
64
61
}
65
62
66
63
if ( ! string . IsNullOrEmpty ( pathOptions . SolutionPath ) )
67
64
{
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 ) ;
75
66
}
76
67
77
68
return true ;
@@ -105,39 +96,53 @@ public static void ValidateSolutionOrProjectOrDirectoryOrModulesArePassedCorrect
105
96
{
106
97
throw new GracefulException ( CliCommandStrings . TestCommandUseProject ) ;
107
98
}
108
- else if ( Directory . Exists ( token ) )
109
- {
110
- throw new GracefulException ( CliCommandStrings . TestCommandUseDirectory ) ;
111
- }
112
99
else if ( ( token . EndsWith ( ".dll" , StringComparison . OrdinalIgnoreCase ) ||
113
100
token . EndsWith ( ".exe" , StringComparison . OrdinalIgnoreCase ) ) &&
114
101
File . Exists ( token ) )
115
102
{
116
103
throw new GracefulException ( CliCommandStrings . TestCommandUseTestModules ) ;
117
104
}
105
+ else if ( Directory . Exists ( token ) )
106
+ {
107
+ throw new GracefulException ( CliCommandStrings . TestCommandUseDirectoryWithSwitch ) ;
108
+ }
118
109
}
119
110
}
120
111
121
- private static bool ValidateSolutionFilePath ( string filePath , TerminalTestReporter output )
112
+ private static bool ValidateSolutionPath ( string path , TerminalTestReporter output )
122
113
{
123
- if ( ! CliConstants . SolutionExtensions . Contains ( Path . GetExtension ( filePath ) ) )
114
+ // If it's a directory, just check if it exists
115
+ if ( Directory . Exists ( path ) )
124
116
{
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 ) ) ;
126
124
return false ;
127
125
}
128
126
129
- return ValidateFilePathExists ( filePath , output ) ;
127
+ return ValidateFilePathExists ( path , output ) ;
130
128
}
131
129
132
- private static bool ValidateProjectFilePath ( string filePath , TerminalTestReporter output )
130
+ private static bool ValidateProjectPath ( string path , TerminalTestReporter output )
133
131
{
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 ) )
135
140
{
136
- output . WriteMessage ( string . Format ( CliCommandStrings . CmdInvalidProjectFileExtensionErrorDescription , filePath ) ) ;
141
+ output . WriteMessage ( string . Format ( CliCommandStrings . CmdInvalidProjectFileExtensionErrorDescription , path ) ) ;
137
142
return false ;
138
143
}
139
144
140
- return ValidateFilePathExists ( filePath , output ) ;
145
+ return ValidateFilePathExists ( path , output ) ;
141
146
}
142
147
143
148
private static bool ValidateFilePathExists ( string filePath , TerminalTestReporter output )
0 commit comments