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