@@ -42,17 +42,31 @@ def test_compile_with_simple_sketch(run_command, data_dir):
42
42
result = run_command ("core install arduino:avr" )
43
43
assert result .ok
44
44
45
- sketch_path = os .path .join (data_dir , "CompileIntegrationTest" )
45
+ sketch_name = "CompileIntegrationTest"
46
+ sketch_path = os .path .join (data_dir , sketch_name )
47
+ fqbn = "arduino:avr:uno"
46
48
47
49
# Create a test sketch
48
- result = run_command ("sketch new CompileIntegrationTest" )
50
+ result = run_command ("sketch new {}" . format ( sketch_name ) )
49
51
assert result .ok
50
52
assert "Sketch created in: {}" .format (sketch_path ) in result .stdout
51
53
52
54
# Build sketch for arduino:avr:uno
53
- result = run_command ("compile -b arduino:avr:uno {}" .format (sketch_path ))
55
+ log_file_name = "compile.log"
56
+ log_file_path = os .path .join (data_dir , log_file_name )
57
+ result = run_command (
58
+ "compile -b {fqbn} {sketch_path} --log-format json --log-file {log_file} --log-level trace" .format (
59
+ fqbn = fqbn , sketch_path = sketch_path , log_file = log_file_path ))
54
60
assert result .ok
55
- assert "Sketch uses" in result .stdout
61
+
62
+ # let's test from the logs if the hex file produced by successful compile is moved to our sketch folder
63
+ log_json = open (log_file_path , 'r' )
64
+ json_log_lines = log_json .readlines ()
65
+ assert is_message_in_json_log_lines ("Executing `arduino compile`" , json_log_lines )
66
+ assert is_message_in_json_log_lines (
67
+ "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name ,
68
+ fqbn = fqbn ),
69
+ json_log_lines )
56
70
57
71
58
72
@pytest .mark .skipif (running_on_ci (), reason = "VMs have no serial ports" )
@@ -110,20 +124,33 @@ def test_compile_and_compile_combo(run_command, data_dir):
110
124
111
125
# Build sketch for each detected board
112
126
for board in detected_boards :
113
- log_file = "compile.log"
127
+ log_file_name = "{fqbn}-compile.log" .format (fqbn = board .get ('fqbn' ))
128
+ log_file_path = os .path .join (data_dir , log_file_name )
114
129
result = run_command (
115
130
"compile -b {fqbn} --upload -p {address} {sketch_path} --log-format json --log-file {log_file} --log-level trace" .format (
116
131
fqbn = board .get ('fqbn' ),
117
132
address = board .get ('address' ),
118
133
sketch_path = sketch_path ,
119
- log_file = log_file
134
+ log_file = log_file_path
120
135
)
121
136
)
122
- log_json = open (log_file ,'r' )
123
- log_json_lines = log_json .readlines ()
124
- assert is_value_in_any_json_log_message ("copying sketch build output" ,log_json_lines )
125
- assert is_value_in_any_json_log_message ("Executing `arduino upload`" ,log_json_lines )
126
137
assert result .ok
127
-
128
- def is_value_in_any_json_log_message (value ,log_json_lines ):
129
- return bool ([index for index , line in enumerate (log_json_lines ) if json .loads (line ).get ("msg" ) == value ])
138
+ # check from the logs if the bin file were uploaded on the current board
139
+ log_json = open (log_file_path , 'r' )
140
+ json_log_lines = log_json .readlines ()
141
+ assert is_message_in_json_log_lines ("Executing `arduino compile`" , json_log_lines )
142
+ assert is_message_in_json_log_lines (
143
+ "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name ,
144
+ fqbn = board .get (
145
+ 'fqbn' )),
146
+ json_log_lines )
147
+ assert is_message_in_json_log_lines ("Executing `arduino upload`" , json_log_lines )
148
+ assert is_message_in_json_log_lines (
149
+ "Upload {sketch} on {fqbn} successful" .format (sketch = sketch_name ,
150
+ fqbn = board .get (
151
+ 'fqbn' )),
152
+ json_log_lines )
153
+
154
+
155
+ def is_message_in_json_log_lines (message , log_json_lines ):
156
+ return len ([index for index , entry in enumerate (log_json_lines ) if json .loads (entry ).get ("msg" ) == message ]) == 1
0 commit comments