@@ -20,35 +20,35 @@ import (
20
20
"testing"
21
21
22
22
bldr "github.com/arduino/arduino-cli/arduino/builder"
23
+ "github.com/arduino/arduino-cli/arduino/builder/preprocessor"
23
24
"github.com/arduino/arduino-cli/legacy/builder"
24
- "github.com/arduino/arduino-cli/legacy/builder/types"
25
25
paths "github.com/arduino/go-paths-helper"
26
26
"github.com/stretchr/testify/require"
27
27
)
28
28
29
- func TestCTagsRunner (t * testing.T ) {
30
- sketchLocation := Abs (t , paths .New ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ))
29
+ func ctagsRunnerTestTemplate (t * testing.T , sketchLocation * paths.Path ) []byte {
31
30
ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
32
31
defer cleanUpBuilderTestContext (t , ctx )
33
32
ctx .Verbose = true
34
33
35
- ctagsRunner := & builder.CTagsRunner {Source : & ctx .SketchSourceMerged , TargetFileName : "ctags_target.cpp" }
36
- var _err error
37
- commands := []types.Command {
38
- & builder.ContainerSetupHardwareToolsLibsSketchAndProps {},
39
- types .BareCommand (func (ctx * types.Context ) error {
40
- ctx .LineOffset , ctx .SketchSourceMerged , _err = bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
41
- return _err
42
- }),
43
- & builder.ContainerFindIncludes {},
44
- & builder.PrintUsedLibrariesIfVerbose {},
45
- & builder.WarnAboutArchIncompatibleLibraries {},
46
- ctagsRunner ,
47
- }
48
- for _ , command := range commands {
49
- err := command .Run (ctx )
50
- NoError (t , err )
51
- }
34
+ err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
35
+ NoError (t , err )
36
+
37
+ _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , nil , ctx .SketchBuildPath )
38
+ NoError (t , err )
39
+
40
+ target := ctx .BuildPath .Join ("ctags_target.cpp" )
41
+ NoError (t , target .WriteFile ([]byte (source )))
42
+
43
+ ctagsOutput , _ , err := preprocessor .RunCTags (target , ctx .BuildProperties )
44
+ NoError (t , err )
45
+
46
+ return ctagsOutput
47
+ }
48
+
49
+ func TestCTagsRunner (t * testing.T ) {
50
+ sketchLocation := Abs (t , paths .New ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ))
51
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
52
52
53
53
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
54
54
expectedOutput := "server " + quotedSketchLocation + " /^BridgeServer server;$/;\" kind:variable line:31\n " +
@@ -58,133 +58,53 @@ func TestCTagsRunner(t *testing.T) {
58
58
"digitalCommand " + quotedSketchLocation + " /^void digitalCommand(BridgeClient client) {$/;\" kind:function line:82 signature:(BridgeClient client) returntype:void\n " +
59
59
"analogCommand " + quotedSketchLocation + " /^void analogCommand(BridgeClient client) {$/;\" kind:function line:109 signature:(BridgeClient client) returntype:void\n " +
60
60
"modeCommand " + quotedSketchLocation + " /^void modeCommand(BridgeClient client) {$/;\" kind:function line:149 signature:(BridgeClient client) returntype:void\n "
61
- require .Equal (t , expectedOutput , strings .Replace (string (ctagsRunner . CtagsOutput ), "\r \n " , "\n " , - 1 ))
61
+ require .Equal (t , expectedOutput , strings .Replace (string (ctagsOutput ), "\r \n " , "\n " , - 1 ))
62
62
}
63
63
64
64
func TestCTagsRunnerSketchWithClass (t * testing.T ) {
65
65
sketchLocation := Abs (t , paths .New ("sketch_with_class" , "sketch_with_class.ino" ))
66
- ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
67
- defer cleanUpBuilderTestContext (t , ctx )
68
- ctx .Verbose = true
69
-
70
- ctagsRunner := & builder.CTagsRunner {Source : & ctx .SketchSourceMerged , TargetFileName : "ctags_target.cpp" }
71
- var _err error
72
- commands := []types.Command {
73
- & builder.ContainerSetupHardwareToolsLibsSketchAndProps {},
74
- types .BareCommand (func (ctx * types.Context ) error {
75
- ctx .LineOffset , ctx .SketchSourceMerged , _err = bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
76
- return _err
77
- }),
78
- & builder.ContainerFindIncludes {},
79
- & builder.PrintUsedLibrariesIfVerbose {},
80
- & builder.WarnAboutArchIncompatibleLibraries {},
81
- ctagsRunner ,
82
- }
83
- for _ , command := range commands {
84
- err := command .Run (ctx )
85
- NoError (t , err )
86
- }
66
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
87
67
88
68
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
89
69
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 " +
90
70
"area\t " + quotedSketchLocation + "\t /^ int area() {return width*height;}$/;\" \t kind:function\t line:5\t class:Rectangle\t signature:()\t returntype:int\n " +
91
71
"set_values\t " + quotedSketchLocation + "\t /^void Rectangle::set_values (int x, int y) {$/;\" \t kind:function\t line:8\t class:Rectangle\t signature:(int x, int y)\t returntype:void\n " +
92
72
"setup\t " + quotedSketchLocation + "\t /^void setup() {$/;\" \t kind:function\t line:13\t signature:()\t returntype:void\n " +
93
73
"loop\t " + quotedSketchLocation + "\t /^void loop() {$/;\" \t kind:function\t line:17\t signature:()\t returntype:void\n "
94
- require .Equal (t , expectedOutput , strings .Replace (string (ctagsRunner . CtagsOutput ), "\r \n " , "\n " , - 1 ))
74
+ require .Equal (t , expectedOutput , strings .Replace (string (ctagsOutput ), "\r \n " , "\n " , - 1 ))
95
75
}
96
76
97
77
func TestCTagsRunnerSketchWithTypename (t * testing.T ) {
98
78
sketchLocation := Abs (t , paths .New ("sketch_with_typename" , "sketch_with_typename.ino" ))
99
- ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
100
- defer cleanUpBuilderTestContext (t , ctx )
101
- ctx .Verbose = true
102
-
103
- ctagsRunner := & builder.CTagsRunner {Source : & ctx .SketchSourceMerged , TargetFileName : "ctags_target.cpp" }
104
- var _err error
105
- commands := []types.Command {
106
- & builder.ContainerSetupHardwareToolsLibsSketchAndProps {},
107
- types .BareCommand (func (ctx * types.Context ) error {
108
- ctx .LineOffset , ctx .SketchSourceMerged , _err = bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
109
- return _err
110
- }),
111
- & builder.ContainerFindIncludes {},
112
- & builder.PrintUsedLibrariesIfVerbose {},
113
- & builder.WarnAboutArchIncompatibleLibraries {},
114
- ctagsRunner ,
115
- }
116
- for _ , command := range commands {
117
- err := command .Run (ctx )
118
- NoError (t , err )
119
- }
79
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
120
80
121
81
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
122
82
expectedOutput := "Foo\t " + quotedSketchLocation + "\t /^ struct Foo{$/;\" \t kind:struct\t line:2\n " +
123
83
"setup\t " + quotedSketchLocation + "\t /^void setup() {$/;\" \t kind:function\t line:6\t signature:()\t returntype:void\n " +
124
84
"loop\t " + quotedSketchLocation + "\t /^void loop() {}$/;\" \t kind:function\t line:10\t signature:()\t returntype:void\n " +
125
85
"func\t " + quotedSketchLocation + "\t /^typename Foo<char>::Bar func(){$/;\" \t kind:function\t line:12\t signature:()\t returntype:Foo::Bar\n "
126
- require .Equal (t , expectedOutput , strings .Replace (string (ctagsRunner . CtagsOutput ), "\r \n " , "\n " , - 1 ))
86
+ require .Equal (t , expectedOutput , strings .Replace (string (ctagsOutput ), "\r \n " , "\n " , - 1 ))
127
87
}
128
88
129
89
func TestCTagsRunnerSketchWithNamespace (t * testing.T ) {
130
90
sketchLocation := Abs (t , paths .New ("sketch_with_namespace" , "sketch_with_namespace.ino" ))
131
- ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
132
- defer cleanUpBuilderTestContext (t , ctx )
133
- ctx .Verbose = true
134
-
135
- ctagsRunner := & builder.CTagsRunner {Source : & ctx .SketchSourceMerged , TargetFileName : "ctags_target.cpp" }
136
- var _err error
137
- commands := []types.Command {
138
- & builder.ContainerSetupHardwareToolsLibsSketchAndProps {},
139
- types .BareCommand (func (ctx * types.Context ) error {
140
- ctx .LineOffset , ctx .SketchSourceMerged , _err = bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
141
- return _err
142
- }),
143
- & builder.ContainerFindIncludes {},
144
- & builder.PrintUsedLibrariesIfVerbose {},
145
- & builder.WarnAboutArchIncompatibleLibraries {},
146
- ctagsRunner ,
147
- }
148
- for _ , command := range commands {
149
- err := command .Run (ctx )
150
- NoError (t , err )
151
- }
91
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
152
92
153
93
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
154
94
expectedOutput := "value\t " + quotedSketchLocation + "\t /^\t int value() {$/;\" \t kind:function\t line:2\t namespace:Test\t signature:()\t returntype:int\n " +
155
95
"setup\t " + quotedSketchLocation + "\t /^void setup() {}$/;\" \t kind:function\t line:7\t signature:()\t returntype:void\n " +
156
96
"loop\t " + quotedSketchLocation + "\t /^void loop() {}$/;\" \t kind:function\t line:8\t signature:()\t returntype:void\n "
157
- require .Equal (t , expectedOutput , strings .Replace (string (ctagsRunner . CtagsOutput ), "\r \n " , "\n " , - 1 ))
97
+ require .Equal (t , expectedOutput , strings .Replace (string (ctagsOutput ), "\r \n " , "\n " , - 1 ))
158
98
}
159
99
160
100
func TestCTagsRunnerSketchWithTemplates (t * testing.T ) {
161
101
sketchLocation := Abs (t , paths .New ("sketch_with_templates_and_shift" , "sketch_with_templates_and_shift.ino" ))
162
- ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
163
- defer cleanUpBuilderTestContext (t , ctx )
164
- ctx .Verbose = true
165
-
166
- ctagsRunner := & builder.CTagsRunner {Source : & ctx .SketchSourceMerged , TargetFileName : "ctags_target.cpp" }
167
- var _err error
168
- commands := []types.Command {
169
- & builder.ContainerSetupHardwareToolsLibsSketchAndProps {},
170
- types .BareCommand (func (ctx * types.Context ) error {
171
- ctx .LineOffset , ctx .SketchSourceMerged , _err = bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
172
- return _err
173
- }),
174
- & builder.ContainerFindIncludes {},
175
- & builder.PrintUsedLibrariesIfVerbose {},
176
- & builder.WarnAboutArchIncompatibleLibraries {},
177
- ctagsRunner ,
178
- }
179
- for _ , command := range commands {
180
- err := command .Run (ctx )
181
- NoError (t , err )
182
- }
102
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
183
103
184
104
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
185
105
expectedOutput := "printGyro\t " + quotedSketchLocation + "\t /^void printGyro()$/;\" \t kind:function\t line:10\t signature:()\t returntype:void\n " +
186
106
"bVar\t " + quotedSketchLocation + "\t /^c< 8 > bVar;$/;\" \t kind:variable\t line:15\n " +
187
107
"aVar\t " + quotedSketchLocation + "\t /^c< 1<<8 > aVar;$/;\" \t kind:variable\t line:16\n " +
188
108
"func\t " + quotedSketchLocation + "\t /^template<int X> func( c< 1<<X> & aParam) {$/;\" \t kind:function\t line:18\t signature:( c< 1<<X> & aParam)\t returntype:template\n "
189
- require .Equal (t , expectedOutput , strings .Replace (string (ctagsRunner . CtagsOutput ), "\r \n " , "\n " , - 1 ))
109
+ require .Equal (t , expectedOutput , strings .Replace (string (ctagsOutput ), "\r \n " , "\n " , - 1 ))
190
110
}
0 commit comments