Created
April 22, 2010 18:06
-
-
Save farcaller/375582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, subprocess, re | |
RX_SUITE_START = re.compile(r"Test Suite '(?P<suitename>\w+)' started at (?P<date>[\d\-]+) (?P<time>[\d\:]+) (?P<tz>[\d\-\+]+)") | |
RX_SUITE_END = re.compile(r"Test Suite '(?P<suitename>\w+)' finished at (?P<date>[\d\-]+) (?P<time>[\d\:]+) (?P<tz>[\d\-\+]+)") | |
RX_TEST_START = re.compile(r"Test Case '(?P<testname>[^']+)' started\.") | |
RX_TEST_END = re.compile(r"Test Case '(?P<testname>[^']+)' passed \((?P<sec>[\d\.]+) seconds\)\.") | |
RX_TEST_FAIL = re.compile(r"Test Case '(?P<testname>[^']+)' failed \((?P<sec>[\d\.]+) seconds\)\.") | |
ALL_RE = [ | |
(RX_SUITE_START, "##teamcity[testSuiteStarted name='%(suitename)s' timestamp='%(date)sT%(time)s%(tz)s']", None), | |
(RX_SUITE_END, "##teamcity[testSuiteFinished name='%(suitename)s' timestamp='%(date)sT%(time)s%(tz)s']", None), | |
(RX_TEST_START, "##teamcity[testStarted name='%(testname)s' captureStandardOutput='true']", None), | |
(RX_TEST_END, "##teamcity[testFinished name='%(testname)s' duration='%(dur)s']", lambda d:dict(d,dur=str(float(d['sec'])*1000)) ), | |
(RX_TEST_FAIL, "##teamcity[testFailed name='%(testname)s' duration='%(dur)s']", lambda d:dict(d,dur=str(float(d['sec'])*1000)) ), | |
] | |
def process_line(line): | |
sline = line.strip() | |
for rx, trans, proc in ALL_RE: | |
m = rx.match(sline) | |
if m: | |
d = {} | |
for k,v in m.groupdict().iteritems(): | |
v = v.replace('|', '||').replace("'", "|'").replace('\n', '|n').replace('\r', '|r').replace(']', '|]') | |
d[k] = v | |
if proc: | |
d = proc(d) | |
return (trans % d) + '\n' | |
return line | |
def spawn_xcode(): | |
pop = subprocess.Popen(['xcodebuild', '-target', 'Tests', '-sdk', 'macosx10.6', '-configuration', 'Debug',], | |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
return pop | |
def process_tests(pop): | |
while pop.poll() == None: | |
l = pop.stdout.readline() | |
print process_line(l), | |
for l in pop.stdout.readlines(): | |
l = pop.stdout.readline() | |
print process_line(l), | |
if __name__ == '__main__': | |
process_tests(spawn_xcode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment