6 from subprocess
import Popen, PIPE
7 from pprint
import pprint
as ppr
12 print 'Usage: {} -t <cstest_path> [-f <file_name.cs>] [-d <directory>]'.
format(s)
16 cmd = [toolpath,
'-f', filepath]
17 process = Popen(cmd, stdout=PIPE, stderr=PIPE)
18 stdout, stderr = process.communicate()
24 matches = re.finditer(
r'\[\s+RUN\s+\]\s+(.*)\n\[\s+FAILED\s+\]', stdout)
26 failed_tests.append(match.group(1))
30 for line
in stderr.split(
'\n'):
31 if '[ PASSED ] 0 test(s).' in line:
35 elif 'ERROR' in line
and ' --- ' in line:
36 parts = line.split(
' --- ')
38 details.append((parts[1], failed_tests[counter], parts[2]))
40 details.append((
'',
'Unknown test', line.split(
' --- ')[1]))
44 print '\n[-] There are/is {} failed test(s)'.
format(
len(details))
45 if len(details) > 0
and getDetails:
46 print '[-] Detailed report for {}:\n'.
format(filepath)
47 for c, f, d
in details:
48 print '\t[+] {}: {}\n\t\t{}\n'.
format(f, c, d)
51 elif len(details) > 0:
52 for c, f, d
in details:
53 if len(f) > 0
and cmt_out
is True:
54 tmp_cmd = [
'sed',
'-E',
'-i.bak',
's/({})(.*)/\/\/ \\1\\2/g'.
format(c), filepath]
55 sed_proc = Popen(tmp_cmd, stdout=PIPE, stderr=PIPE)
56 sed_proc.communicate()
57 tmp_cmd2 = [
'rm',
'-f', filepath +
'.bak']
58 rm_proc = Popen(tmp_cmd2, stdout=PIPE, stderr=PIPE)
66 for root, dirs, files
in os.walk(folderpath):
67 path = root.split(os.sep)
69 if f.split(
'.')[-1] ==
'cs':
70 print '[-] Target:', f,
71 result *=
get_report_file(toolpath, os.sep.join(x
for x
in path) + os.sep + f, details, cmt_out)
75 if __name__ ==
'__main__':
81 opts, args = getopt.getopt(sys.argv[1:],
"ct:f:d:D")
98 except getopt.GetoptError: