Example #1
0
    def test_missing_file(self):  # type: () -> None
        errors = {'':
                  [CppcheckError(file='',
                                 line=0,
                                 message='Too many #ifdef configurations - cppcheck only checks '
                                         '12 configurations. Use --force to check all '
                                         'configurations. For more details, use '
                                         '--enable=information.',
                                 severity='information',
                                 error_id='toomanyconfigs',
                                 verbose='The checking of the file will be interrupted because '
                                         'there are too many #ifdef configurations. Checking of '
                                         'all #ifdef configurations can be forced by --force '
                                         'command line option or from GUI preferences. However '
                                         'that may increase the checking time. For more details, '
                                         'use --enable=information.')]}
        tree = generate_test_suite(errors)
        root = tree.getroot()
        self.assertEqual(root.get('errors'), str(1))
        self.assertEqual(root.get('failures'), str(0))
        self.assertEqual(root.get('tests'), str(1))

        test_case_element = root.find('testcase')
        self.assertEqual(test_case_element.get('name'), '')

        error_element = test_case_element.find('error')
        self.assertEqual(error_element.get('file'), '')
        self.assertEqual(error_element.get('line'), str(0))
        self.assertEqual(error_element.get('message'),
                         '0: (information) Too many #ifdef configurations - cppcheck only checks '
                         '12 configurations. Use --force to check all '
                         'configurations. For more details, use '
                         '--enable=information.')
Example #2
0
    def test_single(self):  # type: () -> None
        errors = {
            'file_name': [
                CppcheckError('file_name', 4, 'error message', 'severity',
                              'error_id', 'verbose error message')
            ]
        }
        tree = generate_test_suite(errors)
        testsuite_element = tree.getroot()
        self.assertEqual(testsuite_element.get('errors'), str(1))
        self.assertEqual(testsuite_element.get('failures'), str(0))
        self.assertEqual(testsuite_element.get('tests'), str(1))
        # Check that testsuite element is compliant with the spec
        for required_attribute in self.junit_testsuite_attributes:
            self.assertTrue(
                required_attribute in testsuite_element.attrib.keys())

        testcase_element = testsuite_element.find('testcase')
        self.assertEqual(testcase_element.get('name'), 'file_name')
        # Check that test_case is compliant with the spec
        for required_attribute in self.junit_testcase_attributes:
            self.assertTrue(
                required_attribute in testcase_element.attrib.keys())

        error_element = testcase_element.find('error')
        self.assertEqual(error_element.get('file'), 'file_name')
        self.assertEqual(error_element.get('line'), str(4))
        self.assertEqual(error_element.get('message'),
                         '4: (severity) error message')
        # Check that error element is compliant with the spec
        for required_attribute in self.junit_error_attributes:
            self.assertTrue(required_attribute in error_element.attrib.keys())
Example #3
0
    def test_missing_file(self):  # type: () -> None
        errors = {
            '': [
                CppcheckError(
                    file='',
                    line=0,
                    message=
                    'Too many #ifdef configurations - cppcheck only checks '
                    '12 configurations. Use --force to check all '
                    'configurations. For more details, use '
                    '--enable=information.',
                    severity='information',
                    error_id='toomanyconfigs',
                    verbose=
                    'The checking of the file will be interrupted because '
                    'there are too many #ifdef configurations. Checking of '
                    'all #ifdef configurations can be forced by --force '
                    'command line option or from GUI preferences. However '
                    'that may increase the checking time. For more details, '
                    'use --enable=information.')
            ]
        }
        tree = generate_test_suite(errors)
        testsuite_element = tree.getroot()
        self.assertEqual(testsuite_element.get('errors'), str(1))
        self.assertEqual(testsuite_element.get('failures'), str(0))
        self.assertEqual(testsuite_element.get('tests'), str(1))
        # Check that testsuite element is compliant with the spec
        for required_attribute in self.junit_testsuite_attributes:
            self.assertTrue(
                required_attribute in testsuite_element.attrib.keys())

        testcase_element = testsuite_element.find('testcase')
        self.assertEqual(testcase_element.get('name'), 'Cppcheck error')
        self.assertEqual(testcase_element.get('classname'), 'Cppcheck error')
        # Check that test_case is compliant with the spec
        for required_attribute in self.junit_testcase_attributes:
            self.assertTrue(
                required_attribute in testcase_element.attrib.keys())

        error_element = testcase_element.find('error')
        self.assertEqual(error_element.get('file'), '')
        self.assertEqual(error_element.get('line'), str(0))
        self.assertEqual(
            error_element.get('message'),
            '0: (information) Too many #ifdef configurations - cppcheck only checks '
            '12 configurations. Use --force to check all '
            'configurations. For more details, use '
            '--enable=information.')
        # Check that error element is compliant with the spec
        for required_attribute in self.junit_error_attributes:
            self.assertTrue(required_attribute in error_element.attrib.keys())
Example #4
0
    def test_single(self):  # type: () -> None
        errors = {'file_name':
                  [CppcheckError('file_name',
                                 4,
                                 'error message',
                                 'severity',
                                 'error_id',
                                 'verbose error message')]}
        tree = generate_test_suite(errors)
        root = tree.getroot()
        self.assertEqual(root.get('errors'), str(1))
        self.assertEqual(root.get('failures'), str(0))
        self.assertEqual(root.get('tests'), str(1))

        test_case_element = root.find('testcase')
        self.assertEqual(test_case_element.get('name'), 'file_name')

        error_element = test_case_element.find('error')
        self.assertEqual(error_element.get('file'), 'file_name')
        self.assertEqual(error_element.get('line'), str(4))
        self.assertEqual(error_element.get('message'), '4: (severity) error message')