@@ -54,7 +54,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) {
5454 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
5555
5656 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
57- require .Equal (t , "#line 33 " + quotedSketchLocation + "\n void setup();\n #line 46 " + quotedSketchLocation + "\n void loop();\n #line 62 " + quotedSketchLocation + "\n void process(BridgeClient client);\n #line 82 " + quotedSketchLocation + "\n void digitalCommand(BridgeClient client);\n #line 109 " + quotedSketchLocation + "\n void analogCommand(BridgeClient client);\n #line 149 " + quotedSketchLocation + "\n void modeCommand(BridgeClient client);\n #line 33 " + quotedSketchLocation + "\n " , ctx . PrototypesSection )
57+ require .Contains (t , ctx . SketchSourceAfterArduinoPreprocessing , "#line 33 " + quotedSketchLocation + "\n void setup();\n #line 46 " + quotedSketchLocation + "\n void loop();\n #line 62 " + quotedSketchLocation + "\n void process(BridgeClient client);\n #line 82 " + quotedSketchLocation + "\n void digitalCommand(BridgeClient client);\n #line 109 " + quotedSketchLocation + "\n void analogCommand(BridgeClient client);\n #line 149 " + quotedSketchLocation + "\n void modeCommand(BridgeClient client);\n #line 33 " + quotedSketchLocation + "\n " )
5858}
5959
6060func TestPrototypesAdderSketchWithIfDef (t * testing.T ) {
@@ -262,7 +262,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) {
262262 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
263263
264264 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
265- require .Equal (t , "#line 13 " + quotedSketchLocation + "\n void setup();\n #line 17 " + quotedSketchLocation + "\n void loop();\n #line 13 " + quotedSketchLocation + "\n " , ctx . PrototypesSection )
265+ require .Contains (t , ctx . SketchSourceAfterArduinoPreprocessing , "#line 13 " + quotedSketchLocation + "\n void setup();\n #line 17 " + quotedSketchLocation + "\n void loop();\n #line 13 " + quotedSketchLocation + "\n " )
266266
267267 preprocessed := LoadAndInterpolate (t , filepath .Join ("sketch_with_config" , "sketch_with_config.preprocessed.txt" ), ctx )
268268 require .Equal (t , preprocessed , strings .Replace (ctx .SketchSourceAfterArduinoPreprocessing , "\r \n " , "\n " , - 1 ))
@@ -293,7 +293,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) {
293293 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
294294
295295 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
296- require .Equal (t , "" , ctx .PrototypesSection )
296+ require .Equal (t , ctx . SketchSourceMerged , ctx .SketchSourceAfterArduinoPreprocessing ) // No prototypes added
297297}
298298
299299func TestPrototypesAdderSketchNoFunctions (t * testing.T ) {
@@ -320,7 +320,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) {
320320 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
321321
322322 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
323- require .Equal (t , "" , ctx .PrototypesSection )
323+ require .Equal (t , ctx . SketchSourceMerged , ctx .SketchSourceAfterArduinoPreprocessing ) // No prototypes added
324324}
325325
326326func TestPrototypesAdderSketchWithDefaultArgs (t * testing.T ) {
@@ -348,7 +348,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) {
348348 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
349349
350350 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
351- require .Equal (t , "#line 4 " + quotedSketchLocation + "\n void setup();\n #line 7 " + quotedSketchLocation + "\n void loop();\n #line 1 " + quotedSketchLocation + "\n " , ctx . PrototypesSection )
351+ require .Contains (t , ctx . SketchSourceAfterArduinoPreprocessing , "#line 4 " + quotedSketchLocation + "\n void setup();\n #line 7 " + quotedSketchLocation + "\n void loop();\n #line 1 " + quotedSketchLocation + "\n " )
352352}
353353
354354func TestPrototypesAdderSketchWithInlineFunction (t * testing.T ) {
@@ -378,7 +378,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) {
378378 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
379379
380380 expected := "#line 1 " + quotedSketchLocation + "\n void setup();\n #line 2 " + quotedSketchLocation + "\n void loop();\n #line 4 " + quotedSketchLocation + "\n short unsigned int testInt();\n #line 8 " + quotedSketchLocation + "\n static int8_t testInline();\n #line 12 " + quotedSketchLocation + "\n __attribute__((always_inline)) uint8_t testAttribute();\n #line 1 " + quotedSketchLocation + "\n "
381- obtained := ctx .PrototypesSection
381+ obtained := ctx .SketchSourceAfterArduinoPreprocessing
382382 // ctags based preprocessing removes "inline" but this is still OK
383383 // TODO: remove this exception when moving to a more powerful parser
384384 expected = strings .Replace (expected , "static inline int8_t testInline();" , "static int8_t testInline();" , - 1 )
@@ -387,7 +387,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) {
387387 // TODO: remove this exception when moving to a more powerful parser
388388 expected = strings .Replace (expected , "__attribute__((always_inline)) uint8_t testAttribute();" , "uint8_t testAttribute();" , - 1 )
389389 obtained = strings .Replace (obtained , "__attribute__((always_inline)) uint8_t testAttribute();" , "uint8_t testAttribute();" , - 1 )
390- require .Equal (t , expected , obtained )
390+ require .Contains (t , obtained , expected )
391391}
392392
393393func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF (t * testing.T ) {
@@ -415,7 +415,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) {
415415 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
416416
417417 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
418- require .Equal (t , "#line 1 " + quotedSketchLocation + "\n void setup();\n #line 3 " + quotedSketchLocation + "\n void loop();\n #line 15 " + quotedSketchLocation + "\n int8_t adalight();\n #line 1 " + quotedSketchLocation + "\n " , ctx . PrototypesSection )
418+ require .Contains (t , ctx . SketchSourceAfterArduinoPreprocessing , "#line 1 " + quotedSketchLocation + "\n void setup();\n #line 3 " + quotedSketchLocation + "\n void loop();\n #line 15 " + quotedSketchLocation + "\n int8_t adalight();\n #line 1 " + quotedSketchLocation + "\n " )
419419}
420420
421421func TestPrototypesAdderSketchWithUSBCON (t * testing.T ) {
@@ -448,7 +448,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) {
448448 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
449449
450450 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
451- require .Equal (t , "#line 5 " + quotedSketchLocation + "\n void ciao();\n #line 10 " + quotedSketchLocation + "\n void setup();\n #line 15 " + quotedSketchLocation + "\n void loop();\n #line 5 " + quotedSketchLocation + "\n " , ctx . PrototypesSection )
451+ require .Contains (t , ctx . SketchSourceAfterArduinoPreprocessing , "#line 5 " + quotedSketchLocation + "\n void ciao();\n #line 10 " + quotedSketchLocation + "\n void setup();\n #line 15 " + quotedSketchLocation + "\n void loop();\n #line 5 " + quotedSketchLocation + "\n " )
452452}
453453
454454func TestPrototypesAdderSketchWithTypename (t * testing.T ) {
@@ -481,12 +481,12 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) {
481481
482482 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
483483 expected := "#line 6 " + quotedSketchLocation + "\n void setup();\n #line 10 " + quotedSketchLocation + "\n void loop();\n #line 12 " + quotedSketchLocation + "\n typename Foo<char>::Bar func();\n #line 6 " + quotedSketchLocation + "\n "
484- obtained := ctx .PrototypesSection
484+ obtained := ctx .SketchSourceAfterArduinoPreprocessing
485485 // ctags based preprocessing ignores line with typename
486486 // TODO: remove this exception when moving to a more powerful parser
487487 expected = strings .Replace (expected , "#line 12 " + quotedSketchLocation + "\n typename Foo<char>::Bar func();\n " , "" , - 1 )
488488 obtained = strings .Replace (obtained , "#line 12 " + quotedSketchLocation + "\n typename Foo<char>::Bar func();\n " , "" , - 1 )
489- require .Equal (t , expected , obtained )
489+ require .Contains (t , obtained , expected )
490490}
491491
492492func TestPrototypesAdderSketchWithIfDef2 (t * testing.T ) {
@@ -514,7 +514,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) {
514514 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
515515
516516 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
517- require .Equal (t , "#line 5 " + quotedSketchLocation + "\n void elseBranch();\n #line 9 " + quotedSketchLocation + "\n void f1();\n #line 10 " + quotedSketchLocation + "\n void f2();\n #line 12 " + quotedSketchLocation + "\n void setup();\n #line 14 " + quotedSketchLocation + "\n void loop();\n #line 5 " + quotedSketchLocation + "\n " , ctx . PrototypesSection )
517+ require .Contains (t , ctx . SketchSourceAfterArduinoPreprocessing , "#line 5 " + quotedSketchLocation + "\n void elseBranch();\n #line 9 " + quotedSketchLocation + "\n void f1();\n #line 10 " + quotedSketchLocation + "\n void f2();\n #line 12 " + quotedSketchLocation + "\n void setup();\n #line 14 " + quotedSketchLocation + "\n void loop();\n #line 5 " + quotedSketchLocation + "\n " )
518518
519519 expectedSource := LoadAndInterpolate (t , filepath .Join ("sketch_with_ifdef" , "sketch.preprocessed.txt" ), ctx )
520520 require .Equal (t , expectedSource , strings .Replace (ctx .SketchSourceAfterArduinoPreprocessing , "\r \n " , "\n " , - 1 ))
@@ -545,7 +545,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) {
545545 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
546546
547547 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
548- require .Equal (t , "#line 2 " + quotedSketchLocation + "\n void ifBranch();\n #line 9 " + quotedSketchLocation + "\n void f1();\n #line 10 " + quotedSketchLocation + "\n void f2();\n #line 12 " + quotedSketchLocation + "\n void setup();\n #line 14 " + quotedSketchLocation + "\n void loop();\n #line 2 " + quotedSketchLocation + "\n " , ctx . PrototypesSection )
548+ require .Contains (t , ctx . SketchSourceAfterArduinoPreprocessing , "#line 2 " + quotedSketchLocation + "\n void ifBranch();\n #line 9 " + quotedSketchLocation + "\n void f1();\n #line 10 " + quotedSketchLocation + "\n void f2();\n #line 12 " + quotedSketchLocation + "\n void setup();\n #line 14 " + quotedSketchLocation + "\n void loop();\n #line 2 " + quotedSketchLocation + "\n " )
549549
550550 expectedSource := LoadAndInterpolate (t , filepath .Join ("sketch_with_ifdef" , "sketch.preprocessed.SAM.txt" ), ctx )
551551 require .Equal (t , expectedSource , strings .Replace (ctx .SketchSourceAfterArduinoPreprocessing , "\r \n " , "\n " , - 1 ))
@@ -576,7 +576,7 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) {
576576 NoError (t , builder .PreprocessSketchWithCtags (ctx ))
577577
578578 require .Contains (t , ctx .SketchSourceAfterArduinoPreprocessing , "#include <Arduino.h>\n #line 1 " + quotedSketchLocation + "\n " )
579- require .Equal (t , "#line 1 " + quotedSketchLocation + "\n void setup();\n #line 2 " + quotedSketchLocation + "\n void loop();\n #line 4 " + quotedSketchLocation + "\n const __FlashStringHelper* test();\n #line 6 " + quotedSketchLocation + "\n const int test3();\n #line 8 " + quotedSketchLocation + "\n volatile __FlashStringHelper* test2();\n #line 10 " + quotedSketchLocation + "\n volatile int test4();\n #line 1 " + quotedSketchLocation + "\n " , ctx . PrototypesSection )
579+ require .Contains (t , ctx . SketchSourceAfterArduinoPreprocessing , "#line 1 " + quotedSketchLocation + "\n void setup();\n #line 2 " + quotedSketchLocation + "\n void loop();\n #line 4 " + quotedSketchLocation + "\n const __FlashStringHelper* test();\n #line 6 " + quotedSketchLocation + "\n const int test3();\n #line 8 " + quotedSketchLocation + "\n volatile __FlashStringHelper* test2();\n #line 10 " + quotedSketchLocation + "\n volatile int test4();\n #line 1 " + quotedSketchLocation + "\n " )
580580}
581581
582582func TestPrototypesAdderSketchWithDosEol (t * testing.T ) {
0 commit comments