summaryrefslogtreecommitdiff
path: root/tests/scanner
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2019-01-09 23:07:00 +0100
committerChristoph Reiter <reiter.christoph@gmail.com>2019-01-09 23:16:55 +0100
commit4f1374ba76d919c4e0d69c8a542f184d9d10df08 (patch)
tree92aaf30998ae841d8386016cbb6b27edc83529be /tests/scanner
parent19e1c72db3ac4436cbb68dc0fb21c79c5f13e74b (diff)
downloadgobject-introspection-4f1374ba76d919c4e0d69c8a542f184d9d10df08.tar.gz
maintransformer: parse deprecation annotations for section blocks. Fixes #213
The scanner matches gtk-doc sections which match the lower case type name to the type and uses that for the type documentation. The only problem is it only takes the docs and none of the other annotations like deprecation info etc. This changes things to also parse the annotations in that case and adds some tests while at it.
Diffstat (limited to 'tests/scanner')
-rw-r--r--tests/scanner/Makefile.am3
-rw-r--r--tests/scanner/meson.build1
-rw-r--r--tests/scanner/test_maintransformer.py72
3 files changed, 75 insertions, 1 deletions
diff --git a/tests/scanner/Makefile.am b/tests/scanner/Makefile.am
index 734f30e8..89bfed90 100644
--- a/tests/scanner/Makefile.am
+++ b/tests/scanner/Makefile.am
@@ -236,7 +236,8 @@ PYTESTS = \
test_transformer.py \
test_xmlwriter.py \
test_docwriter.py \
- test_scanner.py
+ test_scanner.py \
+ test_maintransformer.py
TESTS = $(CHECKGIRS) $(CHECKDOCS) $(TYPELIBS) $(PYTESTS)
TESTS_ENVIRONMENT = env srcdir=$(srcdir) top_srcdir=$(top_srcdir) builddir=$(builddir) top_builddir=$(top_builddir) \
diff --git a/tests/scanner/meson.build b/tests/scanner/meson.build
index 95a9dacc..42104886 100644
--- a/tests/scanner/meson.build
+++ b/tests/scanner/meson.build
@@ -13,6 +13,7 @@ scanner_test_files = [
'test_pkgconfig.py',
'test_docwriter.py',
'test_scanner.py',
+ 'test_maintransformer.py',
]
foreach f : scanner_test_files
diff --git a/tests/scanner/test_maintransformer.py b/tests/scanner/test_maintransformer.py
new file mode 100644
index 00000000..abf3ee73
--- /dev/null
+++ b/tests/scanner/test_maintransformer.py
@@ -0,0 +1,72 @@
+import unittest
+import tempfile
+import os
+
+os.environ['GI_SCANNER_DISABLE_CACHE'] = '1'
+
+from giscanner import ast
+from giscanner.sourcescanner import SourceScanner
+from giscanner.transformer import Transformer
+from giscanner.annotationparser import GtkDocCommentBlockParser
+from giscanner.maintransformer import MainTransformer
+
+
+def create_scanner_from_source_string(source):
+ ss = SourceScanner()
+ tmp_fd, tmp_name = tempfile.mkstemp(suffix='.h', text=True)
+
+ try:
+ with os.fdopen(tmp_fd, 'wt') as file:
+ file.write(source)
+ ss.parse_files([tmp_name])
+ finally:
+ os.unlink(tmp_name)
+
+ return ss
+
+
+def load_namespace_from_source_string(namespace, source):
+ ss = create_scanner_from_source_string(source)
+ transformer = Transformer(namespace)
+ transformer.parse(ss.get_symbols())
+ cbp = GtkDocCommentBlockParser()
+ blocks = cbp.parse_comment_blocks(ss.get_comments())
+ main = MainTransformer(transformer, blocks)
+ main.transform()
+
+
+class TestDeprecations(unittest.TestCase):
+
+ def test_record_deprecated(self):
+ namespace = ast.Namespace('Test', '1.0')
+ load_namespace_from_source_string(namespace, """
+ /** TestStruct:
+ * foo
+ * Deprecated: 1.2: something
+ */
+ typedef struct _TestStruct TestStruct;
+ """)
+
+ node = namespace.get('Struct')
+ self.assertEqual(node.doc, "foo")
+ self.assertEqual(node.deprecated, "1.2")
+ self.assertEqual(node.deprecated_doc, "something")
+
+ def test_record_deprecated_from_section(self):
+ namespace = ast.Namespace('Test', '1.0')
+ load_namespace_from_source_string(namespace, """
+ /** SECTION:teststruct
+ * foo
+ * Deprecated: 1.2: something
+ */
+ typedef struct _TestStruct TestStruct;
+ """)
+
+ node = namespace.get('Struct')
+ self.assertEqual(node.doc, "foo")
+ self.assertEqual(node.deprecated, "1.2")
+ self.assertEqual(node.deprecated_doc, "something")
+
+
+if __name__ == '__main__':
+ unittest.main()