diff --git a/CHANGES.rst b/CHANGES.rst index 6f7279e8011..e0a9f12f28d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -18,6 +18,10 @@ Features added Bugs fixed ---------- +* #13230: Fix the ``toc.empty_glob`` warning sub-type not being suppressible + via :confval:`suppress_warnings`, due to a missing ``type='toc'`` argument + in the toctree directive's warning call. + Patch by Ferdinand Schwenk. * #14189: autodoc: Fix duplicate ``:no-index-entry:`` for modules. Patch by Adam Turner * #13713: Fix compatibility with MyST-Parser. diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 80bedce43cb..9d50d772e65 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -119,6 +119,7 @@ def parse_content(self, toctree: addnodes.toctree) -> None: __("toctree glob pattern %r didn't match any documents"), entry, location=toctree, + type='toc', subtype='empty_glob', ) diff --git a/tests/test_directives/test_directive_other.py b/tests/test_directives/test_directive_other.py index 1aa370cce8d..42f0ea60a34 100644 --- a/tests/test_directives/test_directive_other.py +++ b/tests/test_directives/test_directive_other.py @@ -127,6 +127,28 @@ def test_toctree_glob_and_url(app): ) +@pytest.mark.sphinx('html', testroot='toctree-glob') +def test_toctree_glob_empty_emits_warning(app): + """An unmatched glob pattern emits a toc.empty_glob warning.""" + text = '.. toctree::\n :glob:\n\n nonexistent*\n' + app.env.find_files(app.config, app.builder) + restructuredtext.parse(app, text, 'index') + assert "toctree glob pattern 'nonexistent*' didn't match any documents" in app._warning.getvalue() + + +@pytest.mark.sphinx( + 'html', + testroot='toctree-glob', + confoverrides={'suppress_warnings': ['toc.empty_glob']}, +) +def test_toctree_glob_empty_suppressed(app): + """suppress_warnings=['toc.empty_glob'] must suppress the empty glob warning.""" + text = '.. toctree::\n :glob:\n\n nonexistent*\n' + app.env.find_files(app.config, app.builder) + restructuredtext.parse(app, text, 'index') + assert app._warning.getvalue() == '' + + @pytest.mark.sphinx('html', testroot='toctree-glob') def test_reversed_toctree(app): text = '.. toctree::\n :reversed:\n\n foo\n bar/index\n baz\n'