1- //
2- // Run Docker/Linux test with:
3- //
4- // docker build -t sgr/findexecutable .
5- // docker run --rm sgr/findexecutable
6- //
7-
8- using System ;
9- using System . IO ;
10- using System . Reflection ;
11-
12- namespace FindExecutable
13- {
14- internal class Program
15- {
16- static int Main ( string [ ] args )
1+ //
2+ // Run Docker/Linux test with:
3+ //
4+ // docker build -t sgr/findexecutable .
5+ // docker run --rm sgr/findexecutable
6+ //
7+
8+ using System ;
9+ using System . IO ;
10+ using System . Reflection ;
11+
12+ namespace FindExecutable
13+ {
14+ internal class Program
15+ {
16+ static int Main ( string [ ] args )
1717 {
18- Console . OutputEncoding = System . Text . Encoding . UTF8 ;
19- int retval = 0 ;
20-
21- retval = Math . Max ( retval , TestSearchGit ( ) ) ;
22-
23- retval = Math . Max ( retval , TestUnicodeFile ( ) ) ;
24-
25- Console . WriteLine ( "done." ) ;
18+ Console . OutputEncoding = System . Text . Encoding . UTF8 ;
19+ int retval = 0 ;
20+
21+ retval = Math . Max ( retval , TestSearchGit ( ) ) ;
22+
23+ retval = Math . Max ( retval , TestUnicodeFile ( ) ) ;
24+
25+ Console . WriteLine ( "done." ) ;
2626 if ( retval != 0 )
2727 {
2828 Console . WriteLine ( $ "exit code: { retval } ") ;
29- }
30- return retval ;
31- }
32-
33- static int TestSearchGit ( )
29+ }
30+ return retval ;
31+ }
32+
33+ static int TestSearchGit ( )
3434 {
35- string [ ] executables = [
36- "git.exe" ,
37- "git"
38- ] ;
39-
40- foreach ( string executable in executables )
41- {
42- try
43- {
44- Console . WriteLine ( $ "Searching for: { executable } ") ;
45-
46- string ? fullPath = FindExecutable . FullPath ( executable ) ;
47-
48- if ( fullPath != null )
49- {
50- if ( Path . IsPathFullyQualified ( fullPath ) )
51- {
52- Console . WriteLine ( $ "FOUND: { fullPath } ") ;
53- }
54- else
55- {
56- Console . WriteLine ( $ "FOUND w/ WARNING: non-full path, { fullPath } ") ;
57- }
58- }
59- else
60- {
61- Console . Error . WriteLine ( "NOT FOUND" ) ;
62- return 1 ;
63- }
64- }
65- catch ( Exception e )
66- {
67- Console . Error . WriteLine ( $ "FAILED, Exception: { e } ") ;
68- return 2 ;
69- }
70- }
71-
35+ string [ ] executables = [
36+ "git.exe" ,
37+ "git"
38+ ] ;
39+
40+ foreach ( string executable in executables )
41+ {
42+ try
43+ {
44+ Console . WriteLine ( $ "Searching for: { executable } ") ;
45+
46+ string ? fullPath = FindExecutable . FullPath ( executable ) ;
47+
48+ if ( fullPath != null )
49+ {
50+ if ( Path . IsPathFullyQualified ( fullPath ) )
51+ {
52+ Console . WriteLine ( $ "FOUND: { fullPath } ") ;
53+ }
54+ else
55+ {
56+ Console . WriteLine ( $ "FOUND w/ WARNING: non-full path, { fullPath } ") ;
57+ }
58+ }
59+ else
60+ {
61+ Console . Error . WriteLine ( "NOT FOUND" ) ;
62+ return 1 ;
63+ }
64+ }
65+ catch ( Exception e )
66+ {
67+ Console . Error . WriteLine ( $ "FAILED, Exception: { e } ") ;
68+ return 2 ;
69+ }
70+ }
71+
7272 return 0 ;
73- }
74-
75- static int TestUnicodeFile ( )
73+ }
74+
75+ static int TestUnicodeFile ( )
7676 {
7777 Console . WriteLine ( "Searching for an (artificial) executable with a unicode name:" ) ;
7878
7979 const string gitExec = "git" ;
80- const string unicodeExec = "まじかよ。.exe" ;
81-
82- if ( File . Exists ( unicodeExec ) )
83- {
84- File . Delete ( unicodeExec ) ;
85- }
86-
80+ const string unicodeExec = "まじかよ。.exe" ;
81+
82+ if ( File . Exists ( unicodeExec ) )
83+ {
84+ File . Delete ( unicodeExec ) ;
85+ }
86+
8787 string unicodeExecPath = Path . Join ( AppContext . BaseDirectory , unicodeExec ) ;
8888 string ? gitFullPath = FindExecutable . FullPath ( gitExec ) ;
8989
@@ -93,30 +93,30 @@ static int TestUnicodeFile()
9393 return 5 ;
9494 }
9595
96- File . Copy ( gitFullPath , unicodeExecPath ) ;
97-
96+ File . Copy ( gitFullPath , unicodeExecPath ) ;
97+
9898 if ( ! OperatingSystem . IsWindows ( ) )
9999 {
100100 File . SetUnixFileMode ( unicodeExecPath , File . GetUnixFileMode ( gitFullPath ) ) ;
101101 }
102102
103- if ( ! FindExecutable . IsExecutable ( unicodeExecPath ) )
103+ if ( ! FindExecutable . IsExecutable ( unicodeExecPath ) )
104104 {
105105 Console . WriteLine ( $ "Failed to setup the unicode executable file name: { unicodeExecPath } ") ;
106106 return 3 ;
107- }
107+ }
108108
109109 string ? findIt = FindExecutable . FullPath ( unicodeExec , includeCurrentDirectory : true ) ;
110110 if ( string . IsNullOrEmpty ( findIt ) )
111111 {
112112 Console . WriteLine ( $ "Failed to find the unicode executable file name: { unicodeExec } ") ;
113113 return 4 ;
114- }
114+ }
115115
116116 Console . WriteLine ( $ "FOUND: { findIt } ") ;
117117
118118 return 0 ;
119- }
120-
121- }
122- }
119+ }
120+
121+ }
122+ }
0 commit comments