mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-22 18:22:11 +01:00
girepository/tests: Add tests on compiler open/write failures
This commit is contained in:
parent
26890fbb82
commit
bf9ea337a2
81
girepository/tests/gi-compile-repository.py
Normal file
81
girepository/tests/gi-compile-repository.py
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright © 2025 Marco Trevisan <mail@3v1n0.net>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
#
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
|
""" Integration tests for gi-compile-repository. """
|
||||||
|
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import taptestrunner
|
||||||
|
import testprogramrunner
|
||||||
|
|
||||||
|
|
||||||
|
class TestGICompileRepositoryBase(testprogramrunner.TestProgramRunner):
|
||||||
|
"""Integration test for checking gi-compile-repository behavior"""
|
||||||
|
|
||||||
|
PROGRAM_NAME = "gi-compile-repository"
|
||||||
|
PROGRAM_TYPE = testprogramrunner.ProgramType.NATIVE
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
|
||||||
|
if "G_TEST_BUILDDIR" in os.environ:
|
||||||
|
cls._gir_path = os.path.join(
|
||||||
|
os.environ["G_TEST_BUILDDIR"], "..", "introspection"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
cls._gir_path = os.path.join(
|
||||||
|
os.path.dirname(os.path.realpath(__file__)),
|
||||||
|
"..",
|
||||||
|
"..",
|
||||||
|
"..",
|
||||||
|
"share",
|
||||||
|
"gir-1.0",
|
||||||
|
)
|
||||||
|
print(f"gir path set to {cls._gir_path}")
|
||||||
|
|
||||||
|
def test_open_failure(self):
|
||||||
|
gir_path = "this-is/not/a-file.gir"
|
||||||
|
result = self.runTestProgram(
|
||||||
|
[gir_path, "--output", os.path.join(self.tmpdir.name, "invalid.typelib")],
|
||||||
|
should_fail=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(result.info.returncode, 1)
|
||||||
|
self.assertIn(f"Error parsing file ‘{gir_path}’", result.err)
|
||||||
|
|
||||||
|
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],
|
||||||
|
should_fail=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(result.info.returncode, 1)
|
||||||
|
self.assertIn(f"Failed to open ‘{typelib_path}.tmp’", result.err)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main(testRunner=taptestrunner.TAPTestRunner())
|
@ -161,3 +161,76 @@ foreach test_name, extra_args : girepository_tests
|
|||||||
should_fail: extra_args.get('should_fail', false),
|
should_fail: extra_args.get('should_fail', false),
|
||||||
)
|
)
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
|
python_tests = {}
|
||||||
|
|
||||||
|
if enable_gir
|
||||||
|
python_tests += {
|
||||||
|
'gi-compile-repository.py': {
|
||||||
|
'depends': [gicompilerepository, glib_gir[0]],
|
||||||
|
'env': {
|
||||||
|
'_G_TEST_PROGRAM_RUNNER_PATH': fs.parent(gicompilerepository.full_path()),
|
||||||
|
},
|
||||||
|
'suite': ['compiler'],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
endif
|
||||||
|
|
||||||
|
python_test_env = test_env
|
||||||
|
python_test_env.prepend('PYTHONPATH', python_test_libraries_path)
|
||||||
|
|
||||||
|
foreach test_name, extra_args : python_tests
|
||||||
|
depends = [extra_args.get('depends', [])]
|
||||||
|
suite = ['girepository', 'no-valgrind'] + extra_args.get('suite', [])
|
||||||
|
|
||||||
|
if extra_args.get('can_fail', false)
|
||||||
|
suite += 'failing'
|
||||||
|
endif
|
||||||
|
|
||||||
|
local_test_env = python_test_env
|
||||||
|
foreach var, value : extra_args.get('env', {})
|
||||||
|
local_test_env.append(var, value)
|
||||||
|
endforeach
|
||||||
|
|
||||||
|
test(
|
||||||
|
test_name,
|
||||||
|
python,
|
||||||
|
protocol : extra_args.get('protocol', test_protocol),
|
||||||
|
depends: depends,
|
||||||
|
args: ['-B', files(test_name)],
|
||||||
|
env: local_test_env,
|
||||||
|
suite: suite,
|
||||||
|
)
|
||||||
|
|
||||||
|
if installed_tests_enabled
|
||||||
|
install_data(
|
||||||
|
files(test_name),
|
||||||
|
install_dir: installed_tests_execdir,
|
||||||
|
install_tag: 'tests',
|
||||||
|
install_mode: 'rwxr-xr-x',
|
||||||
|
)
|
||||||
|
|
||||||
|
test_conf = configuration_data()
|
||||||
|
test_conf.set('installed_tests_dir', installed_tests_execdir)
|
||||||
|
test_conf.set('program', test_name)
|
||||||
|
|
||||||
|
test_env_override = ''
|
||||||
|
installed_tests_env = extra_args.get('installed_tests_env', {})
|
||||||
|
if installed_tests_env != {}
|
||||||
|
envs = []
|
||||||
|
foreach var, value : installed_tests_env
|
||||||
|
envs += '@0@="@1@"'.format(var, value)
|
||||||
|
endforeach
|
||||||
|
test_env_override = '@0@ @1@ '.format(env_program.full_path(), ' '.join(envs))
|
||||||
|
endif
|
||||||
|
test_conf.set('env', test_env_override)
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
input: installed_tests_template_tap,
|
||||||
|
output: test_name + '.test',
|
||||||
|
install_dir: installed_tests_metadir,
|
||||||
|
install_tag: 'tests',
|
||||||
|
configuration: test_conf,
|
||||||
|
)
|
||||||
|
endif
|
||||||
|
endforeach
|
||||||
|
Loading…
x
Reference in New Issue
Block a user