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.")
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')
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.")
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')
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')
def test_malformed(self): # type: () -> None with self.assertRaises(ElementTree.ParseError): parse_cppcheck('tests/cppcheck-out-malformed.xml')
def test_file_not_found(self): # type: () -> None with self.assertRaises(IOError): parse_cppcheck('tests/file_does_not_exist.xml')
def test_xml_version_1(self): # type: () -> None with self.assertRaises(ValueError): parse_cppcheck('tests/cppcheck-out-bad-xml-version-1.xml')
def test_bad_large(self): # type: () -> None errors = parse_cppcheck('tests/cppcheck-out-bad-large.xml') self.assertEqual(len(errors), 43)
def test_good(self): # type: () -> None errors = parse_cppcheck('tests/cppcheck-out-good.xml') self.assertEqual(errors, {})