Skip to content

Commit b04288f

Browse files
committed
Some preprocessing tests now expects a more proper output
The new output is still not well handled by ctags so some exceptions have been added to the tests. Those exception may be eventually removed when a more powerful parser is adopted. Signed-off-by: Cristian Maglie <[email protected]>
1 parent b64fc36 commit b04288f

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/arduino.cc/builder/test/prototypes_adder_test.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,12 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) {
370370
}
371371

372372
preprocessed := LoadAndInterpolate(t, filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"), context)
373-
require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1))
373+
obtained := strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)
374+
// ctags based preprocessing removes the space after "dostuff", but this is still OK
375+
// TODO: remove this exception when moving to a more powerful parser
376+
preprocessed = strings.Replace(preprocessed, "void dostuff (A_NEW_TYPE * bar);", "void dostuff(A_NEW_TYPE * bar);", 1)
377+
obtained = strings.Replace(obtained, "void dostuff (A_NEW_TYPE * bar);", "void dostuff(A_NEW_TYPE * bar);", 1)
378+
require.Equal(t, preprocessed, obtained)
374379
}
375380

376381
func TestPrototypesAdderSketchWithConfig(t *testing.T) {
@@ -587,7 +592,18 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) {
587592
}
588593

589594
require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
590-
require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 2 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 4 \""+absoluteSketchLocation+"\"\nshort unsigned int testInt();\n#line 8 \""+absoluteSketchLocation+"\"\nstatic int8_t testInline();\n#line 12 \""+absoluteSketchLocation+"\"\nuint8_t testAttribute();\n#line 1\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
595+
596+
expected := "#line 1 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 2 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 4 \"" + absoluteSketchLocation + "\"\nshort unsigned int testInt();\n#line 8 \"" + absoluteSketchLocation + "\"\nstatic int8_t testInline();\n#line 12 \"" + absoluteSketchLocation + "\"\n__attribute__((always_inline)) uint8_t testAttribute();\n#line 1\n"
597+
obtained := context[constants.CTX_PROTOTYPE_SECTION].(string)
598+
// ctags based preprocessing removes "inline" but this is still OK
599+
// TODO: remove this exception when moving to a more powerful parser
600+
expected = strings.Replace(expected, "static inline int8_t testInline();", "static int8_t testInline();", -1)
601+
obtained = strings.Replace(obtained, "static inline int8_t testInline();", "static int8_t testInline();", -1)
602+
// ctags based preprocessing removes "__attribute__ ....." but this is still OK
603+
// TODO: remove this exception when moving to a more powerful parser
604+
expected = strings.Replace(expected, "__attribute__((always_inline)) uint8_t testAttribute();", "uint8_t testAttribute();", -1)
605+
obtained = strings.Replace(obtained, "__attribute__((always_inline)) uint8_t testAttribute();", "uint8_t testAttribute();", -1)
606+
require.Equal(t, expected, obtained)
591607
}
592608

593609
func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) {
@@ -718,7 +734,13 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) {
718734
}
719735

720736
require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
721-
require.Equal(t, "#line 6 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 6\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
737+
expected := "#line 6 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 10 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 12 \"" + absoluteSketchLocation + "\"\ntypename Foo<char>::Bar func();\n#line 6\n"
738+
obtained := context[constants.CTX_PROTOTYPE_SECTION].(string)
739+
// ctags based preprocessing ignores line with typename
740+
// TODO: remove this exception when moving to a more powerful parser
741+
expected = strings.Replace(expected, "#line 12 \""+absoluteSketchLocation+"\"\ntypename Foo<char>::Bar func();\n", "", -1)
742+
obtained = strings.Replace(obtained, "#line 12 \""+absoluteSketchLocation+"\"\ntypename Foo<char>::Bar func();\n", "", -1)
743+
require.Equal(t, expected, obtained)
722744
}
723745

724746
func TestPrototypesAdderSketchWithIfDef2(t *testing.T) {

src/arduino.cc/builder/test/sketch8/SketchWithStruct.preprocessed.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void setup();
1414
#line 13 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
1515
void loop();
1616
#line 17 "{{EscapeBackSlashes .sketch.MainFile.Name}}"
17-
void dostuff(A_NEW_TYPE * bar);
17+
void dostuff (A_NEW_TYPE * bar);
1818
#line 9
1919
void setup() {
2020

0 commit comments

Comments
 (0)