@@ -158,6 +158,78 @@ 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 (delete = False ) as external :
182
+ try :
183
+ os .symlink (external .name , symlink_file )
184
+
185
+ with open (main_file , mode = "rb+" ) as main :
186
+ external .write (main .read ())
187
+ external .flush ()
188
+ main .truncate (0 )
189
+ main .flush ()
190
+
191
+ # Close to allow re-opening the file on Windows
192
+ # See https://bugs.python.org/issue14243
193
+ external .close ()
194
+
195
+ # Build sketch for arduino:avr:uno
196
+ result = run_command (["compile" , "-b" , fqbn , sketch_path ])
197
+ assert result .stderr == ""
198
+ assert result .ok
199
+ finally :
200
+ # Explicit cleanup needed because the file is closed above
201
+ os .unlink (external .name )
202
+
203
+ def test_broken_symlink (sketch_name , link_name , target_name , expect_error ):
204
+ sketch_path = os .path .join (data_dir , sketch_name )
205
+ symlink_file = os .path .join (sketch_path , link_name )
206
+ target_file = os .path .join (sketch_path , target_name )
207
+ fqbn = "arduino:avr:uno"
208
+
209
+ # Create a test sketch
210
+ result = run_command (["sketch" , "new" , sketch_path ])
211
+ assert result .ok
212
+ assert "Sketch created in: {}" .format (sketch_path ) in result .stdout
213
+
214
+ os .symlink (target_file , symlink_file )
215
+
216
+ # Build sketch for arduino:avr:uno
217
+ result = run_command (["compile" , "-b" , fqbn , sketch_path ])
218
+
219
+ if expect_error :
220
+ expected_error = "Error during build: Can't open sketch: stat {}: " .format (symlink_file )
221
+ assert expected_error in result .stderr
222
+ assert not result .ok
223
+ else :
224
+ assert result .ok
225
+
226
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenIno" , "link.ino" , "doesnotexist.ino" , expect_error = True )
227
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenCpp" , "link.cpp" , "doesnotexist.cpp" , expect_error = True )
228
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenH" , "link.h" , "doesnotexist.h" , expect_error = True )
229
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenJson" , "link.json" , "doesnotexist.json" , expect_error = True )
230
+ test_broken_symlink ("CompileIntegrationTestSymlinkBrokenXXX" , "link.xxx" , "doesnotexist.xxx" , expect_error = True )
231
+
232
+
161
233
def test_compile_blacklisted_sketchname (run_command , data_dir ):
162
234
"""
163
235
Compile should ignore folders named `RCS`, `.git` and the likes, but
0 commit comments