@@ -52,6 +52,145 @@ public void FundamentalPathsMatchExpectedPathsWhenUseUnixStylePathsOnlyIsUsed()
5252 Assert . AreEqual ( $ "{ currentDirectory } /state", platformSpecifics . StateDirectory ) ;
5353 }
5454
55+ [ Test ]
56+ [ Platform ( Exclude = "Unix,Linux,MacOsX" ) ]
57+ [ TestCase ( "execute" , "execute" ) ]
58+ [ TestCase ( "execute --option-a=one --option-b=two --option_c=three" , "execute" ) ]
59+ [ TestCase ( "execute --option-a one --option-b \" two\" --option_c 'three'" , "execute" ) ]
60+ [ TestCase ( "execute.exe" , "execute" ) ]
61+ [ TestCase ( "execute.exe --option-a=one --option-b=two --option_c=three" , "execute" ) ]
62+ [ TestCase ( "execute.exe --option-a one --option-b \" two\" --option_c 'three'" , "execute" ) ]
63+ [ TestCase ( "./execute" , "execute" ) ]
64+ [ TestCase ( "../execute --option-a=one --option-b=two --option_c=three" , "execute" ) ]
65+ [ TestCase ( "/home/user/tools/execute --option-a one --option-b \" two\" --option_c 'three'" , "execute" ) ]
66+ [ TestCase ( ".\\ execute.exe" , "execute" ) ]
67+ [ TestCase ( ".\\ execute.exe --option-a=one --option-b=two --option_c=three" , "execute" ) ]
68+ [ TestCase ( "C:\\ Users\\ User\\ tools\\ execute.exe --option-a one --option-b \" two\" --option_c 'three'" , "execute" ) ]
69+ public void GetCommmandNameSupportsTheExpectedRangeOfCommands ( string commandLine , string expectedCommandName )
70+ {
71+ Assert . IsTrue ( PlatformSpecifics . TryGetCommandName ( commandLine , out string actualCommandName ) , $ "Failed: { commandLine } ") ;
72+ Assert . AreEqual ( expectedCommandName , actualCommandName , $ "Failed: { commandLine } ") ;
73+ }
74+
75+ [ Test ]
76+ [ Platform ( Exclude = "Unix,Linux,MacOsX" ) ]
77+ [ TestCase ( "bash -c \" hostnamectl\" " , "hostnamectl" ) ]
78+ [ TestCase ( "bash -c \" execute.sh\" " , "execute" ) ]
79+ [ TestCase ( "bash -c \" execute.sh one two three\" " , "execute" ) ]
80+ [ TestCase ( "bash -c \" execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
81+ [ TestCase ( "bash -c \" ./execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
82+ [ TestCase ( "bash -c \" ../execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
83+ [ TestCase ( "bash -c \" /home/user/tools/execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
84+ [ TestCase ( "bash -c \" sudo execute.sh\" " , "execute" ) ]
85+ [ TestCase ( "bash -c \" sudo execute.sh one two three\" " , "execute" ) ]
86+ [ TestCase ( "bash -c \" sudo execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
87+ [ TestCase ( "bash -c \" sudo ./execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
88+ [ TestCase ( "bash -c \" sudo ../execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
89+ [ TestCase ( "bash -c \" sudo /home/user/tools/execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
90+ [ TestCase ( "sudo bash -c \" execute.sh\" " , "execute" ) ]
91+ [ TestCase ( "sudo bash -c \" execute.sh one two three\" " , "execute" ) ]
92+ [ TestCase ( "sudo bash -c \" execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
93+ [ TestCase ( "sudo bash -c \" ./execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
94+ [ TestCase ( "sudo bash -c \" ../execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
95+ [ TestCase ( "sudo bash -c \" /home/user/tools/execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
96+ [ TestCase ( "sudo bash -c \" /home/user/tools/bash/execute.sh --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
97+ public void GetCommmandNameSupportsTheExpectedRangeOfBashCommands ( string commandLine , string expectedCommandName )
98+ {
99+ Assert . IsTrue ( PlatformSpecifics . TryGetCommandName ( commandLine , out string actualCommandName ) , $ "Failed: { commandLine } ") ;
100+ Assert . AreEqual ( expectedCommandName , actualCommandName , $ "Failed: { commandLine } ") ;
101+ }
102+
103+ [ Test ]
104+ [ Platform ( Exclude = "Unix,Linux,MacOsX" ) ]
105+ [ TestCase ( "cmd /C \" execute.exe\" " , "execute" ) ]
106+ [ TestCase ( "cmd /C \" execute.exe one two three\" " , "execute" ) ]
107+ [ TestCase ( "cmd /C \" execute.exe --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
108+ [ TestCase ( "cmd /C \" execute.cmd\" " , "execute" ) ]
109+ [ TestCase ( "cmd /C \" execute.cmd one two three\" " , "execute" ) ]
110+ [ TestCase ( "cmd /C \" execute.cmd --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
111+ [ TestCase ( "cmd /C \" execute.bat\" " , "execute" ) ]
112+ [ TestCase ( "cmd /C \" execute.bat one two three\" " , "execute" ) ]
113+ [ TestCase ( "cmd /C \" execute.bat --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
114+ [ TestCase ( "cmd.exe /C \" execute.exe\" " , "execute" ) ]
115+ [ TestCase ( "cmd.exe /C \" execute.exe one two three\" " , "execute" ) ]
116+ [ TestCase ( "cmd.exe /C \" execute.exe --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
117+ [ TestCase ( "cmd.exe /C \" execute.cmd\" " , "execute" ) ]
118+ [ TestCase ( "cmd.exe /C \" execute.cmd one two three\" " , "execute" ) ]
119+ [ TestCase ( "cmd.exe /C \" execute.cmd --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
120+ [ TestCase ( "cmd.exe /C \" execute.bat\" " , "execute" ) ]
121+ [ TestCase ( "cmd.exe /C \" execute.bat one two three\" " , "execute" ) ]
122+ [ TestCase ( "cmd.exe /C \" execute.bat --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
123+ [ TestCase ( "cmd /C \" .\\ execute.bat --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
124+ [ TestCase ( "cmd /C \" ..\\ execute.bat --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
125+ [ TestCase ( "cmd /C \" C:\\ Users\\ User\\ tools\\ execute.bat --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
126+ [ TestCase ( "cmd /C \" C:\\ Users\\ User\\ tools\\ cmd\\ execute.bat --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
127+ public void GetCommmandNameSupportsTheExpectedRangeOfCmdCommands ( string commandLine , string expectedCommandName )
128+ {
129+ Assert . IsTrue ( PlatformSpecifics . TryGetCommandName ( commandLine , out string actualCommandName ) , $ "Failed: { commandLine } ") ;
130+ Assert . AreEqual ( expectedCommandName , actualCommandName , $ "Failed: { commandLine } ") ;
131+ }
132+
133+ [ Test ]
134+ [ Platform ( Exclude = "Unix,Linux,MacOsX" ) ]
135+ [ TestCase ( "Invoke-This.ps1" , "Invoke-This" ) ]
136+ [ TestCase ( "Invoke-This.ps1 -OptionA one -OptionB=two -OptionC three" , "Invoke-This" ) ]
137+ [ TestCase ( "pwsh Invoke-This.ps1 -OptionA one -OptionB=two -OptionC three" , "Invoke-This" ) ]
138+ [ TestCase ( "pwsh.exe Invoke-This.ps1 -OptionA one -OptionB=two -OptionC three" , "Invoke-This" ) ]
139+ [ TestCase ( "pwsh \" Invoke-This.ps1 -OptionA one -OptionB=two -OptionC three\" " , "Invoke-This" ) ]
140+ [ TestCase ( "pwsh.exe \" Invoke-This.ps1 -OptionA one -OptionB=two -OptionC three\" " , "Invoke-This" ) ]
141+ [ TestCase ( "pwsh -C \" Invoke-This.ps1 -OptionA one -OptionB=two -OptionC three\" " , "Invoke-This" ) ]
142+ [ TestCase ( "pwsh.exe -C \" Invoke-This.ps1 -OptionA one -OptionB=two -OptionC three\" " , "Invoke-This" ) ]
143+ [ TestCase ( "pwsh -Command \" Invoke-This.ps1 -OptionA one -OptionB=two -OptionC three\" " , "Invoke-This" ) ]
144+ [ TestCase ( "pwsh.exe -Command \" Invoke-This.ps1 -OptionA one -OptionB=two -OptionC three\" " , "Invoke-This" ) ]
145+ [ TestCase ( "pwsh -Command \" Import-Module AnyModule.psd1;Invoke-This -OptionA one -OptionB=two -OptionC three\" " , "pwsh" ) ]
146+ [ TestCase ( "pwsh.exe -Command \" Import-Module AnyModule.psm1;Invoke-This -OptionA one -OptionB=two -OptionC three\" " , "pwsh" ) ]
147+ [ TestCase ( "powershell -Command \" Import-Module AnyModule.psd1 && Invoke-This -OptionA one -OptionB=two -OptionC three\" " , "powershell" ) ]
148+ [ TestCase ( "powershell.exe -Command \" Import-Module AnyModule.psm1 && Invoke-This -OptionA one -OptionB=two -OptionC three\" " , "powershell" ) ]
149+ [ TestCase ( "C:\\ ProgramFiles\\ PowerShell7\\ pwsh.exe -Command \" Import-Module AnyModule.psm1;Invoke-This -OptionA one -OptionB=two -OptionC three\" " , "pwsh" ) ]
150+ [ TestCase ( "/home/user/powershell7.5.4/pwsh -Command \" Import-Module AnyModule.psd1;Invoke-This -OptionA one -OptionB=two -OptionC three\" " , "pwsh" ) ]
151+ public void GetCommmandNameSupportsTheExpectedRangeOfPowerShellCommands ( string commandLine , string expectedCommandName )
152+ {
153+ Assert . IsTrue ( PlatformSpecifics . TryGetCommandName ( commandLine , out string actualCommandName ) , $ "Failed: { commandLine } ") ;
154+ Assert . AreEqual ( expectedCommandName , actualCommandName , $ "Failed: { commandLine } ") ;
155+ }
156+
157+ [ Test ]
158+ [ Platform ( Exclude = "Unix,Linux,MacOsX" ) ]
159+ [ TestCase ( "execute.py --option-a=one --option-b=two --option_c=three" , "execute" ) ]
160+ [ TestCase ( "py \" execute.py --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
161+ [ TestCase ( "py.exe \" execute.py --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
162+ [ TestCase ( "python \" execute.py --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
163+ [ TestCase ( "python.exe \" execute.py --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
164+ [ TestCase ( "python3 \" execute.py --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
165+ [ TestCase ( "python3.exe \" execute.py --option-a=one --option-b=two --option_c=three\" " , "execute" ) ]
166+ [ TestCase ( "py -c \" import sys; print(sys.version)\" " , "py" ) ]
167+ [ TestCase ( "py -c \" print('Hello from inline Python')\" " , "py" ) ]
168+ [ TestCase ( "python3 -c \" print('Hello from inline Python')\" " , "python3" ) ]
169+ [ TestCase ( "python3 -c \" import sys; print(sys.version)\" " , "python3" ) ]
170+ [ TestCase ( "python.exe -c \" print('Hello from inline Python')\" " , "python" ) ]
171+ [ TestCase ( "python.exe -c \" import sys; print(sys.version)\" " , "python" ) ]
172+ [ TestCase ( "/home/user/python/python3 -c \" print('Hello from inline Python')\" " , "python3" ) ]
173+ [ TestCase ( "C:\\ ProgramFiles\\ Python3\\ python.exe -c \" import sys; print(sys.version)\" " , "python" ) ]
174+ public void GetCommmandNameSupportsTheExpectedRangeOfPythonCommands ( string commandLine , string expectedCommandName )
175+ {
176+ Assert . IsTrue ( PlatformSpecifics . TryGetCommandName ( commandLine , out string actualCommandName ) , $ "Failed: { commandLine } ") ;
177+ Assert . AreEqual ( expectedCommandName , actualCommandName , $ "Failed: { commandLine } ") ;
178+ }
179+
180+ [ Test ]
181+ [ Platform ( Exclude = "Unix,Linux,MacOsX" ) ]
182+ [ TestCase ( "anycommand /NOTTHECOMMAND --option-a=one --option-b=two --option_c=three" , "anycommand" ) ]
183+ [ TestCase ( "anycommand.exe /NOT_THE_COMMAND --option-a=one --option-b=two --option_c=three" , "anycommand" ) ]
184+ [ TestCase ( "./anycommand /NOTTHECOMMAND --option-a=one --option-b=two --option_c=three" , "anycommand" ) ]
185+ [ TestCase ( ".\\ anycommand /NOTTHECOMMAND --option-a=one --option-b=two --option_c=three" , "anycommand" ) ]
186+ [ TestCase ( "/home/user/tools/anycommand /NOTTHECOMMAND --option-a=one --option-b=two --option_c=three" , "anycommand" ) ]
187+ [ TestCase ( "C:\\ Users\\ User\\ tools\\ anycommand /NOTTHECOMMAND --option-a=one --option-b=two --option_c=three" , "anycommand" ) ]
188+ public void GetCommmandNameSupportsCommandAnomalies ( string commandLine , string expectedCommandName )
189+ {
190+ Assert . IsTrue ( PlatformSpecifics . TryGetCommandName ( commandLine , out string actualCommandName ) , $ "Failed: { commandLine } ") ;
191+ Assert . AreEqual ( expectedCommandName , actualCommandName , $ "Failed: { commandLine } ") ;
192+ }
193+
55194 [ Test ]
56195 public void GetPackagePathReturnsTheExpectedPathOnUnixSystems ( )
57196 {
0 commit comments