@@ -21,24 +21,34 @@ import (
2121
2222 bldr "github.com/arduino/arduino-cli/arduino/builder"
2323 "github.com/arduino/arduino-cli/legacy/builder"
24- "github.com/arduino/arduino-cli/legacy/builder/types"
2524 paths "github.com/arduino/go-paths-helper"
2625 "github.com/stretchr/testify/require"
2726)
2827
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 {
3129 ctx := prepareBuilderTestContext (t , nil , sketchLocation , "arduino:avr:leonardo" )
3230 defer cleanUpBuilderTestContext (t , ctx )
3331 ctx .Verbose = true
3432
3533 err := (& builder.ContainerSetupHardwareToolsLibsSketchAndProps {}).Run (ctx )
3634 NoError (t , err )
35+
3736 _ , source , err := bldr .PrepareSketchBuildPath (ctx .Sketch , nil , ctx .SketchBuildPath )
3837 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 )
4043 NoError (t , err )
4144
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+
4252 quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
4353 expectedOutput := "server " + quotedSketchLocation + " /^BridgeServer server;$/;\" kind:variable line:31\n " +
4454 "setup " + quotedSketchLocation + " /^void setup() {$/;\" kind:function line:33 signature:() returntype:void\n " +
@@ -52,16 +62,7 @@ func TestCTagsRunner(t *testing.T) {
5262
5363func TestCTagsRunnerSketchWithClass (t * testing.T ) {
5464 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 )
6566
6667 quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
6768 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) {
7475
7576func TestCTagsRunnerSketchWithTypename (t * testing.T ) {
7677 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 )
8779
8880 quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
8981 expectedOutput := "Foo\t " + quotedSketchLocation + "\t /^ struct Foo{$/;\" \t kind:struct\t line:2\n " +
@@ -95,16 +87,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) {
9587
9688func TestCTagsRunnerSketchWithNamespace (t * testing.T ) {
9789 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 )
10891
10992 quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
11093 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) {
11598
11699func TestCTagsRunnerSketchWithTemplates (t * testing.T ) {
117100 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 )
128102
129103 quotedSketchLocation := strings .Replace (sketchLocation .String (), "\\ " , "\\ \\ " , - 1 )
130104 expectedOutput := "printGyro\t " + quotedSketchLocation + "\t /^void printGyro()$/;\" \t kind:function\t line:10\t signature:()\t returntype:void\n " +
0 commit comments