1
|
1
|
import os
|
2
|
|
-import pytest
|
|
2
|
+import sys
|
|
3
|
+import shutil
|
3
|
4
|
import itertools
|
|
5
|
+import pytest
|
4
|
6
|
from tests.testutils import cli, generate_junction
|
5
|
7
|
|
6
|
8
|
from buildstream import _yaml
|
... |
... |
@@ -232,3 +234,58 @@ def test_fetched_junction(cli, tmpdir, datafiles, element_name): |
232
|
234
|
|
233
|
235
|
results = result.output.strip().splitlines()
|
234
|
236
|
assert 'junction.bst:import-etc.bst-buildable' in results
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+###############################################################
|
|
240
|
+# Testing recursion depth #
|
|
241
|
+###############################################################
|
|
242
|
+@pytest.mark.parametrize("dependency_depth", [100, 500, 1200])
|
|
243
|
+def test_exceed_max_recursion_depth(cli, tmpdir, dependency_depth):
|
|
244
|
+ project_name = "recursion-test"
|
|
245
|
+ path = str(tmpdir)
|
|
246
|
+ project_path = os.path.join(path, project_name)
|
|
247
|
+
|
|
248
|
+ def setup_test():
|
|
249
|
+ """
|
|
250
|
+ Creates a bst project with dependencydepth + 1 elements, each of which
|
|
251
|
+ depends of the previous element to be created. Each element created
|
|
252
|
+ is of type import and has an empty source file.
|
|
253
|
+ """
|
|
254
|
+ os.mkdir(project_path)
|
|
255
|
+
|
|
256
|
+ result = cli.run(project=project_path, silent=True,
|
|
257
|
+ args=['init', '--project-name', project_name])
|
|
258
|
+ result.assert_success()
|
|
259
|
+
|
|
260
|
+ sourcefiles_path = os.path.join(project_path, "files")
|
|
261
|
+ os.mkdir(sourcefiles_path)
|
|
262
|
+
|
|
263
|
+ element_path = os.path.join(project_path, "elements")
|
|
264
|
+ for i in range(0, dependency_depth + 1):
|
|
265
|
+ element = {
|
|
266
|
+ 'kind': 'import',
|
|
267
|
+ 'sources': [{'kind': 'local',
|
|
268
|
+ 'path': 'files/source{}'.format(str(i))}],
|
|
269
|
+ 'depends': ['element{}.bst'.format(str(i - 1))]
|
|
270
|
+ }
|
|
271
|
+ if i == 0:
|
|
272
|
+ del element['depends']
|
|
273
|
+ _yaml.dump(element, os.path.join(element_path, "element{}.bst".format(str(i))))
|
|
274
|
+
|
|
275
|
+ source = os.path.join(sourcefiles_path, "source{}".format(str(i)))
|
|
276
|
+ open(source, 'x').close()
|
|
277
|
+ assert os.path.exists(source)
|
|
278
|
+
|
|
279
|
+ setup_test()
|
|
280
|
+ result = cli.run(project=project_path, silent=True,
|
|
281
|
+ args=['show', "element{}.bst".format(str(dependency_depth))])
|
|
282
|
+
|
|
283
|
+ recursion_limit = sys.getrecursionlimit()
|
|
284
|
+ if dependency_depth <= recursion_limit:
|
|
285
|
+ result.assert_success()
|
|
286
|
+ else:
|
|
287
|
+ # Assert exception is thown and handled
|
|
288
|
+ assert not result.unhandled_exception
|
|
289
|
+ assert result.exit_code == -1
|
|
290
|
+
|
|
291
|
+ shutil.rmtree(project_path)
|