diff options
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), |