@@ -401,3 +401,62 @@ func TestUploadSketchWithPdeExtension(t *testing.T) {
401401 require .Contains (t , string (stderr ), "Sketches with .pde extension are deprecated, please rename the following files to .ino:" )
402402 }
403403}
404+
405+ func TestUploadWithInputDirContainingMultipleBinaries (t * testing.T ) {
406+ if os .Getenv ("CI" ) != "" {
407+ t .Skip ("VMs have no serial ports" )
408+ }
409+
410+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
411+ defer env .CleanUp ()
412+
413+ // This tests verifies the behaviour outlined in this issue:
414+ // https://github.com/arduino/arduino-cli/issues/765#issuecomment-699678646
415+ _ , _ , err := cli .Run ("update" )
416+ require .NoError (t , err )
417+
418+ // Create two different sketches
419+ sketchOneName := "UploadMultipleBinariesSketchOne"
420+ sketchOnePath := cli .SketchbookDir ().Join (sketchOneName )
421+ _ , _ , err = cli .Run ("sketch" , "new" , sketchOnePath .String ())
422+ require .NoError (t , err )
423+
424+ sketchTwoName := "UploadMultipleBinariesSketchTwo"
425+ sketchTwoPath := cli .SketchbookDir ().Join (sketchTwoName )
426+ _ , _ , err = cli .Run ("sketch" , "new" , sketchTwoPath .String ())
427+ require .NoError (t , err )
428+
429+ for _ , board := range detectedBoards (t , cli ) {
430+ // Install core
431+ _ , _ , err = cli .Run ("core" , "install" , board .core )
432+ require .NoError (t , err )
433+
434+ // Compile both sketches and copy binaries in the same build directory
435+ binariesDir := cli .SketchbookDir ().Join ("build" , "BuiltBinaries" )
436+ _ , _ , err = cli .Run ("compile" , "--clean" , "-b" , board .fqbn , sketchOnePath .String (), "--build-path" , binariesDir .String ())
437+ require .NoError (t , err )
438+ stdout , _ , err := cli .Run ("compile" , "--clean" , "-b" , board .fqbn , sketchTwoPath .String (), "--format" , "json" )
439+ require .NoError (t , err )
440+ buildDirTwo := requirejson .Parse (t , stdout ).Query (".builder_result | .build_path" ).String ()
441+ buildDirTwo = strings .Trim (strings .ReplaceAll (buildDirTwo , "\\ \\ " , "\\ " ), "\" " )
442+ require .NoError (t , paths .New (buildDirTwo ).Join (sketchTwoName + ".ino.bin" ).CopyTo (binariesDir .Join (sketchTwoName + ".ino.bin" )))
443+
444+ waitForBoard (t , cli )
445+ // Verifies upload fails because multiple binaries are found
446+ _ , stderr , err := cli .Run ("upload" , "-b" , board .fqbn , "-p" , board .address , "--input-dir" , binariesDir .String ())
447+ require .Error (t , err )
448+ require .Contains (t , string (stderr ), "Error during Upload: " )
449+ require .Contains (t , string (stderr ), "Error finding build artifacts: " )
450+ require .Contains (t , string (stderr ), "autodetect build artifact: " )
451+ require .Contains (t , string (stderr ), "multiple build artifacts found:" )
452+
453+ // Copy binaries to folder with same name of a sketch
454+ binariesDirSketch := cli .SketchbookDir ().Join ("build" , "UploadMultipleBinariesSketchOne" )
455+ require .NoError (t , binariesDir .CopyDirTo (binariesDirSketch ))
456+
457+ waitForBoard (t , cli )
458+ // Verifies upload is successful using the binaries with the same name of the containing folder
459+ _ , _ , err = cli .Run ("upload" , "-b" , board .fqbn , "-p" , board .address , "--input-dir" , binariesDirSketch .String ())
460+ require .NoError (t , err )
461+ }
462+ }
0 commit comments