Esempio n. 1
0
    def test_all(self):  # type: () -> None
        file1 = 'bad.cpp'
        file2 = 'bad2.cpp'
        errors = parse_cppcheck('tests/cppcheck-out-all.xml')

        self.assertEqual(errors[file1][0].file, file1)
        self.assertEqual(errors[file1][0].line, 4)
        self.assertEqual(
            errors[file1][0].message,
            "Variable 'a' is assigned a value that is never used.")

        self.assertEqual(errors[file1][1].file, file1)
        self.assertEqual(errors[file1][1].line, 4)
        self.assertEqual(
            errors[file1][1].message,
            "Array 'a[10]' accessed at index 10, which is out of bounds.")

        self.assertEqual(errors[file2][0].file, file2)
        self.assertEqual(errors[file2][0].line, 4)
        self.assertEqual(
            errors[file2][0].message,
            "Variable 'a' is assigned a value that is never used.")

        self.assertEqual(errors[file2][1].file, file2)
        self.assertEqual(errors[file2][1].line, 4)
        self.assertEqual(
            errors[file2][1].message,
            "Array 'a[10]' accessed at index 10, which is out of bounds.")
Esempio n. 2
0
    def test_missing_include_no_location_element(self):  # type: () -> None
        file = ''
        errors = parse_cppcheck('tests/cppcheck-out-missing-include-no-location-element.xml')

        self.assertEqual(len(errors), 1)
        error = errors[file][0]
        self.assertEqual(error.file, file)
        self.assertEqual(error.line, 0)
        self.assertEqual(
            error.message,
            'Cppcheck cannot find all the include files (use --check-config for details)')
        self.assertEqual(error.severity, 'information')
Esempio n. 3
0
    def test_bad(self):  # type: () -> None
        file1 = 'bad.cpp'
        errors = parse_cppcheck('tests/cppcheck-out-bad.xml')

        self.assertEqual(errors[file1][0].file, file1)
        self.assertEqual(errors[file1][0].line, 4)
        self.assertEqual(errors[file1][0].message,
                         "Variable 'a' is assigned a value that is never used.")

        self.assertEqual(errors[file1][1].file, file1)
        self.assertEqual(errors[file1][1].line, 4)
        self.assertEqual(errors[file1][1].message,
                         "Array 'a[10]' accessed at index 10, which is out of bounds.")
Esempio n. 4
0
    def test_no_location_element(self):  # type: () -> None
        file = ''
        errors = parse_cppcheck('tests/cppcheck-out-no-location-element.xml')

        self.assertEqual(len(errors), 1)
        error = errors[file][0]
        self.assertEqual(error.file, file)
        self.assertEqual(error.line, 0)
        self.assertEqual(
            error.message,
            'Too many #ifdef configurations - cppcheck only checks 12 configurations. '
            'Use --force to check all configurations. For more details, use '
            '--enable=information.')
        self.assertEqual(error.severity, 'information')
Esempio n. 5
0
    def test_missing_include_no_location_element(self):  # type: () -> None
        file = ''
        errors = parse_cppcheck(
            'tests/cppcheck-out-missing-include-no-location-element.xml')

        self.assertEqual(len(errors), 1)
        error = errors[file][0]
        self.assertEqual(error.file, file)
        self.assertEqual(error.line, 0)
        self.assertEqual(
            error.message,
            'Cppcheck cannot find all the include files (use --check-config for details)'
        )
        self.assertEqual(error.severity, 'information')
Esempio n. 6
0
    def test_no_location_element(self):  # type: () -> None
        file = ''
        errors = parse_cppcheck('tests/cppcheck-out-no-location-element.xml')

        self.assertEqual(len(errors), 1)
        error = errors[file][0]
        self.assertEqual(error.file, file)
        self.assertEqual(error.line, 0)
        self.assertEqual(
            error.message,
            'Too many #ifdef configurations - cppcheck only checks 12 configurations. '
            'Use --force to check all configurations. For more details, use '
            '--enable=information.')
        self.assertEqual(error.severity, 'information')
Esempio n. 7
0
 def test_malformed(self):  # type: () -> None
     with self.assertRaises(ElementTree.ParseError):
         parse_cppcheck('tests/cppcheck-out-malformed.xml')
Esempio n. 8
0
 def test_file_not_found(self):  # type: () -> None
     with self.assertRaises(IOError):
         parse_cppcheck('tests/file_does_not_exist.xml')
Esempio n. 9
0
 def test_xml_version_1(self):  # type: () -> None
     with self.assertRaises(ValueError):
         parse_cppcheck('tests/cppcheck-out-bad-xml-version-1.xml')
Esempio n. 10
0
 def test_bad_large(self):    # type: () -> None
     errors = parse_cppcheck('tests/cppcheck-out-bad-large.xml')
     self.assertEqual(len(errors), 43)
Esempio n. 11
0
 def test_good(self):  # type: () -> None
     errors = parse_cppcheck('tests/cppcheck-out-good.xml')
     self.assertEqual(errors, {})
Esempio n. 12
0
 def test_xml_version_1(self):  # type: () -> None
     with self.assertRaises(ValueError):
         parse_cppcheck('tests/cppcheck-out-bad-xml-version-1.xml')
Esempio n. 13
0
 def test_bad_large(self):  # type: () -> None
     errors = parse_cppcheck('tests/cppcheck-out-bad-large.xml')
     self.assertEqual(len(errors), 43)
Esempio n. 14
0
 def test_good(self):  # type: () -> None
     errors = parse_cppcheck('tests/cppcheck-out-good.xml')
     self.assertEqual(errors, {})
Esempio n. 15
0
 def test_malformed(self):  # type: () -> None
     with self.assertRaises(ElementTree.ParseError):
         parse_cppcheck('tests/cppcheck-out-malformed.xml')
Esempio n. 16
0
 def test_file_not_found(self):  # type: () -> None
     with self.assertRaises(IOError):
         parse_cppcheck('tests/file_does_not_exist.xml')