ocunit2junit 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ocunit2junit +162 -0
- metadata +47 -0
data/bin/ocunit2junit
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# ocunit2junit.rb was written by Christian Hedin <christian.hedin@jayway.com>
|
4
|
+
# Version: 0.1 - 30/01 2010
|
5
|
+
# Usage:
|
6
|
+
# xcodebuild -yoursettings | ocunit2junit.rb
|
7
|
+
# All output is just passed through to stdout so you don't miss a thing!
|
8
|
+
# JUnit style XML-report are put in the folder specified below.
|
9
|
+
#
|
10
|
+
# Known problems:
|
11
|
+
# * "Errors" are not cought, only "warnings".
|
12
|
+
# * It's not possible to click links to failed test in Hudson
|
13
|
+
# * It's not possible to browse the source code in Hudson
|
14
|
+
#
|
15
|
+
# Acknowledgement:
|
16
|
+
# Big thanks to Steen Lehmann for prettifying this script.
|
17
|
+
################################################################
|
18
|
+
# Edit these variables to match your system
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# Where to put the XML-files from your unit tests
|
22
|
+
TEST_REPORTS_FOLDER = "test-reports"
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# Don't edit below this line
|
26
|
+
################################################################
|
27
|
+
|
28
|
+
require 'time'
|
29
|
+
require 'fileutils'
|
30
|
+
require 'socket'
|
31
|
+
|
32
|
+
class ReportParser
|
33
|
+
|
34
|
+
attr_reader :exit_code
|
35
|
+
|
36
|
+
def initialize(piped_input)
|
37
|
+
@piped_input = piped_input
|
38
|
+
@exit_code = 0
|
39
|
+
|
40
|
+
FileUtils.rm_rf(TEST_REPORTS_FOLDER)
|
41
|
+
FileUtils.mkdir(TEST_REPORTS_FOLDER)
|
42
|
+
parse_input
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def parse_input
|
48
|
+
@piped_input.each do |piped_row|
|
49
|
+
puts piped_row
|
50
|
+
case piped_row
|
51
|
+
|
52
|
+
when /Test Suite '(\S+)'.*started at\s+(.*)/
|
53
|
+
t = Time.parse($2.to_s)
|
54
|
+
handle_start_test_suite(t)
|
55
|
+
|
56
|
+
when /Test Suite '(\S+)'.*finished at\s+(.*)./
|
57
|
+
t = Time.parse($2.to_s)
|
58
|
+
handle_end_test_suite($1,t)
|
59
|
+
|
60
|
+
when /Test Case '-\[\S+\s+(\S+)\]' started./
|
61
|
+
test_case = $1
|
62
|
+
|
63
|
+
when /Test Case '-\[\S+\s+(\S+)\]' passed \((.*) seconds\)/
|
64
|
+
test_case = $1
|
65
|
+
test_case_duration = $2.to_f
|
66
|
+
handle_test_passed(test_case,test_case_duration)
|
67
|
+
|
68
|
+
when /(.*): error: -\[(\S+) (\S+)\] : (.*)/
|
69
|
+
error_location = $1
|
70
|
+
test_suite = $2
|
71
|
+
test_case = $3
|
72
|
+
error_message = $4
|
73
|
+
handle_test_error(test_suite,test_case,error_message,error_location)
|
74
|
+
|
75
|
+
when /Test Case '-\[\S+ (\S+)\]' failed \((\S+) seconds\)/
|
76
|
+
test_case = $1
|
77
|
+
test_case_duration = $2.to_f
|
78
|
+
handle_test_failed(test_case,test_case_duration)
|
79
|
+
|
80
|
+
when /failed with exit code (\d+)/
|
81
|
+
@exit_code = $1.to_i
|
82
|
+
|
83
|
+
when
|
84
|
+
/BUILD FAILED/
|
85
|
+
@exit_code = -1;
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def handle_start_test_suite(start_time)
|
91
|
+
@total_failed_test_cases = 0
|
92
|
+
@total_passed_test_cases = 0
|
93
|
+
@tests_results = Hash.new # test_case -> duration
|
94
|
+
@errors = Hash.new # test_case -> error_msg
|
95
|
+
@ended_current_test_suite = false
|
96
|
+
@cur_start_time = start_time
|
97
|
+
end
|
98
|
+
|
99
|
+
def handle_end_test_suite(test_name,end_time)
|
100
|
+
unless @ended_current_test_suite
|
101
|
+
current_file = File.open("#{TEST_REPORTS_FOLDER}/TEST-#{test_name}.xml", 'w')
|
102
|
+
host_name = string_to_xml Socket.gethostname
|
103
|
+
test_name = string_to_xml test_name
|
104
|
+
test_duration = (end_time - @cur_start_time).to_s
|
105
|
+
total_tests = @total_failed_test_cases + @total_passed_test_cases
|
106
|
+
suite_info = '<testsuite errors="0" failures="'+@total_failed_test_cases.to_s+'" hostname="'+host_name+'" name="'+test_name+'" tests="'+total_tests.to_s+'" time="'+test_duration.to_s+'" timestamp="'+end_time.to_s+'">'
|
107
|
+
current_file << "<?xml version='1.0' encoding='UTF-8' ?>\n"
|
108
|
+
current_file << suite_info
|
109
|
+
@tests_results.each do |t|
|
110
|
+
test_case = string_to_xml t[0]
|
111
|
+
duration = @tests_results[test_case]
|
112
|
+
current_file << "<testcase classname='#{test_name}' name='#{test_case}' time='#{duration.to_s}'"
|
113
|
+
unless @errors[test_case].nil?
|
114
|
+
# uh oh we got a failure
|
115
|
+
puts "tests_errors[0]"
|
116
|
+
puts @errors[test_case][0]
|
117
|
+
puts "tests_errors[1]"
|
118
|
+
puts @errors[test_case][1]
|
119
|
+
|
120
|
+
message = string_to_xml @errors[test_case][0].to_s
|
121
|
+
location = string_to_xml @errors[test_case][1].to_s
|
122
|
+
current_file << ">\n"
|
123
|
+
current_file << "<failure message='#{message}' type='Failure'>#{location}</failure>\n"
|
124
|
+
current_file << "</testcase>\n"
|
125
|
+
else
|
126
|
+
current_file << " />\n"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
current_file << "</testsuite>\n"
|
130
|
+
current_file.close
|
131
|
+
@ended_current_test_suite = true
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def string_to_xml(s)
|
136
|
+
s.gsub(/&/, '&').gsub(/'/, '"').gsub(/</, '<')
|
137
|
+
end
|
138
|
+
|
139
|
+
def handle_test_passed(test_case,test_case_duration)
|
140
|
+
@total_passed_test_cases += 1
|
141
|
+
@tests_results[test_case] = test_case_duration
|
142
|
+
end
|
143
|
+
|
144
|
+
def handle_test_error(test_suite,test_case,error_message,error_location)
|
145
|
+
# error_message.tr!('<','').tr!('>','')
|
146
|
+
@errors[test_case] = [ error_message, error_location ]
|
147
|
+
end
|
148
|
+
|
149
|
+
def handle_test_failed(test_case,test_case_duration)
|
150
|
+
@total_failed_test_cases +=1
|
151
|
+
@tests_results[test_case] = test_case_duration
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
#Main
|
157
|
+
#piped_input = File.open("tests_fail.txt") # for debugging this script
|
158
|
+
piped_input = ARGF.read
|
159
|
+
|
160
|
+
report = ReportParser.new(piped_input)
|
161
|
+
|
162
|
+
exit report.exit_code
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ocunit2junit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christian Hedin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-08 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'Simply pipe your xcodebuild output through ocunit2junit: xcodebuild
|
15
|
+
... | ocunit2junit.rb'
|
16
|
+
email:
|
17
|
+
executables:
|
18
|
+
- ocunit2junit
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- bin/ocunit2junit
|
23
|
+
homepage: https://github.com/ciryon/OCUnit2JUnit
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.24
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: A script that converts OCUnit output to JUnit style XML output.
|
47
|
+
test_files: []
|