fastlane-plugin-pretty_junit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f416d6f263aa879a3789b49cf4e0773628380212
4
+ data.tar.gz: 1dce113da86d23a8d9dbaa6c9c03ad4d1c1dda5d
5
+ SHA512:
6
+ metadata.gz: 4acbf9d6a3d7d70c2f06a6beb4d82131fe14f8348164421cfda21795f0125a82a44aea65e8bbc778bc5c48cf40927dea955b142a460d24d54f9453eb0c3d90e5
7
+ data.tar.gz: 9c6fdc6875395de0c65320f9462089653e885fbf3a773bb876467fc053210143c052dd16243e798e53f317b63449e8f11fbfa482776092e882c96bd3699fefe4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Gary Johnson <gary@gjtt.com>
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # pretty_junit plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-pretty_junit)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-pretty_junit`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin pretty_junit
11
+ ```
12
+
13
+ ## About pretty_junit
14
+
15
+ Pretty JUnit test results for your Android projects.
16
+
17
+ **Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
18
+
19
+ ```
20
+ output_pattern = 'app/build/{test-results,outputs}/**/{normalDebug,NORMAL}/*.xml'
21
+ delete_files(file_pattern: output_pattern)
22
+
23
+ # We ignore exit code otherwise we wouldn't get to the actions below on test failure
24
+ gradle(task: "testNormalDebugUnitTest", flags: "|| true")
25
+
26
+ pretty_junit(file_pattern: output_pattern)
27
+ ```
28
+
29
+ ## Example
30
+
31
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
32
+
33
+ **Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
34
+
35
+ ## Run tests for this plugin
36
+
37
+ To run both the tests, and code style validation, run
38
+
39
+ ```
40
+ rake
41
+ ```
42
+
43
+ To automatically fix many of the styling issues, use
44
+ ```
45
+ rubocop -a
46
+ ```
47
+
48
+ ## Issues and Feedback
49
+
50
+ For any other issues and feedback about this plugin, please submit it to this repository.
51
+
52
+ ## Troubleshooting
53
+
54
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/PluginsTroubleshooting.md) doc in the main `fastlane` repo.
55
+
56
+ ## Using `fastlane` Plugins
57
+
58
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Plugins.md).
59
+
60
+ ## About `fastlane`
61
+
62
+ `fastlane` is the easiest way to automate building and releasing your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/pretty_junit/version'
2
+
3
+ module Fastlane
4
+ module PrettyJunit
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::PrettyJunit.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,99 @@
1
+ require 'terminal-table'
2
+ require 'nokogiri'
3
+ require 'colorize'
4
+
5
+ module Fastlane
6
+
7
+ module Actions
8
+
9
+ class PrettyJunitAction < Action
10
+
11
+ def self.run(params)
12
+ file_pattern = params[:file_pattern]
13
+ UI.message "Searching for JUnit XML files with pattern \"#{file_pattern}\""
14
+
15
+ matching_files = Dir.glob(file_pattern)
16
+ UI.user_error! "No files found! Did your project compile?" unless matching_files.any?
17
+ UI.message "Processing files: #{matching_files.join(", ")}"
18
+
19
+ all_results = []
20
+ headings = ['', 'Context', 'Test', 'Duration']
21
+ table = Terminal::Table.new(title: "Test Results", headings: headings) do |t|
22
+
23
+ matching_files.each do |file|
24
+
25
+ results = nil
26
+ begin
27
+ results = Helper::PrettyJunitHelper.parse_junit_xml(file)
28
+ all_results << results
29
+ rescue Exception => ex
30
+ UI.crash! "An error occurred while trying to parse \"#{file}\": #{ex}"
31
+ end
32
+
33
+ results.passed.each do |result|
34
+ t.add_row ['✅', result.context.green, result.name.green, result.duration.green]
35
+ end
36
+ results.skipped.each do |result|
37
+ t.add_row ['❔', result.context, result.name, result.duration]
38
+ end
39
+ results.failed.each do |result|
40
+ t.add_row ['❌', result.context.red, result.name.red, result.duration.red]
41
+ end
42
+ end
43
+ end
44
+
45
+ all_failed = all_results.map{ |r| r.failed }.flatten
46
+ all_failed.each do |failed|
47
+ UI.error "Failed #{failed.class_path}.#{failed.name} with message: \n#{failed.fail_message}\nStack trace:\n#{failed.stack_trace}\n"
48
+ end
49
+
50
+ UI.message "\n#{table}\n"
51
+
52
+ all_failed.each do |failed|
53
+ UI.error "Failed #{failed.class_path}.#{failed.name} with message:\n\n#{failed.fail_message}\nSee above for stack trace.\n"
54
+ end
55
+
56
+ failed_count = all_results.inject(0) { |sum, r| sum + r.failed.length }
57
+ skipped_count = all_results.inject(0) { |sum, r| sum + r.skipped.length }
58
+ passed_count = all_results.inject(0) { |sum, r| sum + r.passed.length }
59
+
60
+ messages = []
61
+ messages << "#{passed_count} passed".green
62
+ messages << "#{skipped_count} skipped"
63
+ messages << "#{failed_count} failed".red
64
+ test_counts = "#{messages.join(', ')}"
65
+
66
+ if failed_count == 0
67
+ message = "All tests passed!".green
68
+ UI.message "#{message} #{test_counts}"
69
+ else
70
+ message = "You have failing tests!".red
71
+ UI.user_error! "#{message} #{test_counts}"
72
+ end
73
+ end
74
+
75
+ def self.description
76
+ "Pretty JUnit test results for your Android projects."
77
+ end
78
+
79
+ def self.details
80
+ "Pretty prints JUnit test results for your Android projects. You should make sure that the previous test results are deleted before running the gradle action, and that the grade action does not fail the lane on test failure. To delete the files, you can use the delete_files plugin and pass in the same file pattern that you pass to this action. To prevent the gradle action from failing on test failure, you can hack around it by appending '|| true' to the end of the 'flags' argument."
81
+ end
82
+
83
+ def self.authors
84
+ ["Gary Johnson"]
85
+ end
86
+
87
+ def self.available_options
88
+ [
89
+ FastlaneCore::ConfigItem.new(key: :file_pattern,
90
+ description: "Glob file pattern to search for junit-style xml files")
91
+ ]
92
+ end
93
+
94
+ def self.is_supported?(platform)
95
+ true
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,46 @@
1
+ module Fastlane
2
+
3
+ module Helper
4
+
5
+ class PrettyJunitHelper
6
+
7
+ def self.parse_junit_xml(file_path)
8
+ results = OpenStruct.new(skipped:[], failed:[], passed:[])
9
+ xml_doc = File.open(file_path) { |f| Nokogiri::XML(f) }
10
+
11
+ failed_nodes = xml_doc.xpath("//testcase[failure]")
12
+ skipped_nodes = xml_doc.xpath("//testcase[skipped]")
13
+ passed_nodes = xml_doc.xpath("//testcase[not(failure) and not(skipped)]")
14
+
15
+ passed_nodes.each do |node|
16
+ class_path = node['classname']
17
+ context = parse_context(class_path)
18
+ result = OpenStruct.new(name: node['name'], context: context, class_path: class_path, duration: node['time'])
19
+ results.passed.push result
20
+ end
21
+ skipped_nodes.each do |node|
22
+ class_path = node['classname']
23
+ context = parse_context(class_path)
24
+ result = OpenStruct.new(name: node['name'], context: context, class_path: class_path, duration: node['time'])
25
+ results.skipped.push result
26
+ end
27
+ failed_nodes.each do |node|
28
+ class_path = node['classname']
29
+ context = parse_context(class_path)
30
+ failure = node.xpath('.//failure').first
31
+ result = OpenStruct.new(name: node['name'], context: context, class_path: class_path, duration: node['time'],
32
+ fail_message: failure['message'], stack_trace: failure.text)
33
+ results.failed.push result
34
+ end
35
+
36
+ return results
37
+ end
38
+
39
+ def self.parse_context(class_path)
40
+ dot_rindex = class_path.rindex('.')
41
+ class_name = dot_rindex ? class_path[dot_rindex+1..-1] : ''
42
+ return class_name.gsub(/\$/, ', ')
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module PrettyJunit
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-pretty_junit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gary Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: terminal-table
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fastlane
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 1.104.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 1.104.0
139
+ description:
140
+ email: gary@gjtt.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/pretty_junit.rb
148
+ - lib/fastlane/plugin/pretty_junit/actions/pretty_junit_action.rb
149
+ - lib/fastlane/plugin/pretty_junit/helper/pretty_junit_helper.rb
150
+ - lib/fastlane/plugin/pretty_junit/version.rb
151
+ homepage: https://github.com/leandog/fastlane-plugin-pretty_junit
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.5.1
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Pretty JUnit test results for your Android projects.
175
+ test_files: []