@@ -57,17 +57,21 @@ def test_compile_with_simple_sketch(run_command, data_dir):
5757 log_file_path = os .path .join (data_dir , log_file_name )
5858 result = run_command (
5959 "compile -b {fqbn} {sketch_path} --log-format json --log-file {log_file} --log-level trace" .format (
60- fqbn = fqbn , sketch_path = sketch_path , log_file = log_file_path ))
60+ fqbn = fqbn , sketch_path = sketch_path , log_file = log_file_path
61+ )
62+ )
6163 assert result .ok
6264
6365 # let's test from the logs if the hex file produced by successful compile is moved to our sketch folder
64- log_json = open (log_file_path , 'r' )
66+ log_json = open (log_file_path , "r" )
6567 json_log_lines = log_json .readlines ()
6668 expected_trace_sequence = [
6769 "Compile {sketch} for {fqbn} started" .format (sketch = sketch_path , fqbn = fqbn ),
68- "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name , fqbn = fqbn )
70+ "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name , fqbn = fqbn ),
6971 ]
70- assert is_message_sequence_in_json_log_traces (expected_trace_sequence , json_log_lines )
72+ assert is_message_sequence_in_json_log_traces (
73+ expected_trace_sequence , json_log_lines
74+ )
7175
7276
7377def test_compile_with_sketch_with_symlink_selfloop (run_command , data_dir ):
@@ -94,8 +98,8 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
9498
9599 # Build sketch for arduino:avr:uno
96100 result = run_command (
97- "compile -b {fqbn} {sketch_path}" .format (
98- fqbn = fqbn , sketch_path = sketch_path ) )
101+ "compile -b {fqbn} {sketch_path}" .format (fqbn = fqbn , sketch_path = sketch_path )
102+ )
99103 # The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
100104 # returning a different error detailed message
101105 assert "Error during sketch processing" in result .stderr
@@ -118,8 +122,8 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
118122
119123 # Build sketch for arduino:avr:uno
120124 result = run_command (
121- "compile -b {fqbn} {sketch_path}" .format (
122- fqbn = fqbn , sketch_path = sketch_path ) )
125+ "compile -b {fqbn} {sketch_path}" .format (fqbn = fqbn , sketch_path = sketch_path )
126+ )
123127 # The assertion is a bit relaxed also in this case because macOS behaves differently from win and linux:
124128 # the cli does not follow recursively the symlink til breaking
125129 assert "Error during sketch processing" in result .stderr
@@ -177,32 +181,50 @@ def test_compile_and_compile_combo(run_command, data_dir):
177181 continue
178182 assert isinstance (boards , list )
179183 for board in boards :
180- detected_boards .append (dict (address = port .get ('address' ), fqbn = board .get ('FQBN' )))
184+ detected_boards .append (
185+ dict (address = port .get ("address" ), fqbn = board .get ("FQBN" ))
186+ )
181187
182188 assert len (detected_boards ) >= 1 , "There are no boards available for testing"
183189
184190 # Build sketch for each detected board
185191 for board in detected_boards :
186- log_file_name = "{fqbn}-compile.log" .format (fqbn = board .get ('fqbn' ).replace (":" , "-" ))
192+ log_file_name = "{fqbn}-compile.log" .format (
193+ fqbn = board .get ("fqbn" ).replace (":" , "-" )
194+ )
187195 log_file_path = os .path .join (data_dir , log_file_name )
188- command_log_flags = "--log-format json --log-file {} --log-level trace" .format (log_file_path )
189- result = run_command ("compile -b {fqbn} --upload -p {address} {sketch_path} {log_flags}" .format (
190- fqbn = board .get ('fqbn' ),
191- address = board .get ('address' ),
192- sketch_path = sketch_path ,
193- log_flags = command_log_flags
194- ))
196+ command_log_flags = "--log-format json --log-file {} --log-level trace" .format (
197+ log_file_path
198+ )
199+ result = run_command (
200+ "compile -b {fqbn} --upload -p {address} {sketch_path} {log_flags}" .format (
201+ fqbn = board .get ("fqbn" ),
202+ address = board .get ("address" ),
203+ sketch_path = sketch_path ,
204+ log_flags = command_log_flags ,
205+ )
206+ )
195207 assert result .ok
196208 # check from the logs if the bin file were uploaded on the current board
197- log_json = open (log_file_path , 'r' )
209+ log_json = open (log_file_path , "r" )
198210 json_log_lines = log_json .readlines ()
199211 expected_trace_sequence = [
200- "Compile {sketch} for {fqbn} started" .format (sketch = sketch_path , fqbn = board .get ('fqbn' )),
201- "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name , fqbn = board .get ('fqbn' )),
202- "Upload {sketch} on {fqbn} started" .format (sketch = sketch_path , fqbn = board .get ('fqbn' )),
203- "Upload {sketch} on {fqbn} successful" .format (sketch = sketch_name , fqbn = board .get ('fqbn' ))
212+ "Compile {sketch} for {fqbn} started" .format (
213+ sketch = sketch_path , fqbn = board .get ("fqbn" )
214+ ),
215+ "Compile {sketch} for {fqbn} successful" .format (
216+ sketch = sketch_name , fqbn = board .get ("fqbn" )
217+ ),
218+ "Upload {sketch} on {fqbn} started" .format (
219+ sketch = sketch_path , fqbn = board .get ("fqbn" )
220+ ),
221+ "Upload {sketch} on {fqbn} successful" .format (
222+ sketch = sketch_name , fqbn = board .get ("fqbn" )
223+ ),
204224 ]
205- assert is_message_sequence_in_json_log_traces (expected_trace_sequence , json_log_lines )
225+ assert is_message_sequence_in_json_log_traces (
226+ expected_trace_sequence , json_log_lines
227+ )
206228
207229
208230def is_message_sequence_in_json_log_traces (message_sequence , log_json_lines ):
@@ -213,3 +235,34 @@ def is_message_sequence_in_json_log_traces(message_sequence, log_json_lines):
213235 if entry .get ("msg" ) in message_sequence :
214236 trace_entries .append (entry .get ("msg" ))
215237 return message_sequence == trace_entries
238+
239+
240+ def test_compile_blacklisted_sketchname (run_command , data_dir ):
241+ """
242+ Compile should ignore folders named `RCS`, `.git` and the likes, but
243+ it should be ok for a sketch to be named like RCS.ino
244+ """
245+ # Init the environment explicitly
246+ result = run_command ("core update-index" )
247+ assert result .ok
248+
249+ # Download latest AVR
250+ result = run_command ("core install arduino:avr" )
251+ assert result .ok
252+
253+ sketch_name = "RCS"
254+ sketch_path = os .path .join (data_dir , sketch_name )
255+ fqbn = "arduino:avr:uno"
256+
257+ # Create a test sketch
258+ result = run_command ("sketch new {}" .format (sketch_path ))
259+ assert result .ok
260+ assert "Sketch created in: {}" .format (sketch_path ) in result .stdout
261+
262+ # Build sketch for arduino:avr:uno
263+ log_file_name = "compile.log"
264+ log_file_path = os .path .join (data_dir , log_file_name )
265+ result = run_command (
266+ "compile -b {fqbn} {sketch_path}" .format (fqbn = fqbn , sketch_path = sketch_path )
267+ )
268+ assert result .ok
0 commit comments