@@ -7,19 +7,23 @@ import (
7
7
"testing"
8
8
)
9
9
10
+ const (
11
+ DEBUG bool = false
12
+ )
13
+
10
14
func Test_basic_functionality (t * testing.T ) {
11
15
args := []string {"../data/helloworld.c" , "-o" , "../data/hello" }
12
16
exitCode := shared .Compile (args , "clang" )
13
17
if exitCode != 0 {
14
18
t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
15
- } else {
19
+ } else if DEBUG {
16
20
fmt .Println ("Compiled OK" )
17
21
}
18
22
args = []string {"get-bc" , "-v" , "../data/hello" }
19
23
exitCode = shared .Extract (args )
20
24
if exitCode != 0 {
21
25
t .Errorf ("Extraction of %v returned %v\n " , args , exitCode )
22
- } else {
26
+ } else if DEBUG {
23
27
fmt .Println ("Extraction OK" )
24
28
}
25
29
}
@@ -30,27 +34,27 @@ func Test_more_functionality(t *testing.T) {
30
34
exitCode := shared .Compile (args , "clang" )
31
35
if exitCode != 0 {
32
36
t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
33
- } else {
37
+ } else if DEBUG {
34
38
fmt .Println ("Compiled OK" )
35
39
}
36
40
ok , err := shared .IsObjectFileForOS (objectFile , runtime .GOOS )
37
41
if ! ok {
38
42
t .Errorf ("isObjectFileForOS(%v, %v) = %v (err = %v)\n " , objectFile , runtime .GOOS , ok , err )
39
- } else {
43
+ } else if DEBUG {
40
44
fmt .Printf ("isObjectFileForOS(%v, %v) = %v\n " , objectFile , runtime .GOOS , ok )
41
45
}
42
46
args = []string {objectFile , "-o" , "../data/bhello" }
43
47
exitCode = shared .Compile (args , "clang" )
44
48
if exitCode != 0 {
45
49
t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
46
- } else {
50
+ } else if DEBUG {
47
51
fmt .Println ("Compiled OK" )
48
52
}
49
53
args = []string {"get-bc" , "-v" , "../data/bhello" }
50
54
exitCode = shared .Extract (args )
51
55
if exitCode != 0 {
52
56
t .Errorf ("Extraction of %v returned %v\n " , args , exitCode )
53
- } else {
57
+ } else if DEBUG {
54
58
fmt .Println ("Extraction OK" )
55
59
}
56
60
}
@@ -64,39 +68,123 @@ func Test_obscure_functionality(t *testing.T) {
64
68
exitCode := shared .Compile (args , "clang" )
65
69
if exitCode != 0 {
66
70
t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
67
- } else {
71
+ } else if DEBUG {
68
72
fmt .Println ("Compiled OK" )
69
73
}
70
74
ok , err := shared .IsObjectFileForOS (sourceFile , opSys )
71
75
if ok {
72
76
t .Errorf ("isObjectFileForOS(%v, %v) = %v\n " , sourceFile , opSys , ok )
73
- } else {
77
+ } else if DEBUG {
74
78
fmt .Printf ("isObjectFileForOS(%v, %v) = %v (err = %v)\n " , sourceFile , opSys , ok , err )
75
79
}
76
80
ok , err = shared .IsObjectFileForOS (objectFile , opSys )
77
81
if ! ok {
78
82
t .Errorf ("isObjectFileForOS(%v, %v) = %v (err = %v)\n " , objectFile , opSys , ok , err )
79
- } else {
83
+ } else if DEBUG {
80
84
fmt .Printf ("isObjectFileForOS(%v, %v) = %v\n " , objectFile , opSys , ok )
81
85
}
82
86
args = []string {objectFile , "-o" , exeFile }
83
87
exitCode = shared .Compile (args , "clang" )
84
88
if exitCode != 0 {
85
89
t .Errorf ("Compile of %v returned %v\n " , args , exitCode )
86
- } else {
90
+ } else if DEBUG {
87
91
fmt .Println ("Compiled OK" )
88
92
}
89
93
ok , err = shared .IsObjectFileForOS (exeFile , opSys )
90
94
if ok {
91
95
t .Errorf ("isObjectFileForOS(%v, %v) = %v\n " , exeFile , opSys , ok )
92
- } else {
96
+ } else if DEBUG {
93
97
fmt .Printf ("isObjectFileForOS(%v, %v) = %v (err = %v)\n " , exeFile , opSys , ok , err )
94
98
}
95
99
args = []string {"get-bc" , "-v" , exeFile }
96
100
exitCode = shared .Extract (args )
97
101
if exitCode != 0 {
98
102
t .Errorf ("Extraction of %v returned %v\n " , args , exitCode )
99
- } else {
103
+ } else if DEBUG {
100
104
fmt .Println ("Extraction OK" )
101
105
}
102
106
}
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