@@ -7,19 +7,23 @@ import (
77 "testing"
88)
99
10+ const (
11+ DEBUG bool = false
12+ )
13+
1014func Test_basic_functionality (t * testing.T ) {
1115 args := []string {"../data/helloworld.c" , "-o" , "../data/hello" }
1216 exitCode := shared .Compile (args , "clang" )
1317 if exitCode != 0 {
1418 t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
15- } else {
19+ } else if DEBUG {
1620 fmt .Println ("Compiled OK" )
1721 }
1822 args = []string {"get-bc" , "-v" , "../data/hello" }
1923 exitCode = shared .Extract (args )
2024 if exitCode != 0 {
2125 t .Errorf ("Extraction of %v returned %v\n " , args , exitCode )
22- } else {
26+ } else if DEBUG {
2327 fmt .Println ("Extraction OK" )
2428 }
2529}
@@ -30,27 +34,27 @@ func Test_more_functionality(t *testing.T) {
3034 exitCode := shared .Compile (args , "clang" )
3135 if exitCode != 0 {
3236 t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
33- } else {
37+ } else if DEBUG {
3438 fmt .Println ("Compiled OK" )
3539 }
3640 ok , err := shared .IsObjectFileForOS (objectFile , runtime .GOOS )
3741 if ! ok {
3842 t .Errorf ("isObjectFileForOS(%v, %v) = %v (err = %v)\n " , objectFile , runtime .GOOS , ok , err )
39- } else {
43+ } else if DEBUG {
4044 fmt .Printf ("isObjectFileForOS(%v, %v) = %v\n " , objectFile , runtime .GOOS , ok )
4145 }
4246 args = []string {objectFile , "-o" , "../data/bhello" }
4347 exitCode = shared .Compile (args , "clang" )
4448 if exitCode != 0 {
4549 t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
46- } else {
50+ } else if DEBUG {
4751 fmt .Println ("Compiled OK" )
4852 }
4953 args = []string {"get-bc" , "-v" , "../data/bhello" }
5054 exitCode = shared .Extract (args )
5155 if exitCode != 0 {
5256 t .Errorf ("Extraction of %v returned %v\n " , args , exitCode )
53- } else {
57+ } else if DEBUG {
5458 fmt .Println ("Extraction OK" )
5559 }
5660}
@@ -64,39 +68,123 @@ func Test_obscure_functionality(t *testing.T) {
6468 exitCode := shared .Compile (args , "clang" )
6569 if exitCode != 0 {
6670 t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
67- } else {
71+ } else if DEBUG {
6872 fmt .Println ("Compiled OK" )
6973 }
7074 ok , err := shared .IsObjectFileForOS (sourceFile , opSys )
7175 if ok {
7276 t .Errorf ("isObjectFileForOS(%v, %v) = %v\n " , sourceFile , opSys , ok )
73- } else {
77+ } else if DEBUG {
7478 fmt .Printf ("isObjectFileForOS(%v, %v) = %v (err = %v)\n " , sourceFile , opSys , ok , err )
7579 }
7680 ok , err = shared .IsObjectFileForOS (objectFile , opSys )
7781 if ! ok {
7882 t .Errorf ("isObjectFileForOS(%v, %v) = %v (err = %v)\n " , objectFile , opSys , ok , err )
79- } else {
83+ } else if DEBUG {
8084 fmt .Printf ("isObjectFileForOS(%v, %v) = %v\n " , objectFile , opSys , ok )
8185 }
8286 args = []string {objectFile , "-o" , exeFile }
8387 exitCode = shared .Compile (args , "clang" )
8488 if exitCode != 0 {
8589 t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
86- } else {
90+ } else if DEBUG {
8791 fmt .Println ("Compiled OK" )
8892 }
8993 ok , err = shared .IsObjectFileForOS (exeFile , opSys )
9094 if ok {
9195 t .Errorf ("isObjectFileForOS(%v, %v) = %v\n " , exeFile , opSys , ok )
92- } else {
96+ } else if DEBUG {
9397 fmt .Printf ("isObjectFileForOS(%v, %v) = %v (err = %v)\n " , exeFile , opSys , ok , err )
9498 }
9599 args = []string {"get-bc" , "-v" , exeFile }
96100 exitCode = shared .Extract (args )
97101 if exitCode != 0 {
98102 t .Errorf ("Extraction of %v returned %v\n " , args , exitCode )
99- } else {
103+ } else if DEBUG {
100104 fmt .Println ("Extraction OK" )
101105 }
102106}
107+
108+ func Test_file_type (t * testing.T ) {
109+ fictionalFile := "HopefullyThereIsNotAFileCalledThisNearBy.txt"
110+ dataDir := "../data"
111+ sourceFile := "../data/helloworld.c"
112+ objectFile := "../data/bhello.notanextensionthatwerecognize"
113+ exeFile := "../data/bhello"
114+
115+ var binaryFileType shared.BinaryType
116+ binaryFileType = shared .GetBinaryType (fictionalFile )
117+
118+ if binaryFileType != shared .BinaryUnknown {
119+ t .Errorf ("GetBinaryType(%v) = %v\n " , fictionalFile , binaryFileType )
120+ } else if DEBUG {
121+ fmt .Printf ("GetBinaryType(%v) = %v\n " , fictionalFile , binaryFileType )
122+ }
123+
124+ binaryFileType = shared .GetBinaryType (dataDir )
125+
126+ if binaryFileType != shared .BinaryUnknown {
127+ t .Errorf ("GetBinaryType(%v) = %v\n " , dataDir , binaryFileType )
128+ } else if DEBUG {
129+ fmt .Printf ("GetBinaryType(%v) = %v\n " , dataDir , binaryFileType )
130+ }
131+
132+ binaryFileType = shared .GetBinaryType (sourceFile )
133+ if binaryFileType != shared .BinaryUnknown {
134+ t .Errorf ("GetBinaryType(%v) = %v\n " , sourceFile , binaryFileType )
135+ } else if DEBUG {
136+ fmt .Printf ("GetBinaryType(%v) = %v\n " , sourceFile , binaryFileType )
137+ }
138+
139+ binaryFileType = shared .GetBinaryType (objectFile )
140+ if binaryFileType != shared .BinaryObject {
141+ t .Errorf ("GetBinaryType(%v) = %v\n " , objectFile , binaryFileType )
142+ } else if DEBUG {
143+ fmt .Printf ("GetBinaryType(%v) = %v\n " , objectFile , binaryFileType )
144+ }
145+
146+ binaryFileType = shared .GetBinaryType (exeFile )
147+ if binaryFileType != shared .BinaryExecutable {
148+ t .Errorf ("GetBinaryType(%v) = %v\n " , exeFile , binaryFileType )
149+ } else if DEBUG {
150+ fmt .Printf ("GetBinaryType(%v) = %v\n " , exeFile , binaryFileType )
151+ }
152+
153+ var plain bool
154+ plain = shared .IsPlainFile (fictionalFile )
155+
156+ if plain {
157+ t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , fictionalFile , plain )
158+ } else if DEBUG {
159+ fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , fictionalFile , plain )
160+ }
161+
162+ plain = shared .IsPlainFile (dataDir )
163+ if plain {
164+ t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , dataDir , plain )
165+ } else if DEBUG {
166+ fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , dataDir , plain )
167+ }
168+
169+ plain = shared .IsPlainFile (sourceFile )
170+ if ! plain {
171+ t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , sourceFile , plain )
172+ } else if DEBUG {
173+ fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , sourceFile , plain )
174+ }
175+
176+ plain = shared .IsPlainFile (objectFile )
177+ if ! plain {
178+ t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , objectFile , plain )
179+ } else if DEBUG {
180+ fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , objectFile , plain )
181+ }
182+
183+ plain = shared .IsPlainFile (exeFile )
184+ if ! plain {
185+ t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , exeFile , plain )
186+ } else if DEBUG {
187+ fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , exeFile , plain )
188+ }
189+
190+ }
0 commit comments