@@ -158,6 +158,75 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
158
158
assert not result .ok
159
159
160
160
161
+ def test_compile_with_symlink (run_command , data_dir ):
162
+ # Init the environment explicitly
163
+ run_command (["core" , "update-index" ])
164
+
165
+ # Install Arduino AVR Boards
166
+ run_command ([
"core" ,
"install" ,
"arduino:[email protected] " ])
167
+
168
+ sketch_name = "CompileIntegrationTestSymlinkOk"
169
+ sketch_path = os .path .join (data_dir , sketch_name )
170
+ main_file = os .path .join (sketch_path , "{}.ino" .format (sketch_name ))
171
+ symlink_file = os .path .join (sketch_path , "link.ino" )
172
+ fqbn = "arduino:avr:uno"
173
+
174
+ # Create a test sketch
175
+ result = run_command (["sketch" , "new" , sketch_path ])
176
+ assert result .ok
177
+ assert "Sketch created in: {}" .format (sketch_path ) in result .stdout
178
+
179
+ # create a symlink to some external file and move the main .ino
180
+ # contents into that to check that the symlink is actually compiled
181
+ with tempfile .NamedTemporaryFile () as external :
182
+ os .symlink (external .name , symlink_file )
183
+
184
+ with open (main_file , mode = "rb+" ) as main :
185
+ external .write (main .read ())
186
+ external .flush ()
187
+ main .truncate (0 )
188
+ main .flush ()
189
+
190
+ # Build sketch for arduino:avr:uno
191
+ result = run_command (["compile" , "-b" , fqbn , sketch_path ])
192
+ assert result .stderr == ""
193
+ assert result .ok
194
+
195
+ def test_broken_symlink (sketch_name , link_name , target_name , expect_error ):
196
+ sketch_path = os .path .join (data_dir , sketch_name )
197
+ symlink_file = os .path .join (sketch_path , link_name )
198
+ target_file = os .path .join (sketch_path , target_name )
199
+ fqbn = "arduino:avr:uno"
200
+
201
+ # Create a test sketch
202
+ result = run_command (["sketch" , "new" , sketch_path ])
203
+ assert result .ok
204
+ assert "Sketch created in: {}" .format (sketch_path ) in result .stdout
205
+
206
+ os .symlink (target_file , symlink_file )
207
+
208
+ # Build sketch for arduino:avr:uno
209
+ result = run_command (["compile" , "-b" , fqbn , sketch_path ])
210
+
211
+ if expect_error :
212
+ # The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
213
+ # returning a different error detailed message #TODO: Is this true
214
+ # here too and should the error message check be more generic?
215
+ expected_error = "Error during build: Can't open sketch: stat {}: no such file or directory" .format (
216
+ symlink_file
217
+ )
218
+ assert expected_error in result .stderr
219
+ assert not result .ok
220
+ else :
221
+ assert result .ok
222
+
223
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenIno" , "link.ino" , "doesnotexist.ino" , expect_error = True )
224
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenCpp" , "link.cpp" , "doesnotexist.cpp" , expect_error = True )
225
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenH" , "link.h" , "doesnotexist.h" , expect_error = True )
226
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenJson" , "link.json" , "doesnotexist.json" , expect_error = True )
227
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenXXX" , "link.xxx" , "doesnotexist.xxx" , expect_error = True )
228
+
229
+
161
230
def test_compile_blacklisted_sketchname (run_command , data_dir ):
162
231
"""
163
232
Compile should ignore folders named `RCS`, `.git` and the likes, but
0 commit comments