From 6160747fe58e6334e762297b6e4b04e41cf0716e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 24 May 2024 17:05:48 +0200 Subject: [PATCH] girepository/tests: Add tests for the compiler basic operations Adding some initial test for the compiler behavior and its expected output. Also, when using sanitizers we want to be able to test the compiler memory management. --- girepository/tests/gi-compile-repository.py | 44 +++++++++++++++++++-- girepository/tests/meson.build | 4 +- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/girepository/tests/gi-compile-repository.py b/girepository/tests/gi-compile-repository.py index 12ff195ce..a0b2bcf7e 100644 --- a/girepository/tests/gi-compile-repository.py +++ b/girepository/tests/gi-compile-repository.py @@ -30,7 +30,7 @@ import testprogramrunner class TestGICompileRepositoryBase(testprogramrunner.TestProgramRunner): - """Integration test for checking gi-compile-repository behavior""" + """Integration test base class for checking gi-compile-repository behavior""" PROGRAM_NAME = "gi-compile-repository" PROGRAM_TYPE = testprogramrunner.ProgramType.NATIVE @@ -54,6 +54,10 @@ class TestGICompileRepositoryBase(testprogramrunner.TestProgramRunner): ) print(f"gir path set to {cls._gir_path}") + +class TestGICompileRepository(TestGICompileRepositoryBase): + """Integration test for checking gi-compile-repository behavior""" + def test_open_failure(self): gir_path = "this-is/not/a-file.gir" result = self.runTestProgram( @@ -64,18 +68,50 @@ class TestGICompileRepositoryBase(testprogramrunner.TestProgramRunner): self.assertEqual(result.info.returncode, 1) self.assertIn(f"Error parsing file ‘{gir_path}’", result.err) + +class TestGICompileRepositoryForGLib(TestGICompileRepositoryBase): + GIR_NAME = "GLib-2.0" + + def runTestProgram(self, *args, **kwargs): + gir_file = os.path.join(self._gir_path, f"{self.GIR_NAME}.gir") + self.assertTrue(os.path.exists(gir_file)) + argv = [gir_file] + argv.extend(*args) + + if self.GIR_NAME != "GLib-2.0": + argv.extend(["--includedir", self._gir_path]) + + return super().runTestProgram(argv, **kwargs) + def test_write_failure(self): typelib_path = "this-is/not/a-good-output/invalid.typelib" - glib_gir = os.path.join(self._gir_path, "GLib-2.0.gir") - self.assertTrue(os.path.exists(glib_gir)) result = self.runTestProgram( - [glib_gir, "--output", typelib_path], + ["--output", typelib_path], should_fail=True, ) self.assertEqual(result.info.returncode, 1) self.assertIn(f"Failed to open ‘{typelib_path}.tmp’", result.err) + def test_compile(self): + typelib_name = os.path.splitext(self.GIR_NAME)[0] + typelib_path = os.path.join(self.tmpdir.name, f"{typelib_name}.typelib") + argv = ["--output", typelib_path] + + result = self.runTestProgram(argv) + + self.assertFalse(result.out) + self.assertFalse(result.err) + self.assertTrue(os.path.exists(typelib_path)) + + +class TestGICompileRepositoryForGObject(TestGICompileRepositoryForGLib): + GIR_NAME = "GObject-2.0" + + +class TestGICompileRepositoryForGio(TestGICompileRepositoryForGLib): + GIR_NAME = "Gio-2.0" + if __name__ == "__main__": unittest.main(testRunner=taptestrunner.TAPTestRunner()) diff --git a/girepository/tests/meson.build b/girepository/tests/meson.build index eb0d73930..778d86392 100644 --- a/girepository/tests/meson.build +++ b/girepository/tests/meson.build @@ -167,7 +167,7 @@ python_tests = {} if enable_gir python_tests += { 'gi-compile-repository.py': { - 'depends': [gicompilerepository, glib_gir[0]], + 'depends': [gicompilerepository, glib_gir[0], gobject_gir[0], gio_gir[0]], 'env': { '_G_TEST_PROGRAM_RUNNER_PATH': fs.parent(gicompilerepository.full_path()), }, @@ -203,6 +203,8 @@ foreach test_name, extra_args : python_tests ) if installed_tests_enabled + installed_tests_env = extra_args.get('installed_tests_env', {}) + install_data( files(test_name), install_dir: installed_tests_execdir,