-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_test_results.rb
55 lines (42 loc) · 1002 Bytes
/
report_test_results.rb
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
require 'nokogiri'
def green(str)
"\e[32m#{str}\e[0m"
end
def red(str)
"\e[31m#{str}\e[0m"
end
def yellow(str)
"\e[33m#{str}\e[0m"
end
results_path = File.expand_path('./tests.xml', __dir__)
results = Nokogiri::XML(File.open(results_path))
failure_messages = []
def get_failure_message(test_case)
full_name = test_case['fullname']
failure = test_case.xpath('failure').first
message = failure.xpath('message').first.text
stack_trace = failure.xpath('stack-trace').first.text
"#{full_name}\n#{message}\n#{stack_trace}"
end
test_cases = results.xpath('//test-case')
test_cases.each do |test_case|
result = test_case['result']
case result
when 'Passed'
print green('.')
when 'Failed'
print red('F')
failure_messages << get_failure_message(test_case)
when 'Skipped'
print yellow('S')
else
print yellow('?')
end
end
puts
failure_messages.each do |message|
puts
puts red(message)
end
File.delete(results_path)
exit 1 if failure_messages.any?