@@ -27,11 +27,9 @@ import (
27
27
"github.com/stretchr/testify/require"
28
28
)
29
29
30
- func TestCTagsRunner (t * testing.T ) {
30
+ func ctagsRunnerTestTemplate (t * testing.T , sketchLocation * paths. Path ) [] byte {
31
31
DownloadCoresAndToolsAndLibraries (t )
32
32
33
- sketchLocation := Abs (t , paths .New ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ))
34
-
35
33
ctx := & types.Context {
36
34
HardwareDirs : paths .NewPathList (filepath .Join (".." , "hardware" ), "downloaded_hardware" ),
37
35
BuiltInToolsDirs : paths .NewPathList ("downloaded_tools" ),
@@ -47,11 +45,24 @@ func TestCTagsRunner(t *testing.T) {
47
45
48
46
err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
49
47
NoError (t , err )
48
+
50
49
_ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , nil , ctx .SketchBuildPath )
51
50
NoError (t , err )
52
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
51
+
52
+ target := ctx .BuildPath .Join ("ctags_target.cpp" )
53
+ NoError (t , target .Parent ().MkdirAll ())
54
+ NoError (t , target .WriteFile ([]byte (source )))
55
+
56
+ ctagsOutput , _ , err := builder .RunCTags (target , ctx .BuildProperties )
53
57
NoError (t , err )
54
58
59
+ return ctagsOutput
60
+ }
61
+
62
+ func TestCTagsRunner (t * testing.T ) {
63
+ sketchLocation := Abs (t , paths .New ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ))
64
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
65
+
55
66
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
56
67
expectedOutput := "server " + quotedSketchLocation + " /^BridgeServer server;$/;\" kind:variable line:31\n " +
57
68
"setup " + quotedSketchLocation + " /^void setup() {$/;\" kind:function line:33 signature:() returntype:void\n " +
@@ -64,29 +75,8 @@ func TestCTagsRunner(t *testing.T) {
64
75
}
65
76
66
77
func TestCTagsRunnerSketchWithClass (t * testing.T ) {
67
- DownloadCoresAndToolsAndLibraries (t )
68
-
69
78
sketchLocation := Abs (t , paths .New ("sketch_with_class" , "sketch_with_class.ino" ))
70
-
71
- ctx := & types.Context {
72
- HardwareDirs : paths .NewPathList (filepath .Join (".." , "hardware" ), "downloaded_hardware" ),
73
- BuiltInToolsDirs : paths .NewPathList ("downloaded_tools" ),
74
- BuiltInLibrariesDirs : paths .New ("downloaded_libraries" ),
75
- OtherLibrariesDirs : paths .NewPathList ("libraries" ),
76
- Sketch : OpenSketch (t , sketchLocation ),
77
- FQBN : parseFQBN (t , "arduino:avr:leonardo" ),
78
- Verbose : true ,
79
- }
80
-
81
- buildPath := SetupBuildPath (t , ctx )
82
- defer buildPath .RemoveAll ()
83
-
84
- err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
85
- NoError (t , err )
86
- _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
87
- NoError (t , err )
88
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
89
- NoError (t , err )
79
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
90
80
91
81
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
92
82
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 " +
@@ -98,29 +88,8 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) {
98
88
}
99
89
100
90
func TestCTagsRunnerSketchWithTypename (t * testing.T ) {
101
- DownloadCoresAndToolsAndLibraries (t )
102
-
103
91
sketchLocation := Abs (t , paths .New ("sketch_with_typename" , "sketch_with_typename.ino" ))
104
-
105
- ctx := & types.Context {
106
- HardwareDirs : paths .NewPathList (filepath .Join (".." , "hardware" ), "downloaded_hardware" ),
107
- BuiltInToolsDirs : paths .NewPathList ("downloaded_tools" ),
108
- BuiltInLibrariesDirs : paths .New ("downloaded_libraries" ),
109
- OtherLibrariesDirs : paths .NewPathList ("libraries" ),
110
- Sketch : OpenSketch (t , sketchLocation ),
111
- FQBN : parseFQBN (t , "arduino:avr:leonardo" ),
112
- Verbose : true ,
113
- }
114
-
115
- buildPath := SetupBuildPath (t , ctx )
116
- defer buildPath .RemoveAll ()
117
-
118
- err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
119
- NoError (t , err )
120
- _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
121
- NoError (t , err )
122
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
123
- NoError (t , err )
92
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
124
93
125
94
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
126
95
expectedOutput := "Foo\t " + quotedSketchLocation + "\t /^ struct Foo{$/;\" \t kind:struct\t line:2\n " +
@@ -131,29 +100,8 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) {
131
100
}
132
101
133
102
func TestCTagsRunnerSketchWithNamespace (t * testing.T ) {
134
- DownloadCoresAndToolsAndLibraries (t )
135
-
136
103
sketchLocation := Abs (t , paths .New ("sketch_with_namespace" , "sketch_with_namespace.ino" ))
137
-
138
- ctx := & types.Context {
139
- HardwareDirs : paths .NewPathList (filepath .Join (".." , "hardware" ), "downloaded_hardware" ),
140
- BuiltInToolsDirs : paths .NewPathList ("downloaded_tools" ),
141
- BuiltInLibrariesDirs : paths .New ("downloaded_libraries" ),
142
- OtherLibrariesDirs : paths .NewPathList ("libraries" ),
143
- Sketch : OpenSketch (t , sketchLocation ),
144
- FQBN : parseFQBN (t , "arduino:avr:leonardo" ),
145
- Verbose : true ,
146
- }
147
-
148
- buildPath := SetupBuildPath (t , ctx )
149
- defer buildPath .RemoveAll ()
150
-
151
- err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
152
- NoError (t , err )
153
- _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
154
- NoError (t , err )
155
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
156
- NoError (t , err )
104
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
157
105
158
106
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
159
107
expectedOutput := "value\t " + quotedSketchLocation + "\t /^\t int value() {$/;\" \t kind:function\t line:2\t namespace:Test\t signature:()\t returntype:int\n " +
@@ -163,29 +111,8 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) {
163
111
}
164
112
165
113
func TestCTagsRunnerSketchWithTemplates (t * testing.T ) {
166
- DownloadCoresAndToolsAndLibraries (t )
167
-
168
114
sketchLocation := Abs (t , paths .New ("sketch_with_templates_and_shift" , "sketch_with_templates_and_shift.ino" ))
169
-
170
- ctx := & types.Context {
171
- HardwareDirs : paths .NewPathList (filepath .Join (".." , "hardware" ), "downloaded_hardware" ),
172
- BuiltInToolsDirs : paths .NewPathList ("downloaded_tools" ),
173
- BuiltInLibrariesDirs : paths .New ("downloaded_libraries" ),
174
- OtherLibrariesDirs : paths .NewPathList ("libraries" ),
175
- Sketch : OpenSketch (t , sketchLocation ),
176
- FQBN : parseFQBN (t , "arduino:avr:leonardo" ),
177
- Verbose : true ,
178
- }
179
-
180
- buildPath := SetupBuildPath (t , ctx )
181
- defer buildPath .RemoveAll ()
182
-
183
- err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
184
- NoError (t , err )
185
- _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , ctx .SourceOverride , ctx .SketchBuildPath )
186
- NoError (t , err )
187
- ctagsOutput , _ , err := builder .RunCTags (source , "ctags_target.cpp" , ctx .BuildProperties , ctx .PreprocPath )
188
- NoError (t , err )
115
+ ctagsOutput := ctagsRunnerTestTemplate (t , sketchLocation )
189
116
190
117
quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
191
118
expectedOutput := "printGyro\t " + quotedSketchLocation + "\t /^void printGyro()$/;\" \t kind:function\t line:10\t signature:()\t returntype:void\n " +
0 commit comments