summaryrefslogtreecommitdiffstats
path: root/util/cmake/tests/test_parsing.py
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2019-02-11 18:02:22 +0100
committerTobias Hunger <tobias.hunger@qt.io>2019-02-27 16:02:45 +0000
commit35f23a3dad20e09bada4e8fcdcc0de16b8a6af2f (patch)
tree6a6e3d10cbf5896d908a594bba093d2708fe9f9e /util/cmake/tests/test_parsing.py
parentb1fa25e7b8974fd9ce4b6d1283b9a43da532992e (diff)
CMake: pro2cmake.py: Better parsing of scopes with else
Parse conditions more exactly as before, enabling proper handling of else scopes. Change-Id: Icb5dcc73010be4833b2d1cbc1396191992df1ee4 Reviewed-by: Albert Astals Cid <albert.astals.cid@kdab.com>
Diffstat (limited to 'util/cmake/tests/test_parsing.py')
-rwxr-xr-xutil/cmake/tests/test_parsing.py88
1 files changed, 84 insertions, 4 deletions
diff --git a/util/cmake/tests/test_parsing.py b/util/cmake/tests/test_parsing.py
index 0802fe47422..e4f9680f603 100755
--- a/util/cmake/tests/test_parsing.py
+++ b/util/cmake/tests/test_parsing.py
@@ -37,7 +37,7 @@ _tests_path = os.path.dirname(os.path.abspath(__file__))
def validate_op(key, op, value, to_validate):
assert key == to_validate['key']
assert op == to_validate['operation']
- assert value == to_validate['value']
+ assert value == to_validate.get('value', None)
def validate_single_op(key, op, value, to_validate):
@@ -71,10 +71,21 @@ def validate_default_else_test(file_name):
def parse_file(file):
p = QmakeParser(debug=True)
- result = p.parseFile(file).asDict()
- assert len(result) == 1
+ result = p.parseFile(file)
+
+ print('\n\n#### Parser result:')
+ print(result)
+ print('\n#### End of parser result.\n')
+
+ print('\n\n####Parser result dictionary:')
+ print(result.asDict())
+ print('\n#### End of parser result dictionary.\n')
+
+ result_dictionary = result.asDict()
+
+ assert len(result_dictionary) == 1
- return result['statements']
+ return result_dictionary['statements']
def test_else():
@@ -129,6 +140,13 @@ def test_else8():
validate_default_else_test(_tests_path + '/data/else8.pro')
+def test_multiline_assign():
+ result = parse_file(_tests_path + '/data/multiline_assign.pro')
+ assert len(result) == 2
+ validate_op('A', '=', ['42', '43', '44'], result[0])
+ validate_op('B', '=', ['23'], result[1])
+
+
def test_include():
result = parse_file(_tests_path + '/data/include.pro')
assert len(result) == 3
@@ -174,3 +192,65 @@ def test_complex_values():
def test_function_if():
result = parse_file(_tests_path + '/data/function_if.pro')
assert len(result) == 1
+
+
+def test_realworld_standardpaths():
+ result = parse_file(_tests_path + '/data/standardpaths.pro')
+
+ (cond, if_branch, else_branch) = evaluate_condition(result[0])
+ assert cond == 'win32'
+ assert len(if_branch) == 1
+ assert len(else_branch) == 1
+
+ # win32:
+ (cond1, if_branch1, else_branch1) = evaluate_condition(if_branch[0])
+ assert cond1 == '!winrt'
+ assert len(if_branch1) == 1
+ validate_op('SOURCES', '+=', ['io/qstandardpaths_win.cpp'], if_branch1[0])
+ assert len(else_branch1) == 1
+ validate_op('SOURCES', '+=', ['io/qstandardpaths_winrt.cpp'], else_branch1[0])
+
+ # unix:
+ (cond2, if_branch2, else_branch2) = evaluate_condition(else_branch[0])
+ assert cond2 == 'unix'
+ assert len(if_branch2) == 1
+ assert len(else_branch2) == 0
+
+ # mac / else:
+ (cond3, if_branch3, else_branch3) = evaluate_condition(if_branch2[0])
+ assert cond3 == 'mac'
+ assert len(if_branch3) == 1
+ validate_op('OBJECTIVE_SOURCES', '+=', ['io/qstandardpaths_mac.mm'], if_branch3[0])
+ assert len(else_branch3) == 1
+
+ # android / else:
+ (cond4, if_branch4, else_branch4) = evaluate_condition(else_branch3[0])
+ assert cond4 == 'android && !android-embedded'
+ assert len(if_branch4) == 1
+ validate_op('SOURCES', '+=', ['io/qstandardpaths_android.cpp'], if_branch4[0])
+ assert len(else_branch4) == 1
+
+ # haiku / else:
+ (cond5, if_branch5, else_branch5) = evaluate_condition(else_branch4[0])
+ assert cond5 == 'haiku'
+ assert len(if_branch5) == 1
+ validate_op('SOURCES', '+=', ['io/qstandardpaths_haiku.cpp'], if_branch5[0])
+ assert len(else_branch5) == 1
+ validate_op('SOURCES', '+=', ['io/qstandardpaths_unix.cpp'], else_branch5[0])
+
+
+def test_realworld_comment_scope():
+ result = parse_file(_tests_path + '/data/comment_scope.pro')
+ assert len(result) == 2
+ (cond, if_branch, else_branch) = evaluate_condition(result[0])
+ assert cond == 'freebsd|openbsd'
+ assert len(if_branch) == 1
+ validate_op('QMAKE_LFLAGS_NOUNDEF', '=', None, if_branch[0])
+
+ assert result[1].get('included', '') == 'animation/animation.pri'
+
+
+def test_realworld_contains_scope():
+ result = parse_file(_tests_path + '/data/contains_scope.pro')
+ assert len(result) == 2
+