From 2e35aa96043dccc42fcb4ae47ebc84564a090333 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 17 Sep 2018 12:47:56 +0200 Subject: [PATCH 1/2] Add test for #292 --- test/prototypes_adder_test.go | 51 +++++++++++++++++-- ...sketch_with_class_and_method_substring.ino | 13 +++++ 2 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 test/sketch_with_class_and_method_substring/sketch_with_class_and_method_substring.ino diff --git a/test/prototypes_adder_test.go b/test/prototypes_adder_test.go index 7c281461..04d5481a 100644 --- a/test/prototypes_adder_test.go +++ b/test/prototypes_adder_test.go @@ -31,14 +31,15 @@ package test import ( - "github.com/arduino/arduino-builder" - "github.com/arduino/arduino-builder/types" - "github.com/arduino/arduino-builder/utils" - "github.com/stretchr/testify/require" "os" "path/filepath" "strings" "testing" + + "github.com/arduino/arduino-builder" + "github.com/arduino/arduino-builder/types" + "github.com/arduino/arduino-builder/utils" + "github.com/stretchr/testify/require" ) func TestPrototypesAdderBridgeExample(t *testing.T) { @@ -906,3 +907,45 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { } // only requires no error as result } + +func TestPrototypesAdderSketchWithSubstringFunctionMember(t *testing.T) { + DownloadCoresAndToolsAndLibraries(t) + + sketchLocation := filepath.Join("sketch_with_class_and_method_substring", "sketch_with_class_and_method_substring.ino") + quotedSketchLocation := utils.QuoteCppString(Abs(t, sketchLocation)) + + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + Verbose: true, + } + + buildPath := SetupBuildPath(t, ctx) + defer os.RemoveAll(buildPath) + + commands := []types.Command{ + + &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, + + &builder.ContainerMergeCopySketchFiles{}, + + &builder.ContainerFindIncludes{}, + + &builder.PrintUsedLibrariesIfVerbose{}, + &builder.WarnAboutArchIncompatibleLibraries{}, + + &builder.ContainerAddPrototypes{}, + } + + for _, command := range commands { + err := command.Run(ctx) + NoError(t, err) + } + + require.Contains(t, ctx.Source, "class Foo {\nint blooper(int x) { return x+1; }\n};\n\nFoo foo;\n\n#line 7 "+quotedSketchLocation+"\nvoid setup();") +} diff --git a/test/sketch_with_class_and_method_substring/sketch_with_class_and_method_substring.ino b/test/sketch_with_class_and_method_substring/sketch_with_class_and_method_substring.ino new file mode 100644 index 00000000..d933816a --- /dev/null +++ b/test/sketch_with_class_and_method_substring/sketch_with_class_and_method_substring.ino @@ -0,0 +1,13 @@ +class Foo { +int blooper(int x) { return x+1; } +}; + +Foo foo; + +void setup() { + foo.setup(); +} + +void loop() { + foo.loop(); +} From 491a06767ebe5d0b03b9ddf0485de565e00a976f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 17 Sep 2018 12:48:34 +0200 Subject: [PATCH 2/2] Use simpler way to find if an occurrence is a callback --- ctags/ctags_to_prototypes.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ctags/ctags_to_prototypes.go b/ctags/ctags_to_prototypes.go index 7117c3f1..4492704a 100644 --- a/ctags/ctags_to_prototypes.go +++ b/ctags/ctags_to_prototypes.go @@ -72,8 +72,7 @@ func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionTags []*types. if tag.Line != functionTag.Line && strings.Index(tag.Code, "&"+functionTag.FunctionName) != -1 { return true } - if tag.Line != functionTag.Line && strings.Index(tag.Code, functionTag.FunctionName) != -1 && - (functionTag.Signature == "(void)" || functionTag.Signature == "()") { + if tag.Line != functionTag.Line && strings.Index(strings.TrimSpace(tag.Code), "("+functionTag.FunctionName+")") != -1 { return true } }