@@ -21,24 +21,34 @@ import (
21
21
22
22
bldr "github.com/arduino/arduino-cli/arduino/builder"
23
23
"github.com/arduino/arduino-cli/legacy/builder"
24
- "github.com/arduino/arduino-cli/legacy/builder/types"
25
24
paths "github.com/arduino/go-paths-helper"
26
25
"github.com/stretchr/testify/require"
27
26
)
28
27
29
- func TestCTagsRunner (t * testing.T ) {
30
- sketchLocation := Abs (t , paths .New ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ))
28
+ func ctagsRunnerTestTemplate (t * testing.T , sketchLocation * paths.Path ) []byte {
31
29
ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
32
30
defer cleanUpBuilderTestContext (t , ctx )
33
31
ctx .Verbose = true
34
32
35
33
err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
36
34
NoError (t , err )
35
+
37
36
_ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , nil , ctx .SketchBuildPath )
38
37
NoError (t , err )
39
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
38
+
39
+ target := ctx .BuildPath .Join ("ctags_target.cpp" )
40
+ NoError (t , target .WriteFile ([]byte (source )))
41
+
42
+ ctagsOutput , _ , err := builder .RunCTags (target , ctx .BuildProperties )
40
43
NoError (t , err )
41
44
45
+ return ctagsOutput
46
+ }
47
+
48
+ func TestCTagsRunner (t * testing.T ) {
49
+ sketchLocation := Abs (t , paths .New ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ))
50
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
51
+
42
52
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
43
53
expectedOutput := "server " + quotedSketchLocation + " /^BridgeServer server;$/;\" kind:variable line:31\n " +
44
54
"setup " + quotedSketchLocation + " /^void setup() {$/;\" kind:function line:33 signature:() returntype:void\n " +
@@ -52,16 +62,7 @@ func TestCTagsRunner(t *testing.T) {
52
62
53
63
func TestCTagsRunnerSketchWithClass (t * testing.T ) {
54
64
sketchLocation := Abs (t , paths .New ("sketch_with_class" , "sketch_with_class.ino" ))
55
- ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
56
- defer cleanUpBuilderTestContext (t , ctx )
57
- ctx .Verbose = true
58
-
59
- err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
60
- NoError (t , err )
61
- _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
62
- NoError (t , err )
63
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
64
- NoError (t , err )
65
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
65
66
66
67
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
67
68
expectedOutput := "set_values\t " + quotedSketchLocation + "\t /^ void set_values (int,int);$/;\" \t kind:prototype\t line:4\t class:Rectangle\t signature:(int,int)\t returntype:void\n " +
@@ -74,16 +75,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) {
74
75
75
76
func TestCTagsRunnerSketchWithTypename (t * testing.T ) {
76
77
sketchLocation := Abs (t , paths .New ("sketch_with_typename" , "sketch_with_typename.ino" ))
77
- ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
78
- defer cleanUpBuilderTestContext (t , ctx )
79
- ctx .Verbose = true
80
-
81
- err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
82
- NoError (t , err )
83
- _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
84
- NoError (t , err )
85
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
86
- NoError (t , err )
78
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
87
79
88
80
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
89
81
expectedOutput := "Foo\t " + quotedSketchLocation + "\t /^ struct Foo{$/;\" \t kind:struct\t line:2\n " +
@@ -95,16 +87,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) {
95
87
96
88
func TestCTagsRunnerSketchWithNamespace (t * testing.T ) {
97
89
sketchLocation := Abs (t , paths .New ("sketch_with_namespace" , "sketch_with_namespace.ino" ))
98
- ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
99
- defer cleanUpBuilderTestContext (t , ctx )
100
- ctx .Verbose = true
101
-
102
- err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
103
- NoError (t , err )
104
- _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
105
- NoError (t , err )
106
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
107
- NoError (t , err )
90
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
108
91
109
92
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
110
93
expectedOutput := "value\t " + quotedSketchLocation + "\t /^\t int value() {$/;\" \t kind:function\t line:2\t namespace:Test\t signature:()\t returntype:int\n " +
@@ -115,16 +98,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) {
115
98
116
99
func TestCTagsRunnerSketchWithTemplates (t * testing.T ) {
117
100
sketchLocation := Abs (t , paths .New ("sketch_with_templates_and_shift" , "sketch_with_templates_and_shift.ino" ))
118
- ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
119
- defer cleanUpBuilderTestContext (t , ctx )
120
- ctx .Verbose = true
121
-
122
- err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
123
- NoError (t , err )
124
- _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
125
- NoError (t , err )
126
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
127
- NoError (t , err )
101
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
128
102
129
103
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
130
104
expectedOutput := "printGyro\t " + quotedSketchLocation + "\t /^void printGyro()$/;\" \t kind:function\t line:10\t signature:()\t returntype:void\n " +
0 commit comments