summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2018-07-26 19:11:51 +0200
committerChristoph Reiter <reiter.christoph@gmail.com>2018-07-26 19:29:15 +0200
commit6c85b1c45460edd74395b119ebbff6a53eacec7e (patch)
tree9d958bc639c7eec5339b0e532d16be53543e28f7 /tests
parent96df6e243642ee8fe435f6d4108295d20d659b20 (diff)
downloadgobject-introspection-6c85b1c45460edd74395b119ebbff6a53eacec7e.tar.gz
tests: port offset tests to Python
Use the test executable to generate files in a temporary location and use difflib to compare their content. This removes the requirement on "diff" for the test.
Diffstat (limited to 'tests')
-rw-r--r--tests/offsets/Makefile.am10
-rwxr-xr-xtests/offsets/test_offsets.py47
2 files changed, 52 insertions, 5 deletions
diff --git a/tests/offsets/Makefile.am b/tests/offsets/Makefile.am
index 0df9c151..fa1c1001 100644
--- a/tests/offsets/Makefile.am
+++ b/tests/offsets/Makefile.am
@@ -41,7 +41,9 @@ gitestoffsets_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS)
gitestoffsets.c: gen-gitestoffsets offsets.h Offsets-1.0.typelib
$(AM_V_GEN) $(PYTHON) $(srcdir)/gen-gitestoffsets $(srcdir)/offsets.h > $@ || ( rm -f $@ && false )
-EXTRA_DIST += gen-gitestoffsets
+EXTRA_DIST += \
+ gen-gitestoffsets \
+ test_offsets.py
BUILT_SOURCES += gitestoffsets.c
CLEANFILES += gitestoffsets.c $(EXTRA_PROGRAMS)
@@ -50,7 +52,5 @@ CLEANFILES += gitestoffsets.c $(EXTRA_PROGRAMS)
# The trailing "echo" in LOG_COMPILER is used to ignore automake passing
# gitestoffsets as we already run this in the same command line.
TESTS = gitestoffsets
-LOG_COMPILER = env GI_TYPELIB_PATH=:$(top_builddir) ./gitestoffsets$(EXEEXT) offsets.compiled offsets.introspected && \
- diff -u offsets.compiled offsets.introspected && echo
-
-CLEANFILES += offsets.compiled offsets.introspected
+TESTS_ENVIRONMENT = env top_builddir=$(top_builddir) builddir=$(builddir)
+LOG_COMPILER = $(PYTHON) $(srcdir)/test_offsets.py && echo
diff --git a/tests/offsets/test_offsets.py b/tests/offsets/test_offsets.py
new file mode 100755
index 00000000..db10f1c4
--- /dev/null
+++ b/tests/offsets/test_offsets.py
@@ -0,0 +1,47 @@
+import io
+import os
+import tempfile
+import difflib
+import contextlib
+import subprocess
+import unittest
+
+
+@contextlib.contextmanager
+def temp_filename(*args, **kwargs):
+ fd, name = tempfile.mkstemp(*args, **kwargs)
+ try:
+ os.close(fd)
+ yield name
+ finally:
+ os.unlink(name)
+
+
+class TestOffsets(unittest.TestCase):
+
+ def test_main(self):
+ gitestoffsets = os.path.join(os.environ["builddir"], "gitestoffsets")
+
+ env = os.environ.copy()
+ env["GI_TYPELIB_PATH"] = os.pathsep.join(
+ [os.environ["builddir"], os.environ["top_builddir"]])
+
+ with temp_filename(suffix=".compiled") as compiled_name, \
+ temp_filename(suffix=".introspected") as introspected_name:
+
+ subprocess.check_call(
+ [gitestoffsets, compiled_name, introspected_name], env=env)
+
+ with io.open(compiled_name, encoding="utf-8") as compiled, \
+ io.open(introspected_name, encoding="utf-8") as introspected:
+
+ result = difflib.unified_diff(
+ compiled.readlines(), introspected.readlines(),
+ fromfile=compiled_name, tofile=introspected_name)
+ result = "".join(result)
+ if result:
+ raise AssertionError(result)
+
+
+if __name__ == '__main__':
+ unittest.main()