@@ -20,6 +20,7 @@ import (
20
20
21
21
"github.com/arduino/arduino-cli/internal/integrationtest"
22
22
"github.com/stretchr/testify/require"
23
+ "go.bug.st/testifyjson/requirejson"
23
24
)
24
25
25
26
func TestCompileWithProfiles (t * testing.T ) {
@@ -69,3 +70,83 @@ func TestBuilderDidNotCatchLibsFromUnusedPlatforms(t *testing.T) {
69
70
require .NotContains (t , string (stdout ), "samd" )
70
71
require .NotContains (t , string (stderr ), "samd" )
71
72
}
73
+
74
+ func TestCompileWithDefaultProfile (t * testing.T ) {
75
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
76
+ defer env .CleanUp ()
77
+
78
+ // Init the environment explicitly
79
+ _ , _ , err := cli .Run ("core" , "update-index" )
80
+ require .NoError (t , err )
81
+
82
+ // Installa core/libs globally
83
+ _ ,
_ ,
err = cli .
Run (
"core" ,
"install" ,
"arduino:[email protected] " )
84
+ require .NoError (t , err )
85
+
86
+ // copy sketch_with_profile into the working directory
87
+ sketchWithoutDefProfilePath := cli .CopySketch ("sketch_without_default_profile" )
88
+ sketchWithDefProfilePath := cli .CopySketch ("sketch_with_default_profile" )
89
+
90
+ {
91
+ // no default profile -> error missing FQBN
92
+ _ , _ , err := cli .Run ("compile" , sketchWithoutDefProfilePath .String (), "--format" , "json" )
93
+ require .Error (t , err )
94
+ }
95
+ {
96
+ // specified fbqn -> compile with specified FQBN and use global installation
97
+ stdout , _ , err := cli .Run ("compile" , "-b" , "arduino:avr:nano" , sketchWithoutDefProfilePath .String (), "--format" , "json" )
98
+ require .NoError (t , err )
99
+ jsonOut := requirejson .Parse (t , stdout )
100
+ jsonOut .Query (".builder_result.build_platform" ).MustContain (`{"id":"arduino:avr", "version":"1.8.3"}` )
101
+ jsonOut .Query (".builder_result.build_properties" ).MustContain (`[ "build.fqbn=arduino:avr:nano" ]` )
102
+ }
103
+ {
104
+ // specified profile -> use the specified profile
105
+ stdout , _ , err := cli .Run ("compile" , "--profile" , "avr1" , sketchWithoutDefProfilePath .String (), "--format" , "json" )
106
+ require .NoError (t , err )
107
+ jsonOut := requirejson .Parse (t , stdout )
108
+ jsonOut .Query (".builder_result.build_platform" ).MustContain (`{"id":"arduino:avr", "version":"1.8.4"}` )
109
+ jsonOut .Query (".builder_result.build_properties" ).MustContain (`[ "build.fqbn=arduino:avr:uno" ]` )
110
+ }
111
+ {
112
+ // specified profile and fqbn -> use the specified profile and override fqbn
113
+ stdout , _ , err := cli .Run ("compile" , "--profile" , "avr1" , "-b" , "arduino:avr:nano" , sketchWithoutDefProfilePath .String (), "--format" , "json" )
114
+ require .NoError (t , err )
115
+ jsonOut := requirejson .Parse (t , stdout )
116
+ jsonOut .Query (".builder_result.build_platform" ).MustContain (`{"id":"arduino:avr", "version":"1.8.4"}` )
117
+ jsonOut .Query (".builder_result.build_properties" ).MustContain (`[ "build.fqbn=arduino:avr:nano" ]` )
118
+ }
119
+
120
+ {
121
+ // default profile -> use default profile
122
+ stdout , _ , err := cli .Run ("compile" , sketchWithDefProfilePath .String (), "--format" , "json" )
123
+ require .NoError (t , err )
124
+ jsonOut := requirejson .Parse (t , stdout )
125
+ jsonOut .Query (".builder_result.build_platform" ).MustContain (`{"id":"arduino:avr", "version":"1.8.5"}` )
126
+ jsonOut .Query (".builder_result.build_properties" ).MustContain (`[ "build.fqbn=arduino:avr:leonardo" ]` )
127
+ }
128
+ {
129
+ // default profile, specified fbqn -> use default profile, override fqbn
130
+ stdout , _ , err := cli .Run ("compile" , "-b" , "arduino:avr:nano" , sketchWithDefProfilePath .String (), "--format" , "json" )
131
+ require .NoError (t , err )
132
+ jsonOut := requirejson .Parse (t , stdout )
133
+ jsonOut .Query (".builder_result.build_platform" ).MustContain (`{"id":"arduino:avr", "version":"1.8.5"}` )
134
+ jsonOut .Query (".builder_result.build_properties" ).MustContain (`[ "build.fqbn=arduino:avr:nano" ]` )
135
+ }
136
+ {
137
+ // default profile, specified different profile -> use the specified profile
138
+ stdout , _ , err := cli .Run ("compile" , "--profile" , "avr1" , sketchWithDefProfilePath .String (), "--format" , "json" )
139
+ require .NoError (t , err )
140
+ jsonOut := requirejson .Parse (t , stdout )
141
+ jsonOut .Query (".builder_result.build_platform" ).MustContain (`{"id":"arduino:avr", "version":"1.8.4"}` )
142
+ jsonOut .Query (".builder_result.build_properties" ).MustContain (`[ "build.fqbn=arduino:avr:uno" ]` )
143
+ }
144
+ {
145
+ // default profile, specified different profile and fqbn -> use the specified profile and override fqbn
146
+ stdout , _ , err := cli .Run ("compile" , "--profile" , "avr1" , "-b" , "arduino:avr:nano" , sketchWithDefProfilePath .String (), "--format" , "json" )
147
+ require .NoError (t , err )
148
+ jsonOut := requirejson .Parse (t , stdout )
149
+ jsonOut .Query (".builder_result.build_platform" ).MustContain (`{"id":"arduino:avr", "version":"1.8.4"}` )
150
+ jsonOut .Query (".builder_result.build_properties" ).MustContain (`[ "build.fqbn=arduino:avr:nano" ]` )
151
+ }
152
+ }
0 commit comments