@@ -166,8 +166,90 @@ func makeTempSketchbookDir(t *testing.T) func() {
166
166
}
167
167
}
168
168
169
+ func setSketchbookDir (t * testing.T , tmp * paths.Path ) func () {
170
+ os .Setenv ("ARDUINO_SKETCHBOOK_DIR" , tmp .String ())
171
+ currSketchbookDir = tmp
172
+
173
+ fmt .Printf ("ARDUINO_SKETCHBOOK_DIR = %s\n " , os .Getenv ("ARDUINO_SKETCHBOOK_DIR" ))
174
+ return func () {
175
+ os .Unsetenv ("ARDUINO_SKETCHBOOK_DIR" )
176
+ currSketchbookDir = nil
177
+ fmt .Printf ("ARDUINO_SKETCHBOOK_DIR = %s\n " , os .Getenv ("ARDUINO_SKETCHBOOK_DIR" ))
178
+ }
179
+ }
180
+
169
181
// END -- Utility functions
170
182
183
+ func TestUploadCommands (t * testing.T ) {
184
+ defer makeTempDataDir (t )()
185
+ defer useSharedDownloadDir (t )()
186
+ defer setSketchbookDir (t , paths .New ("testdata" , "sketchbook_with_custom_hardware" ))()
187
+
188
+ updateCoreIndex (t )
189
+
190
+ exitCode , _ := executeWithArgs (t , "core" , "install" , "arduino:avr" )
191
+ require .Zero (t , exitCode , "exit code" )
192
+
193
+ // -i flag
194
+ exitCode , d := executeWithArgs (t , "upload" , "-i" , currSketchbookDir .Join ("test.hex" ).String (), "-b" , "test:avr:testboard" , "-p" , "/dev/ttyACM0" )
195
+ require .Zero (t , exitCode , "exit code" )
196
+ require .Contains (t , string (d ), "QUIET" )
197
+ require .Contains (t , string (d ), "NOVERIFY" )
198
+ require .Contains (t , string (d ), "testdata/sketchbook_with_custom_hardware/test.hex" )
199
+
200
+ // -i flag with implicit extension
201
+ exitCode , d = executeWithArgs (t , "upload" , "-i" , currSketchbookDir .Join ("test" ).String (), "-b" , "test:avr:testboard" , "-p" , "/dev/ttyACM0" )
202
+ require .Zero (t , exitCode , "exit code" )
203
+ require .Contains (t , string (d ), "QUIET" )
204
+ require .Contains (t , string (d ), "NOVERIFY" )
205
+ require .Contains (t , string (d ), "testdata/sketchbook_with_custom_hardware/test.hex" )
206
+
207
+ // -i with absolute path
208
+ fullPath , err := currSketchbookDir .Join ("test.hex" ).Abs ()
209
+ require .NoError (t , err , "absolute path of test.hex" )
210
+ exitCode , d = executeWithArgs (t , "upload" , "-i" , fullPath .String (), "-b" , "test:avr:testboard" , "-p" , "/dev/ttyACM0" )
211
+ require .Zero (t , exitCode , "exit code" )
212
+ require .Contains (t , string (d ), "QUIET" )
213
+ require .Contains (t , string (d ), "NOVERIFY" )
214
+ require .Contains (t , string (d ), "testdata/sketchbook_with_custom_hardware/test.hex" )
215
+
216
+ // -v verbose
217
+ exitCode , d = executeWithArgs (t , "upload" , "-v" , "-i" , currSketchbookDir .Join ("test.hex" ).String (), "-b" , "test:avr:testboard" , "-p" , "/dev/ttyACM0" )
218
+ require .Zero (t , exitCode , "exit code" )
219
+ require .Contains (t , string (d ), "VERBOSE" )
220
+ require .Contains (t , string (d ), "NOVERIFY" )
221
+ require .Contains (t , string (d ), "testdata/sketchbook_with_custom_hardware/test.hex" )
222
+
223
+ // -t verify
224
+ exitCode , d = executeWithArgs (t , "upload" , "-t" , "-i" , currSketchbookDir .Join ("test.hex" ).String (), "-b" , "test:avr:testboard" , "-p" , "/dev/ttyACM0" )
225
+ require .Zero (t , exitCode , "exit code" )
226
+ require .Contains (t , string (d ), "QUIET" )
227
+ require .Contains (t , string (d ), "VERIFY" )
228
+ require .Contains (t , string (d ), "testdata/sketchbook_with_custom_hardware/test.hex" )
229
+
230
+ // -v -t verbose verify
231
+ exitCode , d = executeWithArgs (t , "upload" , "-v" , "-t" , "-i" , currSketchbookDir .Join ("test.hex" ).String (), "-b" , "test:avr:testboard" , "-p" , "/dev/ttyACM0" )
232
+ require .Zero (t , exitCode , "exit code" )
233
+ require .Contains (t , string (d ), "VERBOSE" )
234
+ require .Contains (t , string (d ), "VERIFY" )
235
+ require .Contains (t , string (d ), "testdata/sketchbook_with_custom_hardware/test.hex" )
236
+
237
+ // non-existent file
238
+ exitCode , d = executeWithArgs (t , "upload" , "-i" , currSketchbookDir .Join ("test123.hex" ).String (), "-b" , "test:avr:testboard" , "-p" , "/dev/ttyACM0" )
239
+ require .NotZero (t , exitCode , "exit code" )
240
+
241
+ // sketch
242
+ exitCode , d = executeWithArgs (t , "upload" , currSketchbookDir .Join ("TestSketch" ).String (), "-b" , "test:avr:testboard" , "-p" , "/dev/ttyACM0" )
243
+ require .Zero (t , exitCode , "exit code" )
244
+ require .Contains (t , string (d ), "QUIET" )
245
+ require .Contains (t , string (d ), "NOVERIFY" )
246
+ require .Contains (t , string (d ), "testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex" )
247
+
248
+ // sketch without build
249
+ exitCode , d = executeWithArgs (t , "upload" , currSketchbookDir .Join ("TestSketch2" ).String (), "-b" , "test:avr:testboard" , "-p" , "/dev/ttyACM0" )
250
+ require .NotZero (t , exitCode , "exit code" )
251
+ }
252
+
171
253
func TestLibSearch (t * testing.T ) {
172
254
defer makeTempDataDir (t )()
173
255
defer makeTempSketchbookDir (t )()
0 commit comments