@@ -24,6 +24,7 @@ import (
2424 "time"
2525
2626 "github.com/arduino/arduino-cli/internal/integrationtest"
27+ "github.com/arduino/go-paths-helper"
2728 "github.com/stretchr/testify/require"
2829 "go.bug.st/testifyjson/requirejson"
2930)
@@ -340,3 +341,63 @@ func TestCompileAndUploadComboSketchWithPdeExtension(t *testing.T) {
340341 require .Contains (t , string (stderr ), sketchFile .String ())
341342 }
342343}
344+
345+ func TestUploadSketchWithPdeExtension (t * testing.T ) {
346+ if os .Getenv ("CI" ) != "" {
347+ t .Skip ("VMs have no serial ports" )
348+ }
349+
350+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
351+ defer env .CleanUp ()
352+
353+ _ , _ , err := cli .Run ("update" )
354+ require .NoError (t , err )
355+
356+ sketchName := "UploadPdeSketch"
357+ sketchPath := cli .SketchbookDir ().Join (sketchName )
358+
359+ // Create a test sketch
360+ _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
361+ require .NoError (t , err )
362+
363+ // Renames sketch file to pde
364+ sketchFile := sketchPath .Join (sketchName + ".pde" )
365+ require .NoError (t , sketchPath .Join (sketchName + ".ino" ).Rename (sketchFile ))
366+
367+ for _ , board := range detectedBoards (t , cli ) {
368+ // Install core
369+ _ , _ , err = cli .Run ("core" , "install" , board .core )
370+ require .NoError (t , err )
371+
372+ // Compile sketch first
373+ stdout , _ , err := cli .Run ("compile" , "--clean" , "-b" , board .fqbn , sketchPath .String (), "--format" , "json" )
374+ require .NoError (t , err )
375+ buildDir := requirejson .Parse (t , stdout ).Query (".builder_result | .build_path" ).String ()
376+ buildDir = strings .Trim (strings .ReplaceAll (buildDir , "\\ \\ " , "\\ " ), "\" " )
377+
378+ // Upload from sketch folder
379+ waitForBoard (t , cli )
380+ _ , _ , err = cli .Run ("upload" , "-b" , board .fqbn , "-p" , board .address , sketchPath .String ())
381+ require .NoError (t , err )
382+
383+ // Upload from sketch file
384+ waitForBoard (t , cli )
385+ _ , _ , err = cli .Run ("upload" , "-b" , board .fqbn , "-p" , board .address , sketchFile .String ())
386+ require .NoError (t , err )
387+
388+ waitForBoard (t , cli )
389+ _ , stderr , err := cli .Run ("upload" , "-b" , board .fqbn , "-p" , board .address , "--input-dir" , buildDir )
390+ require .NoError (t , err )
391+ require .Contains (t , string (stderr ), "Sketches with .pde extension are deprecated, please rename the following files to .ino:" )
392+
393+ // Upload from binary file
394+ waitForBoard (t , cli )
395+ // We don't need a specific file when using the --input-file flag to upload since
396+ // it's just used to calculate the directory, so it's enough to get a random file
397+ // that's inside that directory
398+ binaryFile := paths .New (buildDir , sketchName + ".pde.bin" )
399+ _ , stderr , err = cli .Run ("upload" , "-b" , board .fqbn , "-p" , board .address , "--input-file" , binaryFile .String ())
400+ require .NoError (t , err )
401+ require .Contains (t , string (stderr ), "Sketches with .pde extension are deprecated, please rename the following files to .ino:" )
402+ }
403+ }
0 commit comments