1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
# Copyright 2013 Shuxiong Ye <yeshuxiong@gmail.com>
#
# 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
import unittest
import os
from firehose.parsers import findbugs# import parse_warning, parse_file
from firehose.model import Analysis, Issue, Location, File, Point, \
Function, Message, Sut, Metadata, Generator
FAKE_SUT = Sut()
def readRawData(filePath):
f = open(filePath, "r")
ret = f.readlines()
f.close()
return ret
class TestParseFile(unittest.TestCase):
def _run_testdata(self, xmlFileName, answer, isDebug=False):
path = os.path.join(os.path.dirname(__file__), "example-output",
"findbugs", xmlFileName)
analysis = findbugs.parse_file(path)
self.assertIsInstance(analysis, Analysis)
self.assertNotEqual(analysis.results, None)
if isDebug:
print(len(analysis.results), len(answer))
self.assertEqual(len(analysis.results), len(answer))
for i in range(0, len(analysis.results)):
ret = analysis.results[i]
self.assertIsInstance(ret, Issue)
self.assertIsInstance(ret.location, Location)
self.assertEqual(ret.location.line, answer[i][0])
if answer[i][1]:
self.assertIsInstance(ret.location.function, Function)
self.assertEqual(ret.location.function.name, answer[i][1])
else:
self.assertEqual(ret.location.function, None)
self.assertIsInstance(ret.location.file, File)
self.assertEqual(ret.location.file.givenpath, answer[i][2])
def test_testdata_jformatstring(self):
answer = [
[66, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterCompileTimeTest.testBug1874856FalsePositive()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterCompileTimeTest.java"],
[89, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterCompileTimeTest.testBug1874856TruePositive()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterCompileTimeTest.java"],
[19, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testShouldWork()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[52, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testFormatDateWithY()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[36, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testNotEnoughParameters()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[28, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testStringWhereIntegerExpected()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[88, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testDateMismatch()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[28, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testStringWhereIntegerExpected()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[43, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testPassingAnArray()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[47, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testPassingAnIntToABoolean()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[52, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testFormatDateWithY()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[36, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testNotEnoughParameters()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[78, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testBug1874856TruePositive()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[88, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testDateMismatch()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[21, "edu.umd.cs.findbugs.formatStringChecker"+
".FormatterRuntimeTest.testShouldWork()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"],
[22, "edu.umd.cs.findbugs.formatStringChecker."+
"FormatterRuntimeTest.testShouldWork()",
"edu/umd/cs/findbugs/formatStringChecker/"+
"FormatterRuntimeTest.java"]
]
self._run_testdata("findbugs_jformatstring.xml", answer)
def test_testdata_example(self):
answer = [
[8, "O0.<static initializer for O0>()", "O0.java"],
[13, "new O0()", "O0.java"],
[18, "O0.bugs()", "O0.java"],
[23, "O0.main(String[])", "O0.java"],
[9, "l1.O1.<static initializer for O1>()", "l1/O1.java"],
[14, "new l1.O1()", "l1/O1.java"],
[19, "l1.O1.bugs()", "l1/O1.java"],
[24, "l1.O1.main(String[])", "l1/O1.java"],
[9, "l1.l2.O2.<static initializer for O2>()",
"l1/l2/O2.java"],
[14, "new l1.l2.O2()", "l1/l2/O2.java"],
[19, "l1.l2.O2.bugs()", "l1/l2/O2.java"],
[24, "l1.l2.O2.main(String[])", "l1/l2/O2.java"],
]
self._run_testdata("findbugs_Example.xml", answer)
def test_testdata_no_method(self):
answer = [
[77, None, "com/clearspring/ircbot/trac/TracRpc.java"],
]
self._run_testdata("findbugs_no_method.xml", answer)
|