@@ -233,6 +233,133 @@ def test_compile_without_precompiled_libraries(run_command, data_dir):
233
233
assert result .ok
234
234
235
235
236
+ def test_compile_with_build_properties_flag (run_command , data_dir , copy_sketch ):
237
+ # Init the environment explicitly
238
+ assert run_command ("core update-index" )
239
+
240
+ # Install Arduino AVR Boards
241
+ assert run_command (
"core install arduino:[email protected] " )
242
+
243
+ sketch_path = copy_sketch ("sketch_with_single_string_define" )
244
+ fqbn = "arduino:avr:uno"
245
+
246
+ # Compile using a build property with quotes
247
+ res = run_command (
248
+ f"compile -b { fqbn } "
249
+ + '--build-properties="build.extra_flags=\\ "-DMY_DEFINE=\\ "hello world\\ "\\ "" '
250
+ + f"{ sketch_path } --verbose --clean"
251
+ )
252
+ assert res .failed
253
+ assert "Flag --build-properties has been deprecated, please use --build-property instead." not in res .stderr
254
+
255
+ # Try again with quotes
256
+ res = run_command (
257
+ f"compile -b { fqbn } "
258
+ + '--build-properties="build.extra_flags=-DMY_DEFINE=\\ "hello\\ "" '
259
+ + f"{ sketch_path } --verbose --clean"
260
+ )
261
+ assert res .failed
262
+ assert "Flag --build-properties has been deprecated, please use --build-property instead." not in res .stderr
263
+
264
+ # Try without quotes
265
+ sketch_path = copy_sketch ("sketch_with_single_int_define" )
266
+ res = run_command (
267
+ f"compile -b { fqbn } "
268
+ + '--build-properties="build.extra_flags=-DMY_DEFINE=1" '
269
+ + f"{ sketch_path } --verbose --clean"
270
+ )
271
+ assert res .ok
272
+ assert "Flag --build-properties has been deprecated, please use --build-property instead." in res .stderr
273
+ assert "-DMY_DEFINE=1" in res .stdout
274
+
275
+ sketch_path = copy_sketch ("sketch_with_multiple_int_defines" )
276
+ res = run_command (
277
+ f"compile -b { fqbn } "
278
+ + '--build-properties="build.extra_flags=-DFIRST_PIN=1,compiler.cpp.extra_flags=-DSECOND_PIN=2" '
279
+ + f"{ sketch_path } --verbose --clean"
280
+ )
281
+ assert res .ok
282
+ assert "Flag --build-properties has been deprecated, please use --build-property instead." in res .stderr
283
+ assert "-DFIRST_PIN=1" in res .stdout
284
+ assert "-DSECOND_PIN=2" in res .stdout
285
+
286
+
287
+ def test_compile_with_build_property_containing_quotes (run_command , data_dir , copy_sketch ):
288
+ # Init the environment explicitly
289
+ assert run_command ("core update-index" )
290
+
291
+ # Install Arduino AVR Boards
292
+ assert run_command (
"core install arduino:[email protected] " )
293
+
294
+ sketch_path = copy_sketch ("sketch_with_single_string_define" )
295
+ fqbn = "arduino:avr:uno"
296
+
297
+ # Compile using a build property with quotes
298
+ res = run_command (
299
+ f"compile -b { fqbn } "
300
+ + '--build-property="build.extra_flags=\\ "-DMY_DEFINE=\\ "hello world\\ "\\ "" '
301
+ + f"{ sketch_path } --verbose"
302
+ )
303
+ assert res .ok
304
+ assert '-DMY_DEFINE=\\ "hello world\\ "' in res .stdout
305
+
306
+
307
+ def test_compile_with_multiple_build_property_flags (run_command , data_dir , copy_sketch , working_dir ):
308
+ # Init the environment explicitly
309
+ assert run_command ("core update-index" )
310
+
311
+ # Install Arduino AVR Boards
312
+ assert run_command (
"core install arduino:[email protected] " )
313
+
314
+ sketch_path = copy_sketch ("sketch_with_multiple_defines" )
315
+ fqbn = "arduino:avr:uno"
316
+
317
+ # Compile using multiple build properties separated by a space
318
+ res = run_command (
319
+ f"compile -b { fqbn } "
320
+ + '--build-property="compiler.cpp.extra_flags=\\ "-DPIN=2 -DSSID=\\ "This is a String\\ "\\ "" '
321
+ + f"{ sketch_path } --verbose --clean"
322
+ )
323
+ assert res .failed
324
+
325
+ # Compile using multiple build properties separated by a space and properly quoted
326
+ res = run_command (
327
+ f"compile -b { fqbn } "
328
+ + '--build-property="compiler.cpp.extra_flags=-DPIN=2 \\ "-DSSID=\\ "This is a String\\ "\\ "" '
329
+ + f"{ sketch_path } --verbose --clean"
330
+ )
331
+ assert res .ok
332
+ assert '-DPIN=2 "-DSSID=\\ "This is a String\\ ""' in res .stdout
333
+
334
+ # Tries compilation using multiple build properties separated by a comma
335
+ res = run_command (
336
+ f"compile -b { fqbn } "
337
+ + '--build-property="compiler.cpp.extra_flags=\\ "-DPIN=2,-DSSID=\\ "This is a String\\ "\\ "\\ " '
338
+ + f"{ sketch_path } --verbose --clean"
339
+ )
340
+ assert res .failed
341
+
342
+ res = run_command (
343
+ f"compile -b { fqbn } "
344
+ + '--build-property="compiler.cpp.extra_flags=\\ "-DPIN=2\\ "" '
345
+ + '--build-property="compiler.cpp.extra_flags=\\ "-DSSID=\\ "This is a String\\ "\\ "" '
346
+ + f"{ sketch_path } --verbose --clean"
347
+ )
348
+ assert res .failed
349
+ assert "-DPIN=2" not in res .stdout
350
+ assert '-DSSID=\\ "This is a String\\ "' in res .stdout
351
+
352
+ res = run_command (
353
+ f"compile -b { fqbn } "
354
+ + '--build-property="compiler.cpp.extra_flags=\\ "-DPIN=2\\ "" '
355
+ + '--build-property="build.extra_flags=\\ "-DSSID=\\ "hello world\\ "\\ "" '
356
+ + f"{ sketch_path } --verbose --clean"
357
+ )
358
+ assert res .ok
359
+ assert "-DPIN=2" in res .stdout
360
+ assert '-DSSID=\\ "hello world\\ "' in res .stdout
361
+
362
+
236
363
def test_compile_with_output_dir_flag (run_command , data_dir ):
237
364
# Init the environment explicitly
238
365
run_command ("core update-index" )
0 commit comments