forked from lvmguy/thinp-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_reports
executable file
·95 lines (75 loc) · 2.36 KB
/
generate_reports
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
#!/usr/bin/env ruby
require 'erb'
require 'lib/log'
require 'lib/report-generators/report_templates'
require 'lib/report-generators/reports'
require 'lib/test-outcome'
require 'pathname'
require 'yaml'
#----------------------------------------------------------------
include ReportTemplates
Message = Struct.new(:level, :time, :txt)
def trim_time(txt)
# [2011-10-19T15:02:36.011520 #1065]
m = /T(\S+)/.match(txt)
m ? m[1] : 'arf'
end
class File
def each_message
msg = nil
in_message = false
each_line do |line|
if in_message
m = /([DIWE]), (\[.*\])[^:]*: (.*)/.match(line)
if m
yield(msg)
msg = Message.new(m[1], trim_time(m[2]), m[3])
else
msg.txt.concat line
end
else
m = /([DIWE]), (\[.*\])[^:]*: (.*)/.match(line)
if !m
raise RuntimeError, "bad log line: '#{line}'"
end
msg = Message.new(m[1], trim_time(m[2]), m[3])
in_message = true
end
end
if in_message
yield(msg)
end
end
end
# Formats dm tables
def expand_tables(txt)
txt.gsub(/<<table:([^>]*)>>/) do |match|
output = '</pre><table width="95%" cellspacing="0" cellpadding="0" border="0" class="stripes">'
$1.split(/;\s*/).each do |line|
m = /(\d+)\s+(\d+)\s+(\S+)\s+(.*)/.match(line)
raise RuntimeError, "badly formatted table line" if !m
output << "<tr><td><pre>#{m[1]}</pre></td><td><pre>#{m[2]}</pre></td><td><pre>#{m[3]}</pre></td><td><pre>#{m[4]}</pre></td></tr>"
end
output << '</table><pre>'
end
end
def expand_message(msg)
"<tr class=\"#{msg.level}\"><td><pre>#{msg.level}</pre></td><td><pre>#{msg.time}</pre></td><td><pre>#{expand_tables(msg.txt)}</pre></td></tr>"
end
all_tests = Array.new
Dir::glob('reports/*.yaml') do |yaml_file|
t = YAML::load_file(yaml_file)
generate_report(:unit_detail, binding, Pathname.new("reports/#{mangle(t.suite + "__" + t.name)}.html"))
all_tests << t
end
suites = all_tests.group_by {|t| t.suite}
total_passed = all_tests.inject(0) {|tot, t| tot + (t.pass? ? 1 : 0)}
total_failed = all_tests.length - total_passed
generate_report(:unit_test, binding)
# Generate the index page
reports = ReportRegister.new
def safe_mtime(r)
r.path.file? ? r.path.mtime.to_s : "not generated"
end
generate_report(:index, binding)
#----------------------------------------------------------------