Skip to content

Commit

Permalink
Rewrite PerModuletest to use a LogObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Dec 31, 2013
1 parent 66698b3 commit 00344f3
Showing 1 changed file with 64 additions and 80 deletions.
144 changes: 64 additions & 80 deletions master/buildbot/steps/shell.py
Expand Up @@ -571,8 +571,6 @@ def createSummary(self, log):
# warnings regular expressions. If did, bump the warnings count and
# add the line to the collection of lines with warnings
warnings = []
# TODO: use log.readlines(), except we need to decide about stdout vs
# stderr
for line in log.getText().split("\n"):
if directoryEnterRe:
match = directoryEnterRe.search(line)
Expand Down Expand Up @@ -665,87 +663,73 @@ def describe(self, done=False):
return description


class PerlModuleTest(Test):
command = ["prove", "--lib", "lib", "-r", "t"]
total = 0

def evaluateCommand(self, cmd):
# Get stdio, stripping pesky newlines etc.
lines = map(
lambda line: line.replace('\r\n', '').replace('\r', '').replace('\n', ''),
self.getLog('stdio').readlines()
)

total = 0
passed = 0
failed = 0
rc = SUCCESS
if cmd.didFail():
rc = FAILURE

# New version of Test::Harness?
if "Test Summary Report" in lines:
test_summary_report_index = lines.index("Test Summary Report")
del lines[0:test_summary_report_index + 2]

re_test_result = re.compile(r"^Result: (PASS|FAIL)$|Tests: \d+ Failed: (\d+)\)|Files=\d+, Tests=(\d+)")

mos = map(lambda line: re_test_result.search(line), lines)
test_result_lines = [mo.groups() for mo in mos if mo]

for line in test_result_lines:
if line[0] == 'FAIL':
rc = FAILURE

if line[1]:
failed += int(line[1])
if line[2]:
total = int(line[2])

else: # Nope, it's the old version
re_test_result = re.compile(r"^(All tests successful)|(\d+)/(\d+) subtests failed|Files=\d+, Tests=(\d+),")

mos = map(lambda line: re_test_result.search(line), lines)
test_result_lines = [mo.groups() for mo in mos if mo]

if test_result_lines:
test_result_line = test_result_lines[0]
class PerlModuleTestObserver(logobserver.LogLineObserver):

success = test_result_line[0]

if success:
failed = 0

test_totals_line = test_result_lines[1]
total_str = test_totals_line[3]
else:
failed_str = test_result_line[1]
failed = int(failed_str)

total_str = test_result_line[2]

rc = FAILURE

total = int(total_str)

warnings = 0
if self.warningPattern:
wre = self.warningPattern
if isinstance(wre, str):
wre = re.compile(wre)

warnings = len([l for l in lines if wre.search(l)])
def __init__(self, warningPattern):
logobserver.LogLineObserver.__init__(self)
if warningPattern:
self.warningPattern = re.compile(warningPattern)
else:
self.warningPattern = None
self.rc = SUCCESS
self.total = 0
self.failed = 0
self.warnings = 0
self.newStyle = False
self.complete = False

failedRe = re.compile(r"Tests: \d+ Failed: (\d+)\)")
testsRe = re.compile(r"Files=\d+, Tests=(\d+)")
oldFailureCountsRe = re.compile(r"(\d+)/(\d+) subtests failed")
oldSuccessCountsRe = re.compile(r"Files=\d+, Tests=(\d+),")

def outLineReceived(self, line):
if self.warningPattern.match(line):
self.warnings += 1
if self.newStyle:
if line.startswith('Result: FAIL'):
self.rc = FAILURE
mo = self.failedRe.search(line)
if mo:
self.failed += int(mo.group(1))
if self.failed:
self.rc = FAILURE
mo = self.testsRe.search(line)
if mo:
self.total = int(mo.group(1))
else:
if line.startswith('Test Summary Report'):
self.newStyle = True
mo = self.oldFailureCountsRe.search(line)
if mo:
self.failed = int(mo.group(1))
self.total = int(mo.group(2))
self.rc = FAILURE
mo = self.oldSuccessCountsRe.search(line)
if mo:
self.total = int(mo.group(1))

# Because there are two paths that are used to determine
# the success/fail result, I have to modify it here if
# there were warnings.
if rc == SUCCESS and warnings:
rc = WARNINGS

if total:
passed = total - failed
class PerlModuleTest(Test):
command = ["prove", "--lib", "lib", "-r", "t"]
total = 0

self.setTestResults(total=total, failed=failed, passed=passed,
warnings=warnings)
def __init__(self, *args, **kwargs):
Test.__init__(self, *args, **kwargs)
self.observer = PerlModuleTestObserver(warningPattern=self.warningPattern)
self.addLogObserver('stdio', self.observer)

def evaluateCommand(self, cmd):
if self.observer.total:
passed = self.observer.total - self.observer.failed

self.setTestResults(
total=self.observer.total,
failed=self.observer.failed,
passed=passed,
warnings=self.observer.warnings)

rc = self.observer.rc
if rc == SUCCESS and self.observer.warnings:
rc = WARNINGS
return rc

0 comments on commit 00344f3

Please sign in to comment.