@@ -18,6 +18,7 @@ package compile_part_1_test
18
18
import (
19
19
"crypto/md5"
20
20
"encoding/hex"
21
+ "fmt"
21
22
"strings"
22
23
"testing"
23
24
@@ -105,3 +106,49 @@ func TestCompileWithExportBinariesFlag(t *testing.T) {
105
106
require .FileExists (t , sketchPath .Join ("build" , fqbn , sketchName + ".ino.with_bootloader.bin" ).String ())
106
107
require .FileExists (t , sketchPath .Join ("build" , fqbn , sketchName + ".ino.with_bootloader.hex" ).String ())
107
108
}
109
+
110
+ func TestCompileWithCustomBuildPath (t * testing.T ) {
111
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
112
+ defer env .CleanUp ()
113
+
114
+ // Init the environment explicitly
115
+ _ , _ , err := cli .Run ("core" , "update-index" )
116
+ require .NoError (t , err )
117
+
118
+ // Download latest AVR
119
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
120
+ require .NoError (t , err )
121
+
122
+ sketchName := "CompileWithBuildPath"
123
+ sketchPath := cli .SketchbookDir ().Join (sketchName )
124
+ fqbn := "arduino:avr:uno"
125
+
126
+ // Create a test sketch
127
+ _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
128
+ require .NoError (t , err )
129
+
130
+ // Test the --build-path flag with absolute path
131
+ buildPath := cli .DataDir ().Join ("test_dir" , "build_dir" )
132
+ _ , stderr , err := cli .Run ("compile" , "-b" , fqbn , sketchPath .String (), "--build-path" , buildPath .String ())
133
+ fmt .Print (stderr )
134
+ require .NoError (t , err )
135
+
136
+ // Verifies expected binaries have been built to build_path
137
+ require .DirExists (t , buildPath .String ())
138
+ require .FileExists (t , buildPath .Join (sketchName + ".ino.eep" ).String ())
139
+ require .FileExists (t , buildPath .Join (sketchName + ".ino.elf" ).String ())
140
+ require .FileExists (t , buildPath .Join (sketchName + ".ino.hex" ).String ())
141
+ require .FileExists (t , buildPath .Join (sketchName + ".ino.with_bootloader.bin" ).String ())
142
+ require .FileExists (t , buildPath .Join (sketchName + ".ino.with_bootloader.hex" ).String ())
143
+
144
+ // Verifies there are no binaries in temp directory
145
+ md5 := md5 .Sum (([]byte (sketchPath .String ())))
146
+ sketchPathMd5 := strings .ToUpper (hex .EncodeToString (md5 [:]))
147
+ require .NotEmpty (t , sketchPathMd5 )
148
+ buildDir := paths .TempDir ().Join ("arduino-sketch-" + sketchPathMd5 )
149
+ require .NoFileExists (t , buildDir .Join (sketchName + ".ino.eep" ).String ())
150
+ require .NoFileExists (t , buildDir .Join (sketchName + ".ino.elf" ).String ())
151
+ require .NoFileExists (t , buildDir .Join (sketchName + ".ino.hex" ).String ())
152
+ require .NoFileExists (t , buildDir .Join (sketchName + ".ino.with_bootloader.bin" ).String ())
153
+ require .NoFileExists (t , buildDir .Join (sketchName + ".ino.with_bootloader.hex" ).String ())
154
+ }
0 commit comments