@@ -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,39 @@ 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,40 +111,79 @@ func Test_file_type(t *testing.T) {
107111 sourceFile := "../data/helloworld.c"
108112 objectFile := "../data/bhello.notanextensionthatwerecognize"
109113 exeFile := "../data/bhello"
110- fmt .Printf ("GetBinaryType(%v) = %v\n " , fictionalFile , shared .GetBinaryType (fictionalFile ))
111- fmt .Printf ("GetBinaryType(%v) = %v\n " , dataDir , shared .GetBinaryType (dataDir ))
112- fmt .Printf ("GetBinaryType(%v) = %v\n " , sourceFile , shared .GetBinaryType (sourceFile ))
113- fmt .Printf ("GetBinaryType(%v) = %v\n " , objectFile , shared .GetBinaryType (objectFile ))
114- fmt .Printf ("GetBinaryType(%v) = %v\n " , exeFile , shared .GetBinaryType (exeFile ))
115114
116- plain := shared .IsPlainFile (fictionalFile )
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+
117156 if plain {
118157 t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , fictionalFile , plain )
119- } else {
158+ } else if DEBUG {
120159 fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , fictionalFile , plain )
121160 }
161+
122162 plain = shared .IsPlainFile (dataDir )
123163 if plain {
124164 t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , dataDir , plain )
125- } else {
165+ } else if DEBUG {
126166 fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , dataDir , plain )
127167 }
168+
128169 plain = shared .IsPlainFile (sourceFile )
129170 if ! plain {
130171 t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , sourceFile , plain )
131- } else {
172+ } else if DEBUG {
132173 fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , sourceFile , plain )
133174 }
175+
134176 plain = shared .IsPlainFile (objectFile )
135177 if ! plain {
136178 t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , objectFile , plain )
137- } else {
179+ } else if DEBUG {
138180 fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , objectFile , plain )
139181 }
182+
140183 plain = shared .IsPlainFile (exeFile )
141184 if ! plain {
142185 t .Errorf ("shared.IsPlainFile(%v) returned %v\n " , exeFile , plain )
143- } else {
186+ } else if DEBUG {
144187 fmt .Printf ("shared.IsPlainFile(%v) returned %v\n " , exeFile , plain )
145188 }
146189
0 commit comments