diff options
author | Jakob Lykke Andersen <Jakob@caput.dk> | 2020-01-20 19:20:35 +0100 |
---|---|---|
committer | Jakob Lykke Andersen <Jakob@caput.dk> | 2020-01-20 19:40:00 +0100 |
commit | 6d7ff482f6af6f3066e1c15d3dd8cae2ee554db8 (patch) | |
tree | 13e53b425013ac96a6f817d0683d67b2bf1c2bc5 /tests/test_domain_cpp.py | |
parent | c07c618f1b034dd40a25468da6b7954cc77b41de (diff) | |
download | sphinx-git-6d7ff482f6af6f3066e1c15d3dd8cae2ee554db8.tar.gz |
C++, test role target checks and fix two cases
Diffstat (limited to 'tests/test_domain_cpp.py')
-rw-r--r-- | tests/test_domain_cpp.py | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py index df1e1bae1..7626ff99d 100644 --- a/tests/test_domain_cpp.py +++ b/tests/test_domain_cpp.py @@ -786,11 +786,59 @@ def test_xref_parsing(): # raise DefinitionError("") +def filter_warnings(warning, file): + lines = warning.getvalue().split("\n"); + res = [l for l in lines if "/domain-cpp/{}.rst".format(file) in l and + "WARNING: document isn't included in any toctree" not in l] + print("Filtered warnings for file '{}':".format(file)) + for w in res: + print(w) + return res + + @pytest.mark.sphinx(testroot='domain-cpp') def test_build_domain_cpp_misuse_of_roles(app, status, warning): app.builder.build_all() - - # TODO: properly check for the warnings we expect + ws = filter_warnings(warning, "roles-targets-ok") + assert len(ws) == 0 + + ws = filter_warnings(warning, "roles-targets-warn") + # the roles that should be able to generate warnings: + allRoles = ['class', 'struct', 'union', 'func', 'member', 'var', 'type', 'concept', 'enum', 'enumerator'] + ok = [ # targetType, okRoles + ('class', ['class', 'struct', 'type']), + ('union', ['union', 'type']), + ('func', ['func', 'type']), + ('member', ['member', 'var']), + ('type', ['type']), + ('concept', ['concept']), + ('enum', ['type', 'enum']), + ('enumerator', ['enumerator']), + ('tParam', ['class', 'struct', 'union', 'func', 'member', 'var', 'type', 'concept', 'enum', 'enumerator', 'functionParam']), + ('functionParam', ['member', 'var']), + ] + warn = [] + for targetType, roles in ok: + txtTargetType = "function" if targetType == "func" else targetType + for r in allRoles: + if r not in roles: + warn.append("WARNING: cpp:{} targets a {} (".format(r, txtTargetType)) + warn = list(sorted(warn)) + for w in ws: + assert "targets a" in w + ws = [w[w.index("WARNING:"):] for w in ws] + ws = list(sorted(ws)) + print("Expected warnings:") + for w in warn: + print(w) + print("Actual warnings:") + for w in ws: + print(w) + + for i in range(min(len(warn), len(ws))): + assert ws[i].startswith(warn[i]) + + assert len(ws) == len(warn) @pytest.mark.skipif(docutils.__version_info__ < (0, 13), |