@@ -38,17 +38,17 @@ import (
3838 "github.com/stretchr/testify/require"
3939)
4040
41- func producePrototypes (t * testing.T , filename string ) ([]* types.Prototype , int ) {
41+ func producePrototypes (t * testing.T , filename string , mainFile string ) ([]* types.Prototype , int ) {
4242 bytes , err := ioutil .ReadFile (filepath .Join ("test_data" , filename ))
4343 require .NoError (t , err )
4444
4545 parser := & CTagsParser {}
46- parser .Parse (string (bytes ))
46+ parser .Parse (string (bytes ), mainFile )
4747 return parser .GeneratePrototypes ()
4848}
4949
5050func TestCTagsToPrototypesShouldListPrototypes (t * testing.T ) {
51- prototypes , line := producePrototypes (t , "TestCTagsParserShouldListPrototypes.txt" )
51+ prototypes , line := producePrototypes (t , "TestCTagsParserShouldListPrototypes.txt" , "/tmp/sketch7210316334309249705.cpp" )
5252 require .Equal (t , 5 , len (prototypes ))
5353 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
5454 require .Equal (t , "/tmp/sketch7210316334309249705.cpp" , prototypes [0 ].File )
@@ -61,7 +61,7 @@ func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) {
6161}
6262
6363func TestCTagsToPrototypesShouldListTemplates (t * testing.T ) {
64- prototypes , line := producePrototypes (t , "TestCTagsParserShouldListTemplates.txt" )
64+ prototypes , line := producePrototypes (t , "TestCTagsParserShouldListTemplates.txt" , "/tmp/sketch8398023134925534708.cpp" )
6565
6666 require .Equal (t , 3 , len (prototypes ))
6767 require .Equal (t , "template <typename T> T minimum (T a, T b);" , prototypes [0 ].Prototype )
@@ -73,7 +73,7 @@ func TestCTagsToPrototypesShouldListTemplates(t *testing.T) {
7373}
7474
7575func TestCTagsToPrototypesShouldListTemplates2 (t * testing.T ) {
76- prototypes , line := producePrototypes (t , "TestCTagsParserShouldListTemplates2.txt" )
76+ prototypes , line := producePrototypes (t , "TestCTagsParserShouldListTemplates2.txt" , "/tmp/sketch463160524247569568.cpp" )
7777
7878 require .Equal (t , 4 , len (prototypes ))
7979 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
@@ -86,15 +86,15 @@ func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) {
8686}
8787
8888func TestCTagsToPrototypesShouldDealWithClasses (t * testing.T ) {
89- prototypes , line := producePrototypes (t , "TestCTagsParserShouldDealWithClasses.txt" )
89+ prototypes , line := producePrototypes (t , "TestCTagsParserShouldDealWithClasses.txt" , "/tmp/sketch9043227824785312266.cpp" )
9090
9191 require .Equal (t , 0 , len (prototypes ))
9292
9393 require .Equal (t , 8 , line )
9494}
9595
9696func TestCTagsToPrototypesShouldDealWithStructs (t * testing.T ) {
97- prototypes , line := producePrototypes (t , "TestCTagsParserShouldDealWithStructs.txt" )
97+ prototypes , line := producePrototypes (t , "TestCTagsParserShouldDealWithStructs.txt" , "/tmp/sketch8930345717354294915.cpp" )
9898
9999 require .Equal (t , 3 , len (prototypes ))
100100 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
@@ -106,7 +106,7 @@ func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) {
106106}
107107
108108func TestCTagsToPrototypesShouldDealWithMacros (t * testing.T ) {
109- prototypes , line := producePrototypes (t , "TestCTagsParserShouldDealWithMacros.txt" )
109+ prototypes , line := producePrototypes (t , "TestCTagsParserShouldDealWithMacros.txt" , "/tmp/sketch5976699731718729500.cpp" )
110110
111111 require .Equal (t , 5 , len (prototypes ))
112112 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
@@ -120,7 +120,7 @@ func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) {
120120}
121121
122122func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures (t * testing.T ) {
123- prototypes , line := producePrototypes (t , "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt" )
123+ prototypes , line := producePrototypes (t , "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt" , "/tmp/test260613593/preproc/ctags_target.cpp" )
124124
125125 require .Equal (t , 1 , len (prototypes ))
126126 require .Equal (t , "boolean getBytes( byte addr, int amount );" , prototypes [0 ].Prototype )
@@ -130,7 +130,7 @@ func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T
130130}
131131
132132func TestCTagsToPrototypesClassMembersAreFilteredOut (t * testing.T ) {
133- prototypes , line := producePrototypes (t , "TestCTagsParserClassMembersAreFilteredOut.txt" )
133+ prototypes , line := producePrototypes (t , "TestCTagsParserClassMembersAreFilteredOut.txt" , "/tmp/test834438754/preproc/ctags_target.cpp" )
134134
135135 require .Equal (t , 2 , len (prototypes ))
136136 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
@@ -141,7 +141,7 @@ func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) {
141141}
142142
143143func TestCTagsToPrototypesStructWithFunctions (t * testing.T ) {
144- prototypes , line := producePrototypes (t , "TestCTagsParserStructWithFunctions.txt" )
144+ prototypes , line := producePrototypes (t , "TestCTagsParserStructWithFunctions.txt" , "/tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp" )
145145
146146 require .Equal (t , 2 , len (prototypes ))
147147 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
@@ -152,7 +152,7 @@ func TestCTagsToPrototypesStructWithFunctions(t *testing.T) {
152152}
153153
154154func TestCTagsToPrototypesDefaultArguments (t * testing.T ) {
155- prototypes , line := producePrototypes (t , "TestCTagsParserDefaultArguments.txt" )
155+ prototypes , line := producePrototypes (t , "TestCTagsParserDefaultArguments.txt" , "/tmp/test179252494/preproc/ctags_target.cpp" )
156156
157157 require .Equal (t , 3 , len (prototypes ))
158158 require .Equal (t , "void test(int x = 1);" , prototypes [0 ].Prototype )
@@ -164,7 +164,7 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) {
164164}
165165
166166func TestCTagsToPrototypesNamespace (t * testing.T ) {
167- prototypes , line := producePrototypes (t , "TestCTagsParserNamespace.txt" )
167+ prototypes , line := producePrototypes (t , "TestCTagsParserNamespace.txt" , "/tmp/test030883150/preproc/ctags_target.cpp" )
168168
169169 require .Equal (t , 2 , len (prototypes ))
170170 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
@@ -175,7 +175,7 @@ func TestCTagsToPrototypesNamespace(t *testing.T) {
175175}
176176
177177func TestCTagsToPrototypesStatic (t * testing.T ) {
178- prototypes , line := producePrototypes (t , "TestCTagsParserStatic.txt" )
178+ prototypes , line := producePrototypes (t , "TestCTagsParserStatic.txt" , "/tmp/test542833488/preproc/ctags_target.cpp" )
179179
180180 require .Equal (t , 3 , len (prototypes ))
181181 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
@@ -188,7 +188,7 @@ func TestCTagsToPrototypesStatic(t *testing.T) {
188188}
189189
190190func TestCTagsToPrototypesFunctionPointer (t * testing.T ) {
191- prototypes , line := producePrototypes (t , "TestCTagsParserFunctionPointer.txt" )
191+ prototypes , line := producePrototypes (t , "TestCTagsParserFunctionPointer.txt" , "/tmp/test547238273/preproc/ctags_target.cpp" )
192192
193193 require .Equal (t , 3 , len (prototypes ))
194194 require .Equal (t , "void t1Callback();" , prototypes [0 ].Prototype )
@@ -200,7 +200,7 @@ func TestCTagsToPrototypesFunctionPointer(t *testing.T) {
200200}
201201
202202func TestCTagsToPrototypesFunctionPointers (t * testing.T ) {
203- prototypes , line := producePrototypes (t , "TestCTagsParserFunctionPointers.txt" )
203+ prototypes , line := producePrototypes (t , "TestCTagsParserFunctionPointers.txt" , "/tmp/test907446433/preproc/ctags_target.cpp" )
204204 require .Equal (t , 2 , len (prototypes ))
205205 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
206206 require .Equal (t , "/tmp/test907446433/preproc/ctags_target.cpp" , prototypes [0 ].File )
@@ -209,11 +209,30 @@ func TestCTagsToPrototypesFunctionPointers(t *testing.T) {
209209 require .Equal (t , 2 , line )
210210}
211211
212+ func TestCTagsToPrototypesFunctionPointersNoIndirect (t * testing.T ) {
213+ prototypes , line := producePrototypes (t , "TestCTagsParserFunctionPointersNoIndirect.txt" , "/tmp/test547238273/preproc/bug_callback.ino" )
214+ require .Equal (t , 5 , len (prototypes ))
215+ require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
216+ require .Equal (t , "/tmp/test547238273/preproc/bug_callback.ino" , prototypes [0 ].File )
217+ require .Equal (t , "void loop();" , prototypes [1 ].Prototype )
218+
219+ require .Equal (t , 10 , line )
220+ }
221+
212222func TestCTagsRunnerSketchWithClassFunction (t * testing.T ) {
213- prototypes , _ := producePrototypes (t , "TestCTagsRunnerSketchWithClassFunction.txt" )
223+ prototypes , _ := producePrototypes (t , "TestCTagsRunnerSketchWithClassFunction.txt" , "/home/megabug/Workspace/arduino-builder/src/arduino.cc/builder/test/sketch_class_function/sketch_class_function.ino" )
214224
215225 require .Equal (t , 3 , len (prototypes ))
216226 require .Equal (t , "void setup();" , prototypes [0 ].Prototype )
217227 require .Equal (t , "void loop();" , prototypes [1 ].Prototype )
218228 require .Equal (t , "void asdf();" , prototypes [2 ].Prototype )
219229}
230+
231+ func TestCTagsRunnerSketchWithMultiFile (t * testing.T ) {
232+ prototypes , line := producePrototypes (t , "TestCTagsRunnerSketchWithMultifile.txt" , "/tmp/apUNI8a/main.ino" )
233+
234+ require .Equal (t , 0 , line )
235+ require .Equal (t , "void A7105_Setup();" , prototypes [0 ].Prototype )
236+ require .Equal (t , "void A7105_Reset();" , prototypes [1 ].Prototype )
237+ require .Equal (t , "int A7105_calibrate_VCB(uint8_t channel);" , prototypes [2 ].Prototype )
238+ }
0 commit comments