Generate text output using both the directive and the parser test
output, they should match.
Depends on the sphinx_testing package.
---
test/Makefile.local | 3 +--
test/sphinx/conf.py | 9 +++----
test/sphinx/index.rst | 2 --
test/test_cautodoc.py | 62 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 10 deletions(-)
create mode 100755 test/test_cautodoc.py
diff --git a/test/Makefile.local b/test/Makefile.local
index 6eeb06a155f2..743ab502b804 100644
--- a/test/Makefile.local
+++ b/test/Makefile.local
@@ -3,8 +3,7 @@
# Licensed under the terms of BSD 2-Clause, see LICENSE for details.
#
# FIXME: This is inadequate. Needs more test data, in particular more
-# pathological real world test data. Needs to run the directive extension too,
-# not just the comment extraction part.
+# pathological real world test data.
#
dir := test
diff --git a/test/sphinx/conf.py b/test/sphinx/conf.py
index 3a05c080c994..07d15b9ce29e 100644
--- a/test/sphinx/conf.py
+++ b/test/sphinx/conf.py
@@ -18,7 +18,7 @@ import os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-sys.path.insert(0, os.path.abspath('../..'))
+#sys.path.insert(0, os.path.abspath('../..'))
# -- General configuration ------------------------------------------------
@@ -31,7 +31,7 @@ sys.path.insert(0, os.path.abspath('../..'))
extensions = ['hawkmoth']
# Add any paths that contain templates here, relative to this directory.
-templates_path = ['_templates']
+#templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
@@ -127,7 +127,7 @@ html_theme = 'default'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ['_static']
+#html_static_path = ['_static']
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
@@ -256,6 +256,3 @@ texinfo_documents = [
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False
-
-# -- Options for Hawkmoth CAutoDoc
-cautodoc_root = os.path.abspath('..')
diff --git a/test/sphinx/index.rst b/test/sphinx/index.rst
index e14db81bac00..66bb80d380a1 100644
--- a/test/sphinx/index.rst
+++ b/test/sphinx/index.rst
@@ -11,8 +11,6 @@ Contents:
.. toctree::
:maxdepth: 2
-.. c:autodoc:: *.c
-
Indices and tables
==================
diff --git a/test/test_cautodoc.py b/test/test_cautodoc.py
new file mode 100755
index 000000000000..17c7fd0132ee
--- /dev/null
+++ b/test/test_cautodoc.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+# Copyright (c) 2018, Jani Nikula <jani@xxxxxxxxxx>
+# Licensed under the terms of BSD 2-Clause, see LICENSE for details.
+
+import os
+import shutil
+import unittest
+
+import testenv
+from sphinx_testing import with_app
+
+class DirectiveTest(unittest.TestCase):
+
+ def setup_src(self, srcdir, testcase_in):
+ testcase_out = testenv.modify_filename(testcase_in, dir=srcdir)
+
+ # use the pre-generated rst as comparison data
+ shutil.copyfile(testenv.modify_filename(testcase_in, ext='stdout'),
+ testenv.modify_filename(testcase_out,
ext='expected.rst'))
+
+ # set up an rst file to run the extension
+ shutil.copyfile(testcase_in, testcase_out)
+ options = testenv.get_testcase_options(testcase_in)
+
+ with open(testenv.modify_filename(testcase_out, ext='output.rst'),
'w') as file:
+ fmt = '.. c:autodoc:: {source}\n'
+ file.write(fmt.format(source=os.path.basename(testcase_out)))
+ for key in options.keys():
+ fmt = ' :{key}: {value}\n'
+ file.write(fmt.format(key=key, value=options[key]))
+
+ def check_out(self, outdir, testcase_in):
+ testcase_out = testenv.modify_filename(testcase_in, dir=outdir)
+
+ # compare output from the pre-generated rst against the output
generated
+ # by the extension
+
+ output = testenv.read_file(testenv.modify_filename(testcase_out,
+ ext='output.txt'))
+
+ expected = testenv.read_file(testenv.modify_filename(testcase_out,
+
ext='expected.txt'))
+
+ self.assertEqual(expected, output)
+
+ # Use copy_srcdir_to_tmpdir=False and outdir='some-dir' for debugging
+ @with_app(srcdir=os.path.join(testenv.testdir, 'sphinx'),
+ buildername='text', copy_srcdir_to_tmpdir=True)
+ def test_directive(self, app, status, warning):
+ testcases = testenv.get_testcases(testenv.testdir)
+
+ for f in testcases:
+ self.setup_src(app.srcdir, f)
+
+ app.build()
+
+ for f in testcases:
+ with self.subTest(source=os.path.basename(f)):
+ self.check_out(app.outdir, os.path.basename(f))
+
+if __name__ == '__main__':
+ unittest.main()
--
2.19.2