diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7c2ee000..3c68ef7a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -99,15 +99,6 @@ jobs: if: matrix.os == 'macos-12' run: | wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/5d937e938f7b882a3a3e7941e68f8312d0898aaf2082e00003dd362b1ba70b98b0a08706a1be28e71652a6a0f1e66f89768b5eaa20e5a100592d5b3deefec3f0/download | tar zxf - -C ~/ - - name: Setup castxml config - if: matrix.compiler == 'gcc' && matrix.version == '9' - run: mv unittests/configs/gcc9.cfg unittests/xml_generator.cfg; - - name: Run legacy tests - run: | - export PATH=~/castxml/bin:$PATH - coverage run -m unittests.test_all - coverage combine - coverage xml - name: Run tests run: | export PATH=~/castxml/bin:$PATH diff --git a/unittests/gccxml10184_tester.py b/tests/test_gccxml10184.py similarity index 100% rename from unittests/gccxml10184_tester.py rename to tests/test_gccxml10184.py diff --git a/unittests/gccxml10185_tester.py b/tests/test_gccxml10185.py similarity index 100% rename from unittests/gccxml10185_tester.py rename to tests/test_gccxml10185.py diff --git a/tests/test_parser_raise.py b/tests/test_parser_raise.py new file mode 100644 index 00000000..8181610a --- /dev/null +++ b/tests/test_parser_raise.py @@ -0,0 +1,18 @@ +# Copyright 2014-2017 Insight Software Consortium. +# Copyright 2004-2009 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt + +import os +import pytest + +from . import autoconfig + +from pygccxml import parser + + +def test_raise(): + config = autoconfig.cxx_parsers_cfg.config.clone() + content = "abra cadabra " + os.linesep + with pytest.raises(RuntimeError) as _: + parser.parse_string(content, config) diff --git a/tests/test_patcher.py b/tests/test_patcher.py new file mode 100644 index 00000000..336e57d2 --- /dev/null +++ b/tests/test_patcher.py @@ -0,0 +1,161 @@ +# Copyright 2014-2017 Insight Software Consortium. +# Copyright 2004-2009 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt + +import pytest + +from . import autoconfig + +from pygccxml import declarations +from pygccxml import parser +from pygccxml import utils + + +TEST_FILES = [ + "patcher.hpp", +] + +config = autoconfig.cxx_parsers_cfg.config.clone() +project_reader = parser.project_reader_t(config=config, cache=None) +decls = project_reader.read_files( + TEST_FILES, + parser.COMPILATION_MODE.ALL_AT_ONCE +) +config.xml_generator_from_xml_file = project_reader.xml_generator_from_xml_file +config.__cxx_std = utils.cxx_standard(config.cflags) + + +@pytest.fixture +def global_ns(): + global_ns = declarations.get_global_namespace(decls) + return global_ns + + +def test_enum_patcher(global_ns): + fix_enum = global_ns.free_function("fix_enum") + default_val = fix_enum.arguments[0].default_value + if config.__cxx_std.is_cxx11_or_greater: + val = "::ns1::ns2::fruit::apple" + else: + val = "::ns1::ns2::apple" + assert default_val == val + + fix_enum2 = global_ns.free_function("fix_enum2") + default_val = fix_enum2.arguments[0].default_value + assert default_val == val + + ns1 = global_ns.namespace("ns1") + ns2 = ns1.namespace("ns2") + fix_enum2 = ns2.free_function("fix_enum2") + default_val = fix_enum2.arguments[0].default_value + assert default_val == val + + fix_enum3 = global_ns.free_function("fix_enum3") + default_val = fix_enum3.arguments[0].default_value + val = val.replace("apple", "orange") + assert default_val == val + + if config.__cxx_std.is_cxx11_or_greater: + fix_enum4 = global_ns.free_function("fix_enum4") + default_val = fix_enum4.arguments[0].default_value + assert default_val == "::ns4::color::blue" + + fix_enum5 = global_ns.free_function("fix_enum5") + default_val = fix_enum5.arguments[0].default_value + assert default_val == "::ns4::color::blue" + + lpe = global_ns.free_function("log_priority_enabled") + default_val = lpe.arguments[0].default_value + if config.__cxx_std.is_cxx11_or_greater: + val = "(long int)" + \ + "(::ACE_Log_Priority_Index::LM_INVALID_BIT_INDEX)" + else: + val = "(long int)(::LM_INVALID_BIT_INDEX)" + assert default_val == val + + +def test_numeric_patcher(global_ns): + fix_numeric = global_ns.free_function("fix_numeric") + generator = config.xml_generator_from_xml_file + if generator.is_castxml1 or \ + float(generator.xml_output_version) >= 1.137: + val = "(unsigned long long)-1" + else: + val = "(ull)-1" + assert fix_numeric.arguments[0].default_value == val + + +def test_unqualified_integral_patcher(global_ns): + # For this check to be removed, patcher_tester_64bit.xml + # will need to be updated for CastXML + return + + ns1 = global_ns.namespace("ns1") + st1 = ns1.class_("st1") + fun1 = st1.member_function("fun1") + output_verion = xml_generator_from_xml_file.xml_output_version + if xml_generator_from_xml_file.is_castxml1 or \ + float(output_verion) >= 1.137: + val1 = "ns1::DEFAULT_1" + val2 = "ns1::st1::DEFAULT_2" + else: + val1 = "::ns1::DEFAULT_1" + val2 = "::ns1::st1::DEFAULT_2" + assertEqual( + fun1.arguments[0].default_value, val1) + assertEqual( + fun1.arguments[1].default_value, val2) + + fun2 = global_ns.free_function("fun2") + assertEqual( + fun2.arguments[0].default_value, + "::DEFAULT_1") + output_verion = xml_generator_from_xml_file.xml_output_version + if xml_generator_from_xml_file.is_castxml1 or \ + float(output_verion) >= 1.137: + val1 = "ns1::DEFAULT_1" + val2 = "ns1::st1::DEFAULT_2" + else: + # Before XML output version 1.137, the following two + # were unpatched and were identical to the text in + # matcher.hpp + val1 = "ns1::DEFAULT_1" + val2 = "::ns1::st1::DEFAULT_2" + assertEqual( + fun2.arguments[1].default_value, val1) + assertEqual( + fun2.arguments[2].default_value, val2) + + +def test_unnamed_enum_patcher(global_ns): + fix_unnamed = global_ns.free_function("fix_unnamed") + assert fix_unnamed.arguments[0].default_value == "int(::fx::unnamed)" + + +def test_function_call_patcher(global_ns): + fix_function_call = global_ns.free_function("fix_function_call") + default_val = fix_function_call.arguments[0].default_value + output_verion = config.xml_generator_from_xml_file.xml_output_version + if config.xml_generator_from_xml_file.is_castxml1 or \ + float(output_verion) >= 1.137: + val = "function_call::calc(1, 2, 3)" + else: + val = "calc(1, 2, 3)" + assert default_val == val + + +def test_fundamental_patcher(global_ns): + fcall = global_ns.free_function("fix_fundamental") + if config.__cxx_std.is_cxx11_or_greater: + val = "(unsigned int)(::fundamental::spam::eggs)" + else: + val = "(unsigned int)(::fundamental::eggs)" + assert fcall.arguments[0].default_value == val + + +def test_constructor_patcher(global_ns): + typedef__func = global_ns.free_function("typedef__func") + default_val = typedef__func.arguments[0].default_value + val = "typedef_::alias()" + assert default_val == val diff --git a/unittests/vector_traits_tester.py b/tests/test_vector_traits.py similarity index 100% rename from unittests/vector_traits_tester.py rename to tests/test_vector_traits.py diff --git a/unittests/gccxml_runner_tester.py b/unittests/gccxml_runner_tester.py deleted file mode 100644 index 423c1c40..00000000 --- a/unittests/gccxml_runner_tester.py +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2014-2017 Insight Software Consortium. -# Copyright 2004-2009 Roman Yakovenko. -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt - -import os -import unittest - -from . import parser_test_case - -from pygccxml import parser - - -class Test(parser_test_case.parser_test_case_t): - COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE - - def __init__(self, *args): - parser_test_case.parser_test_case_t.__init__(self, *args) - self.content = "abra cadabra " + os.linesep - - def test_gccxml_on_input_with_errors(self): - self.assertRaises( - RuntimeError, - parser.parse_string, - self.content, - self.config) - - -def create_suite(): - suite = unittest.TestSuite() - suite.addTest( - unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test)) - return suite - - -def run_suite(): - unittest.TextTestRunner(verbosity=2).run(create_suite()) - - -if __name__ == "__main__": - run_suite() diff --git a/unittests/patcher_tester.py b/unittests/patcher_tester.py deleted file mode 100644 index a0369d82..00000000 --- a/unittests/patcher_tester.py +++ /dev/null @@ -1,240 +0,0 @@ -# Copyright 2014-2017 Insight Software Consortium. -# Copyright 2004-2009 Roman Yakovenko. -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt - -import os -import unittest -import platform - -from . import autoconfig -from . import parser_test_case - -from pygccxml import utils -from pygccxml import parser - - -class tester_impl_t(parser_test_case.parser_test_case_t): - - def __init__(self, architecture, *args): - parser_test_case.parser_test_case_t.__init__(self, *args) - self.architecture = architecture - self.global_ns = None - self.__cxx_std = utils.cxx_standard(self.config.cflags) - - def test_enum_patcher(self): - fix_enum = self.global_ns.free_function("fix_enum") - default_val = fix_enum.arguments[0].default_value - if self.__cxx_std.is_cxx11_or_greater: - val = "::ns1::ns2::fruit::apple" - else: - val = "::ns1::ns2::apple" - self.assertEqual(default_val, val) - - if 32 == self.architecture or \ - self.xml_generator_from_xml_file.is_castxml: - fix_enum2 = self.global_ns.free_function("fix_enum2") - default_val = fix_enum2.arguments[0].default_value - self.assertEqual(default_val, val) - - ns1 = self.global_ns.namespace("ns1") - ns2 = ns1.namespace("ns2") - fix_enum2 = ns2.free_function("fix_enum2") - default_val = fix_enum2.arguments[0].default_value - self.assertEqual(default_val, val) - - fix_enum3 = self.global_ns.free_function("fix_enum3") - default_val = fix_enum3.arguments[0].default_value - val = val.replace("apple", "orange") - self.assertEqual(default_val, val) - - if self.__cxx_std.is_cxx11_or_greater: - fix_enum4 = self.global_ns.free_function("fix_enum4") - default_val = fix_enum4.arguments[0].default_value - self.assertEqual(default_val, "::ns4::color::blue") - - fix_enum5 = self.global_ns.free_function("fix_enum5") - default_val = fix_enum5.arguments[0].default_value - self.assertEqual(default_val, "::ns4::color::blue") - - lpe = self.global_ns.free_function("log_priority_enabled") - default_val = lpe.arguments[0].default_value - if self.__cxx_std.is_cxx11_or_greater: - val = "(long int)" + \ - "(::ACE_Log_Priority_Index::LM_INVALID_BIT_INDEX)" - else: - val = "(long int)(::LM_INVALID_BIT_INDEX)" - self.assertEqual(default_val, val) - - def test_numeric_patcher(self): - fix_numeric = self.global_ns.free_function("fix_numeric") - if 32 == self.architecture: - val = "0xffffffffffffffff" - self.assertEqual( - fix_numeric.arguments[0].default_value, val) - else: - generator = self.xml_generator_from_xml_file - if generator.is_castxml1 or \ - float(generator.xml_output_version) >= 1.137: - val = "(unsigned long long)-1" - else: - val = "(ull)-1" - self.assertEqual( - fix_numeric.arguments[0].default_value, val) - - def test_unqualified_integral_patcher(self): - if 32 != self.architecture: - # For this check to be removed, patcher_tester_64bit.xml - # will need to be updated for CastXML - return - - ns1 = self.global_ns.namespace("ns1") - st1 = ns1.class_("st1") - fun1 = st1.member_function("fun1") - output_verion = self.xml_generator_from_xml_file.xml_output_version - if self.xml_generator_from_xml_file.is_castxml1 or \ - float(output_verion) >= 1.137: - val1 = "ns1::DEFAULT_1" - val2 = "ns1::st1::DEFAULT_2" - else: - val1 = "::ns1::DEFAULT_1" - val2 = "::ns1::st1::DEFAULT_2" - self.assertEqual( - fun1.arguments[0].default_value, val1) - self.assertEqual( - fun1.arguments[1].default_value, val2) - - fun2 = self.global_ns.free_function("fun2") - self.assertEqual( - fun2.arguments[0].default_value, - "::DEFAULT_1") - output_verion = self.xml_generator_from_xml_file.xml_output_version - if self.xml_generator_from_xml_file.is_castxml1 or \ - float(output_verion) >= 1.137: - val1 = "ns1::DEFAULT_1" - val2 = "ns1::st1::DEFAULT_2" - else: - # Before XML output version 1.137, the following two - # were unpatched and were identical to the text in - # matcher.hpp - val1 = "ns1::DEFAULT_1" - val2 = "::ns1::st1::DEFAULT_2" - self.assertEqual( - fun2.arguments[1].default_value, val1) - self.assertEqual( - fun2.arguments[2].default_value, val2) - - def test_unnamed_enum_patcher(self): - fix_unnamed = self.global_ns.free_function("fix_unnamed") - self.assertEqual( - fix_unnamed.arguments[0].default_value, "int(::fx::unnamed)") - - def test_function_call_patcher(self): - fix_function_call = self.global_ns.free_function("fix_function_call") - default_val = fix_function_call.arguments[0].default_value - output_verion = self.xml_generator_from_xml_file.xml_output_version - if self.xml_generator_from_xml_file.is_castxml1 or \ - float(output_verion) >= 1.137: - val = "function_call::calc(1, 2, 3)" - else: - val = "calc(1, 2, 3)" - self.assertEqual(default_val, val) - - def test_fundamental_patcher(self): - fcall = self.global_ns.free_function("fix_fundamental") - if self.__cxx_std.is_cxx11_or_greater: - val = "(unsigned int)(::fundamental::spam::eggs)" - else: - val = "(unsigned int)(::fundamental::eggs)" - self.assertEqual( - fcall.arguments[0].default_value, val) - - def test_constructor_patcher(self): - typedef__func = self.global_ns.free_function("typedef__func") - default_val = typedef__func.arguments[0].default_value - val = "typedef_::alias()" - self.assertEqual(default_val, val) - if 32 == self.architecture: - clone_tree = self.global_ns.free_function("clone_tree") - default_values = [ - ("vector," + - " std::allocator >,std::allocator" + - ", " + - "std::allocator > > >()"), - ("vector," + - "std::allocator >,std::allocator" + - ", " + - "std::allocator > > >((&allocator" + - ", " + - "std::allocator > >()))")] - self.assertIn( - clone_tree.arguments[0].default_value, default_values) - - -class tester_32_t(tester_impl_t): - global_ns = None - - def __init__(self, *args): - tester_impl_t.__init__(self, 32, *args) - - def setUp(self): - if not tester_32_t.global_ns: - reader = parser.source_reader_t(self.config) - tester_32_t.global_ns = reader.read_file( - "patcher.hpp")[0].top_parent - tester_32_t.xml_generator_from_xml_file = \ - reader.xml_generator_from_xml_file - self.global_ns = tester_32_t.global_ns - self.xml_generator_from_xml_file = \ - tester_32_t.xml_generator_from_xml_file - - -class tester_64_t(tester_impl_t): - global_ns = None - - def __init__(self, *args): - tester_impl_t.__init__(self, 64, *args) - self.original_get_architecture = utils.get_architecture - - def setUp(self): - self.original_get_architecture = utils.get_architecture - utils.get_architecture = lambda: 64 - - if not tester_64_t.global_ns: - reader = parser.source_reader_t(self.config) - if "castxml" not in self.config.xml_generator: - tester_64_t.global_ns = reader.read_xml_file( - os.path.join( - autoconfig.data_directory, - "patcher_tester_64bit.xml"))[0].top_parent - else: - tester_64_t.global_ns = reader.read_file( - "patcher.hpp")[0].top_parent - tester_64_t.xml_generator_from_xml_file = \ - reader.xml_generator_from_xml_file - self.global_ns = tester_64_t.global_ns - self.xml_generator_from_xml_file = \ - tester_64_t.xml_generator_from_xml_file - - def tearDown(self): - utils.get_architecture = self.original_get_architecture - - -def create_suite(): - suite = unittest.TestSuite() - if "castxml" not in autoconfig.cxx_parsers_cfg.config.xml_generator: - suite.addTest( - unittest.TestLoader().loadTestsFromTestCase( - testCaseClass=tester_32_t)) - suite.addTest( - unittest.TestLoader().loadTestsFromTestCase( - testCaseClass=tester_64_t)) - return suite - - -def run_suite(): - unittest.TextTestRunner(verbosity=2).run(create_suite()) - - -if __name__ == "__main__": - run_suite() diff --git a/unittests/test_all.py b/unittests/test_all.py deleted file mode 100644 index d7757ecb..00000000 --- a/unittests/test_all.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2014-2017 Insight Software Consortium. -# Copyright 2004-2009 Roman Yakovenko. -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt - -import os -import sys -import unittest - -from . import gccxml_runner_tester -from . import patcher_tester -from . import vector_traits_tester -from . import gccxml10184_tester -from . import gccxml10185_tester - -testers = [ - gccxml_runner_tester, - vector_traits_tester, - gccxml10184_tester, - gccxml10185_tester, - patcher_tester, -] - - -if os.path.isfile("test_cost.log"): - # Remove the cost log file when tests are run again. - # See the parser_test_case which generates this file. - os.remove("test_cost.log") # pragma: no cover - - -def create_suite(): - main_suite = unittest.TestSuite() - for tester in testers: - main_suite.addTest(tester.create_suite()) - return main_suite - - -def run_suite(): - result = unittest.TextTestRunner(verbosity=2).run(create_suite()) - error_desc = 'EXCEPTION IN SAFE SELECT 9' - all_errors = result.failures + result.errors - for test_case, description in all_errors: - if error_desc not in description: # pragma: no cover - return 1 # pragma: no cover - return 0 - - -if __name__ == "__main__": - sys.exit(run_suite())