13
13
// Arduino software without disclosing the source code of your own applications.
14
14
// To purchase a commercial license, send an email to license@arduino.cc.
15
15
16
- package upload
16
+ package commands
17
17
18
18
import (
19
19
"bytes"
@@ -32,23 +32,23 @@ import (
32
32
)
33
33
34
34
func TestDetectSketchNameFromBuildPath (t * testing.T ) {
35
- sk1 , err1 := detectSketchNameFromBuildPath (paths .New ("testdata/build_path_1" ))
35
+ sk1 , err1 := detectSketchNameFromBuildPath (paths .New ("testdata/upload/ build_path_1" ))
36
36
require .NoError (t , err1 )
37
37
require .Equal (t , "sketch.ino" , sk1 )
38
38
39
- sk2 , err2 := detectSketchNameFromBuildPath (paths .New ("testdata/build_path_2" ))
39
+ sk2 , err2 := detectSketchNameFromBuildPath (paths .New ("testdata/upload/ build_path_2" ))
40
40
require .NoError (t , err2 )
41
41
require .Equal (t , "Blink.ino" , sk2 )
42
42
43
- sk3 , err3 := detectSketchNameFromBuildPath (paths .New ("testdata/build_path_3" ))
43
+ sk3 , err3 := detectSketchNameFromBuildPath (paths .New ("testdata/upload/ build_path_3" ))
44
44
require .Error (t , err3 )
45
45
require .Equal (t , "" , sk3 )
46
46
47
- sk4 , err4 := detectSketchNameFromBuildPath (paths .New ("testdata/build_path_4" ))
47
+ sk4 , err4 := detectSketchNameFromBuildPath (paths .New ("testdata/upload/ build_path_4" ))
48
48
require .Error (t , err4 )
49
49
require .Equal (t , "" , sk4 )
50
50
51
- sk5 , err5 := detectSketchNameFromBuildPath (paths .New ("testdata/build_path_invalid" ))
51
+ sk5 , err5 := detectSketchNameFromBuildPath (paths .New ("testdata/upload/ build_path_invalid" ))
52
52
require .Error (t , err5 )
53
53
require .Equal (t , "" , sk5 )
54
54
}
@@ -63,7 +63,7 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
63
63
resSketchName string
64
64
}
65
65
66
- blonk , err := sketch .New (paths .New ("testdata/Blonk" ))
66
+ blonk , err := sketch .New (paths .New ("testdata/upload/ Blonk" ))
67
67
require .NoError (t , err )
68
68
69
69
fqbn , err := cores .ParseFQBN ("arduino:samd:mkr1000" )
@@ -73,39 +73,39 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
73
73
// 00: error: no data passed in
74
74
{"" , "" , nil , nil , "<nil>" , "" },
75
75
// 01: use importFile to detect build.path and project_name
76
- {"testdata/build_path_2/Blink.ino.hex" , "" , nil , nil , "testdata/build_path_2" , "Blink.ino" },
76
+ {"testdata/upload/ build_path_2/Blink.ino.hex" , "" , nil , nil , "testdata/upload /build_path_2" , "Blink.ino" },
77
77
// 02: use importPath as build.path and project_name
78
- {"" , "testdata/build_path_2" , nil , nil , "testdata/build_path_2" , "Blink.ino" },
78
+ {"" , "testdata/upload/ build_path_2" , nil , nil , "testdata/upload /build_path_2" , "Blink.ino" },
79
79
// 03: error: used both importPath and importFile
80
- {"testdata/build_path_2/Blink.ino.hex" , "testdata/build_path_2" , nil , nil , "<nil>" , "" },
80
+ {"testdata/upload/ build_path_2/Blink.ino.hex" , "testdata/upload /build_path_2" , nil , nil , "<nil>" , "" },
81
81
// 04: only sketch without FQBN
82
82
{"" , "" , blonk , nil , blonk .DefaultBuildPath ().String (), "Blonk.ino" },
83
83
// 05: use importFile to detect build.path and project_name, sketch is ignored.
84
- {"testdata/build_path_2/Blink.ino.hex" , "" , blonk , nil , "testdata/build_path_2" , "Blink.ino" },
84
+ {"testdata/upload/ build_path_2/Blink.ino.hex" , "" , blonk , nil , "testdata/upload /build_path_2" , "Blink.ino" },
85
85
// 06: use importPath as build.path and Blink as project name, ignore the sketch Blonk
86
- {"" , "testdata/build_path_2" , blonk , nil , "testdata/build_path_2" , "Blink.ino" },
86
+ {"" , "testdata/upload/ build_path_2" , blonk , nil , "testdata/upload /build_path_2" , "Blink.ino" },
87
87
// 07: error: used both importPath and importFile
88
- {"testdata/build_path_2/Blink.ino.hex" , "testdata/build_path_2" , blonk , nil , "<nil>" , "" },
88
+ {"testdata/upload/ build_path_2/Blink.ino.hex" , "testdata/upload /build_path_2" , blonk , nil , "<nil>" , "" },
89
89
// 08: error: no data passed in
90
90
{"" , "" , nil , fqbn , "<nil>" , "" },
91
91
// 09: use importFile to detect build.path and project_name, fqbn ignored
92
- {"testdata/build_path_2/Blink.ino.hex" , "" , nil , fqbn , "testdata/build_path_2" , "Blink.ino" },
92
+ {"testdata/upload/ build_path_2/Blink.ino.hex" , "" , nil , fqbn , "testdata/upload /build_path_2" , "Blink.ino" },
93
93
// 10: use importPath as build.path and project_name, fqbn ignored
94
- {"" , "testdata/build_path_2" , nil , fqbn , "testdata/build_path_2" , "Blink.ino" },
94
+ {"" , "testdata/upload/ build_path_2" , nil , fqbn , "testdata/upload /build_path_2" , "Blink.ino" },
95
95
// 11: error: used both importPath and importFile
96
- {"testdata/build_path_2/Blink.ino.hex" , "testdata/build_path_2" , nil , fqbn , "<nil>" , "" },
96
+ {"testdata/upload/ build_path_2/Blink.ino.hex" , "testdata/upload /build_path_2" , nil , fqbn , "<nil>" , "" },
97
97
// 12: use sketch to determine project name and sketch+fqbn to determine build path
98
98
{"" , "" , blonk , fqbn , blonk .DefaultBuildPath ().String (), "Blonk.ino" },
99
99
// 13: use importFile to detect build.path and project_name, sketch+fqbn is ignored.
100
- {"testdata/build_path_2/Blink.ino.hex" , "" , blonk , fqbn , "testdata/build_path_2" , "Blink.ino" },
100
+ {"testdata/upload/ build_path_2/Blink.ino.hex" , "" , blonk , fqbn , "testdata/upload /build_path_2" , "Blink.ino" },
101
101
// 14: use importPath as build.path and Blink as project name, ignore the sketch Blonk, ignore fqbn
102
- {"" , "testdata/build_path_2" , blonk , fqbn , "testdata/build_path_2" , "Blink.ino" },
102
+ {"" , "testdata/upload/ build_path_2" , blonk , fqbn , "testdata/upload /build_path_2" , "Blink.ino" },
103
103
// 15: error: used both importPath and importFile
104
- {"testdata/build_path_2/Blink.ino.hex" , "testdata/build_path_2" , blonk , fqbn , "<nil>" , "" },
104
+ {"testdata/upload/ build_path_2/Blink.ino.hex" , "testdata/upload /build_path_2" , blonk , fqbn , "<nil>" , "" },
105
105
// 16: importPath containing multiple firmwares, but one has the same name as the containing folder
106
- {"" , "testdata/firmware" , nil , fqbn , "testdata/firmware" , "firmware.ino" },
106
+ {"" , "testdata/upload/ firmware" , nil , fqbn , "testdata/upload /firmware" , "firmware.ino" },
107
107
// 17: importFile among multiple firmwares
108
- {"testdata/firmware/another_firmware.ino.bin" , "" , nil , fqbn , "testdata/firmware" , "another_firmware.ino" },
108
+ {"testdata/upload/ firmware/another_firmware.ino.bin" , "" , nil , fqbn , "testdata/upload /firmware" , "another_firmware.ino" },
109
109
}
110
110
for i , test := range tests {
111
111
t .Run (fmt .Sprintf ("SubTest%02d" , i ), func (t * testing.T ) {
@@ -128,9 +128,9 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
128
128
129
129
func TestUploadPropertiesComposition (t * testing.T ) {
130
130
pmb := packagemanager .NewBuilder (nil , nil , nil , nil , "test" )
131
- errs := pmb .LoadHardwareFromDirectory (paths .New ("testdata" , "hardware" ))
131
+ errs := pmb .LoadHardwareFromDirectory (paths .New ("testdata" , "upload" , " hardware" ))
132
132
require .Len (t , errs , 0 )
133
- buildPath1 := paths .New ("testdata" , "build_path_1" )
133
+ buildPath1 := paths .New ("testdata" , "upload" , " build_path_1" )
134
134
logrus .SetLevel (logrus .TraceLevel )
135
135
type test struct {
136
136
importDir * paths.Path
@@ -149,32 +149,32 @@ func TestUploadPropertiesComposition(t *testing.T) {
149
149
150
150
tests := []test {
151
151
// 0: classic upload, requires port
152
- {buildPath1 , "alice:avr:board1" , "port" , "serial" , "" , false , "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol port -bspeed testdata/build_path_1/sketch.ino.hex\n " , "" },
152
+ {buildPath1 , "alice:avr:board1" , "port" , "serial" , "" , false , "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol port -bspeed testdata/upload/ build_path_1/sketch.ino.hex\n " , "" },
153
153
{buildPath1 , "alice:avr:board1" , "" , "" , "" , false , "FAIL" , "" },
154
154
// 2: classic upload, no port
155
- {buildPath1 , "alice:avr:board2" , "port" , "serial" , "" , false , "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol -bspeed testdata/build_path_1/sketch.ino.hex\n " , "" },
156
- {buildPath1 , "alice:avr:board2" , "" , "" , "" , false , "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol -bspeed testdata/build_path_1/sketch.ino.hex\n " , "" },
155
+ {buildPath1 , "alice:avr:board2" , "port" , "serial" , "" , false , "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol -bspeed testdata/upload/ build_path_1/sketch.ino.hex\n " , "" },
156
+ {buildPath1 , "alice:avr:board2" , "" , "" , "" , false , "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol -bspeed testdata/upload/ build_path_1/sketch.ino.hex\n " , "" },
157
157
158
158
// 4: upload with programmer, requires port
159
- {buildPath1 , "alice:avr:board1" , "port" , "serial" , "progr1" , false , "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ progprotocol port -bspeed testdata/build_path_1/sketch.ino.hex\n " , "" },
159
+ {buildPath1 , "alice:avr:board1" , "port" , "serial" , "progr1" , false , "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ progprotocol port -bspeed testdata/upload/ build_path_1/sketch.ino.hex\n " , "" },
160
160
{buildPath1 , "alice:avr:board1" , "" , "" , "progr1" , false , "FAIL" , "" },
161
161
// 6: upload with programmer, no port
162
- {buildPath1 , "alice:avr:board1" , "port" , "serial" , "progr2" , false , "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog2protocol -bspeed testdata/build_path_1/sketch.ino.hex\n " , "" },
163
- {buildPath1 , "alice:avr:board1" , "" , "" , "progr2" , false , "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog2protocol -bspeed testdata/build_path_1/sketch.ino.hex\n " , "" },
162
+ {buildPath1 , "alice:avr:board1" , "port" , "serial" , "progr2" , false , "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog2protocol -bspeed testdata/upload/ build_path_1/sketch.ino.hex\n " , "" },
163
+ {buildPath1 , "alice:avr:board1" , "" , "" , "progr2" , false , "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog2protocol -bspeed testdata/upload/ build_path_1/sketch.ino.hex\n " , "" },
164
164
// 8: upload with programmer, require port through extra params
165
- {buildPath1 , "alice:avr:board1" , "port" , "serial" , "progr3" , false , "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog3protocol port -bspeed testdata/build_path_1/sketch.ino.hex\n " , "" },
165
+ {buildPath1 , "alice:avr:board1" , "port" , "serial" , "progr3" , false , "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog3protocol port -bspeed testdata/upload/ build_path_1/sketch.ino.hex\n " , "" },
166
166
{buildPath1 , "alice:avr:board1" , "" , "" , "progr3" , false , "FAIL" , "" },
167
167
168
168
// 10: burn bootloader, require port
169
169
{buildPath1 , "alice:avr:board1" , "port" , "serial" , "" , true , "FAIL" , "" }, // requires programmer
170
170
{buildPath1 , "alice:avr:board1" , "port" , "serial" , "progr1" , true ,
171
171
"ERASE conf-board1 conf-general conf-erase $$VERBOSE-VERIFY$$ genprog1protocol port -bspeed\n " ,
172
- "BURN conf-board1 conf-general conf-bootloader $$VERBOSE-VERIFY$$ genprog1protocol port -bspeed -F0xFF " + cwd + "/testdata/hardware/alice/avr/bootloaders/niceboot/niceboot.hex\n " },
172
+ "BURN conf-board1 conf-general conf-bootloader $$VERBOSE-VERIFY$$ genprog1protocol port -bspeed -F0xFF " + cwd + "/testdata/upload/ hardware/alice/avr/bootloaders/niceboot/niceboot.hex\n " },
173
173
174
174
// 12: burn bootloader, preferences override from programmers.txt
175
175
{buildPath1 , "alice:avr:board1" , "port" , "serial" , "progr4" , true ,
176
176
"ERASE conf-board1 conf-two-general conf-two-erase $$VERBOSE-VERIFY$$ prog4protocol-bootloader port -bspeed\n " ,
177
- "BURN conf-board1 conf-two-general conf-two-bootloader $$VERBOSE-VERIFY$$ prog4protocol-bootloader port -bspeed -F0xFF " + cwd + "/testdata/hardware/alice/avr/bootloaders/niceboot/niceboot.hex\n " },
177
+ "BURN conf-board1 conf-two-general conf-two-bootloader $$VERBOSE-VERIFY$$ prog4protocol-bootloader port -bspeed -F0xFF " + cwd + "/testdata/upload/ hardware/alice/avr/bootloaders/niceboot/niceboot.hex\n " },
178
178
}
179
179
180
180
pm := pmb .Build ()
0 commit comments