Skip to content

Commit

Permalink
detectors.py fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
choller committed Apr 13, 2012
1 parent 925b49d commit 8a0bacf
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions detect/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ class Detector:
def __init__(self):
pass

def readIgnoreLists(self, knownPath, filename, readerFunction):
while os.path.basename(knownPath) != "known":
filename = os.path.join(knownPath, filename)
if os.path.exists(filename):
readerFunction(filename)
knownPath = os.path.dirname(os.path.dirname(filename))
def readIgnoreLists(self, knownPath, baseFilename, readerFunction):
currentPath = knownPath
while os.path.basename(currentPath) != "known":
filename = os.path.join(currentPath, baseFilename)
if os.path.exists(filename):
readerFunction(filename)
currentPath = os.path.dirname(os.path.dirname(filename))

# Recognizes NS_ASSERTIONs based on condition, text, and filename (ignoring irrelevant parts of the path)
# Recognizes JS_ASSERT based on condition only :(
# Recognizes ObjC exceptions based on message, since there is no stack information available, at least on Tiger.
class AssertionDetector(Detector):
def __init__(self, knownPath):
self.simpleAssertionsIgnoreList = []
self.twoPartAssertionsIgnoreList = []
self.simpleIgnoreList = []
self.twoPartIgnoreList = []
self.readIgnoreLists(knownPath, "assertions.txt", self.readAssertionsIgnoreList)
print "detect_assertions is ready (ignoring %d strings without filenames and %d strings with filenames)" % (len(self.simpleIgnoreList), len(self.twoPartIgnoreList))

Expand All @@ -47,17 +48,19 @@ def scanLineAssertions(self, line):

return False

def scanFileAssertions(self, currentFile, verbose, ignoreKnownAssertions):
def scanFileAssertions(self, currentFile, verbose, ignoreKnownAssertions, lineFilter=None):
foundSomething = False

# map from (assertion message) to (true, if seen in the current file)
seenInCurrentFile = {}

for line in currentFile:
line = line.strip("\x07").rstrip("\n")
if (lineFilter != None):
line = lineFilter(line)
if (self.hasAssertion(line) and not (line in seenInCurrentFile)):
seenInCurrentFile[line] = True
if not (self.ignore(line)):
if not (self.ignoreAssertion(line)):
print "! New assertion: "
print line
foundSomething = True
Expand Down

0 comments on commit 8a0bacf

Please sign in to comment.