xcpretty-junit-formatter 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 67fa7b7ce83a60b25f80d299e90378d32758da9a80109c2ac7fa348afdcf5a63
4
+ data.tar.gz: 36ed73df1b55d942f2bf76aca3ec90e4fad733720a3c1d0a31754b7ac256e233
5
+ SHA512:
6
+ metadata.gz: 8922c15610f765bd5cb5ecb0430fbd06b3136b0cc4e46cfe10031e6c7deac90fc9ca2fc008ba59f81d6030772db074d689c34e2c8ee3afd20e98b44a0a6eb5cb
7
+ data.tar.gz: 52c01e03f61f888ebbeac90d0ca92d9ec6bf6d93425a8164910b6da3a59731ec8767cbee7477d6048f746d1cea98459e50f056eea90b71bbe4a488bb0571b35c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Marcelo Fabri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # XCPretty JUnit Formatter
2
+
3
+ [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](LICENSE.txt)
4
+ [![Gem](https://img.shields.io/gem/v/xcpretty-json-formatter.svg?style=flat)](http://rubygems.org/gems/xcpretty-json-formatter)
5
+ [![Build Status](https://travis-ci.org/marcelofabri/xcpretty-json-formatter.svg?branch=master)](https://travis-ci.org/marcelofabri/xcpretty-json-formatter)
6
+
7
+ Custom formatter for [xcpretty](https://github.com/supermarin/xcpretty) that saves on a XML (JUnit) file all the errors, warnings and test failures, so you can process them easily later.
8
+
9
+ ## Installation
10
+
11
+ This formatter is distributed via RubyGems, and depends on a version of `xcpretty` >= 0.0.7 (when custom formatters were introduced). Run:
12
+
13
+ gem install xcpretty-junit-formatter
14
+
15
+ ## Usage
16
+
17
+ Specify `xcpretty-junit-formatter` as a custom formatter to `xcpretty`:
18
+
19
+ ```bash
20
+ #!/bin/bash
21
+
22
+ xcodebuild | xcpretty -f `xcpretty-junit-formatter`
23
+ ```
24
+
25
+ By default, `xcpretty-junit-formatter` writes the result in `build/reports/errors.xml`, but you can change that with an environment variable:
26
+
27
+ ```bash
28
+ #!/bin/bash
29
+
30
+ xcodebuild | XCPRETTY_JUNIT_FILE_OUTPUT=result.xml xcpretty -f `xcpretty-junit-formatter`
31
+ ```
32
+
33
+ ## Output format
34
+
35
+ You can check some example JUnit xml files in the [fixtures folder](spec/fixtures).
36
+
37
+ ## Thanks
38
+
39
+ * [Marin Usalj](http://github.com/supermarin) and [Delisa Mason](http://github.com/kattrali) for creating [xcpretty](https://github.com/supermarin/xcpretty).
40
+ * [Delisa Mason](http://github.com/kattrali) for creating [xcpretty-travis-formatter](https://github.com/kattrali/xcpretty-travis-formatter), which I used as a guide.
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/faken/xcpretty-junit-formatter.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ print File.expand_path('../../lib/junit_formatter.rb', __FILE__)
@@ -0,0 +1,186 @@
1
+ require 'fileutils'
2
+ require 'xmlsimple'
3
+ require 'cgi'
4
+
5
+ class JUNITFormatter < XCPretty::Simple
6
+ FILE_PATH = 'build/reports/errors.xml'.freeze
7
+
8
+ def initialize(use_unicode, colorize)
9
+ super
10
+ @warnings = []
11
+ @ld_warnings = []
12
+ @compile_warnings = []
13
+ @errors = []
14
+ @compile_errors = []
15
+ @file_missing_errors = []
16
+ @undefined_symbols_errors = []
17
+ @duplicate_symbols_errors = []
18
+ @failures = {}
19
+ @tests_summary_messages = []
20
+ end
21
+
22
+ def format_ld_warning(message)
23
+ @ld_warnings << message
24
+ write_to_file_if_needed
25
+ super
26
+ end
27
+
28
+ def format_warning(message)
29
+ @warnings << message
30
+ write_to_file_if_needed
31
+ super
32
+ end
33
+
34
+ def format_compile_warning(file_name, file_path, reason, line, cursor)
35
+ @compile_warnings << {
36
+ message: reason,
37
+ type: "WARNING",
38
+ "content" => "\nFile: #{file_name}\n"\
39
+ "Path: #{file_path}\n"\
40
+ "Line: #{line}\n"\
41
+ "Reason: #{reason}\n"\
42
+ "Cursor: #{cursor}\n"
43
+ }
44
+ write_to_file_if_needed
45
+ super
46
+ end
47
+
48
+ def format_error(message)
49
+ @errors << message
50
+ write_to_file_if_needed
51
+ super
52
+ end
53
+
54
+ def format_compile_error(file_name, file_path, reason, line, cursor)
55
+ @compile_errors << {
56
+ message: reason,
57
+ type: "ERROR",
58
+ "content" => "\nFile: #{file_name}\n"\
59
+ "Path: #{file_path}\n"\
60
+ "Line: #{line}\n"\
61
+ "Reason: #{reason}\n"\
62
+ "Cursor: #{cursor}\n"
63
+ }
64
+ write_to_file_if_needed
65
+ super
66
+ end
67
+
68
+ def format_file_missing_error(reason, file_path)
69
+ @file_missing_errors << {
70
+ message: reason,
71
+ type: "ERROR",
72
+ "content" => "\nFile: #{file_path}\n"\
73
+ "Reason: #{reason}\n"
74
+ }
75
+ write_to_file_if_needed
76
+ super
77
+ end
78
+
79
+ def format_undefined_symbols(message, symbol, reference)
80
+ @undefined_symbols_errors = {
81
+ message: message,
82
+ type: "ERROR",
83
+ "content" => "Reference: #{reference}"\
84
+ "Symbol: #{symbol}"
85
+ }
86
+ write_to_file_if_needed
87
+ super
88
+ end
89
+
90
+ def format_duplicate_symbols(message, file_paths)
91
+ @duplicate_symbols_errors = {
92
+ message: message,
93
+ type: "ERROR",
94
+ "content" => "\nMessage: #{message}\n"\
95
+ "Paths: #{file_paths}\n"
96
+ }
97
+ write_to_file_if_needed
98
+ super
99
+ end
100
+
101
+ def format_test_summary(message, failures_per_suite)
102
+ @failures = failures_per_suite.map { |key, value|
103
+ {
104
+ name: key,
105
+ failure: value.map { |failure|
106
+ {
107
+ message: CGI.escapeHTML(failure[:reason]),
108
+ type: "ERROR",
109
+ "content" => "\nFile: #{failure[:file_path]}\n"\
110
+ "Reason: #{failure[:reason]}\n"\
111
+ "Test Case: #{failure[:test_case]}\n"
112
+ }
113
+ }
114
+ }
115
+ }
116
+
117
+ @tests_summary_messages << message
118
+
119
+ puts "😂: #{@failures}"
120
+ puts "😂: #{@tests_summary_messages}"
121
+
122
+ write_to_file_if_needed
123
+ super
124
+ end
125
+
126
+ def finish
127
+ write_to_file
128
+ super
129
+ end
130
+
131
+ def combined_compile_errors
132
+ [ @errors, @compile_errors, @file_missing_errors,
133
+ @undefined_symbols_errors, @duplicate_symbols_errors ].flatten.compact.delete_if &:empty?
134
+ end
135
+
136
+ def combined_compile_warnings
137
+ [@warnings, @ld_warnings, @compile_warnings].flatten.compact.delete_if &:empty?
138
+ end
139
+
140
+ def combined_test_failures
141
+ [@failures].flatten.compact.delete_if &:empty?
142
+ end
143
+
144
+ def junit_output
145
+ {
146
+ testsuites: {
147
+ name: "xcode_build",
148
+ testsuite: [
149
+ {
150
+ name: "compile",
151
+ testcase: [
152
+ {
153
+ name: "failures",
154
+ failure: combined_compile_warnings
155
+ },
156
+ {
157
+ name: "errors",
158
+ error: combined_compile_errors
159
+ }
160
+ ]
161
+ },
162
+ {
163
+ name: "test",
164
+ testcase: combined_test_failures
165
+ }
166
+ ]
167
+ }
168
+ }
169
+ end
170
+
171
+ def write_to_file_if_needed
172
+ write_to_file unless XCPretty::Formatter.method_defined? :finish
173
+ end
174
+
175
+ def write_to_file
176
+ file_name = ENV['XCPRETTY_JUNIT_FILE_OUTPUT'] || FILE_PATH
177
+ dirname = File.dirname(file_name)
178
+ FileUtils.mkdir_p dirname
179
+
180
+ File.open(file_name, 'w') do |io|
181
+ io.write(XmlSimple.xml_out(junit_output, {keeproot: true, noescape: true}))
182
+ end
183
+ end
184
+ end
185
+
186
+ JUNITFormatter
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xcpretty-junit-formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Sascha Held
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xcpretty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.0.7
33
+ - !ruby/object:Gem::Dependency
34
+ name: xml-simple
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.1.5
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.1.5
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.11'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.11'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '10.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '10.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rubocop
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 0.49.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: 0.49.0
109
+ description: Custom formatter for xcpretty that saves on a JUNIT file that contains
110
+ all the errors, warnings and test failures, so you can process them easily later.
111
+ email:
112
+ - saschaheld@me.com
113
+ executables:
114
+ - xcpretty-junit-formatter
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - LICENSE
119
+ - README.md
120
+ - bin/xcpretty-junit-formatter
121
+ - lib/junit_formatter.rb
122
+ homepage: https://github.com/faken/xcpretty-junit-formatter
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.7.6
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: xcpretty custom formatter for JUNIT output
146
+ test_files: []